1
0
Fork 0
oldhaven/app/coffeescripts/beathaven.coffee

129 lines
2.8 KiB
CoffeeScript

# Registering global objects
_beathaven = null
_session = 1
_vkontakte = null
_ajax = null
_player = null
_search = null
_pages = null
_settings = null
$ ->
l = document.location
if l.host not in ['beathaven.org', 'dev.beathaven.org']
l.href = 'http://beathaven.org/'+ l.hash
_beathaven = new BeatHaven()
_beathaven.init()
$(window).resize ->
_beathaven.adjustSizes()
_beathaven.redrawScrollbar()
false
window.setTimeout ->
_beathaven.checkRedrawScrollbar()
false
, 500
class BeatHaven
last_height: false
lang: 'ru'
init: ->
this.adjustSizes()
this.checkRedrawScrollbar()
# if document.location.host == 'beathaven.org' then 2335068 else 2383163
_vkontakte = new Vkontakte(2335068)
_vkontakte.init()
_ajax = new Ajax()
_player = new Player()
_player.initJplayer()
_search = new Search()
_pages = new Pages()
_settings = new Settings()
false
adjustSizes: ->
$('.data-container').height $(window).height() - $('.header-container').height()
$('.data-container').width $(window).width() - $('.player').width()
$('.player-container').height $(window).height()
$('.playlist').height $(window).height() - $('.player').height() - $('.player-container .additional-controls').height()
$('.data-container').scrollbar()
$('.playlist').scrollbar()
false
checkRedrawScrollbar: ->
focused_id = false
if document.activeElement.id?
focused_id = document.activeElement.id;
outer_height = $('.data-container > div').outerHeight()
if outer_height > 300 and outer_height != _beathaven.last_height
_beathaven.last_height = outer_height
_beathaven.redrawScrollbar()
if focused_id
document.getElementById(focused_id).focus()
focused_id = false
window.setTimeout ->
_beathaven.checkRedrawScrollbar()
false
, 500
false
redrawScrollbar: ->
$('.data-container').html $('.data-container').find('.inner').first()
$('.data-container').scrollbar()
false
localizeHTML: (obj, lang) ->
unless obj?
obj = $('body')
unless lang?
lang = _beathaven.lang
$(obj).find('[data-ls]').each ->
if _locale[$(this).attr 'data-ls']? and _locale[$(this).attr 'data-ls'][lang]?
if this.nodeName is 'INPUT'
$(this).val _locale[$(this).attr 'data-ls'][lang]
else
$(this).text _locale[$(this).attr 'data-ls'][lang]
return obj
ls: (id, lang) ->
unless lang?
lang = _beathaven.lang
if _locale[id]? and _locale[id][lang]?
_locale[id][lang]
else
id
String::htmlsafe = ->
replaces = [
["\\", "\\\\"]
["\"", """]
["<", "&lt;"]
[">", "&gt;"]
]
str = this
for item in replaces
str = str.replace item[0], item[1]
str
String::trim = ->
str = this
while str.indexOf(' ') != -1
str = str.replace(' ', ' ')
if str.charAt(0) == ' '
str = str.substring 1
if str.charAt(str.length - 1) == ' '
str = str.substring(0, str.length - 1)
str