136 lines
3.7 KiB
CoffeeScript
136 lines
3.7 KiB
CoffeeScript
# Registering global objects
|
|
window._beathaven = null
|
|
window._session = null
|
|
window._vkontakte = null
|
|
window._ajax = null
|
|
window._player = null
|
|
window._search = null
|
|
window._pages = null
|
|
window._settings = null
|
|
|
|
$ ->
|
|
l = document.location
|
|
if l.hostname not in ['beathaven.org', 'dev.beathaven.org']
|
|
l.href = 'http://beathaven.org/'+ l.hash
|
|
|
|
window._beathaven = new BeatHaven()
|
|
window._beathaven.init()
|
|
|
|
class BeatHaven
|
|
|
|
last_height: false
|
|
lang: 'ru'
|
|
|
|
init: ->
|
|
window._vkontakte = new Vkontakte(2335068)
|
|
window._vkontakte.init()
|
|
|
|
window._ajax = new Ajax()
|
|
|
|
window._player = new Player()
|
|
window._player.initJplayer()
|
|
|
|
window._search = new Search()
|
|
|
|
window._pages = new Pages()
|
|
|
|
window._settings = new Settings()
|
|
|
|
this.setupAutocomplete()
|
|
window._ajax.detectPage()
|
|
|
|
false
|
|
|
|
setupAutocomplete: ->
|
|
$('#search').first().bh_autocomplete
|
|
serviceUrl: '/artist/autocomplete' # Страница для обработки запросов автозаполнения
|
|
minChars: 2 # Минимальная длина запроса для срабатывания автозаполнения
|
|
delimiter: /(,|;)\s*/ # Разделитель для нескольких запросов, символ или регулярное выражение
|
|
maxHeight: 400 # Максимальная высота списка подсказок, в пикселях
|
|
width: 415 # Ширина списка
|
|
zIndex: 9999 # z-index списка
|
|
deferRequestBy: 500 # Задержка запроса (мсек)
|
|
containerId: 'autocomplete-container'
|
|
containerItemsId: 'autocomplete-items'
|
|
onSelect: ->
|
|
_ajax.loadArtistData $('#search').first().val()
|
|
|
|
adjustSizes: ->
|
|
$('.data-container').height $(window).height() - $('.header-container').height() - $('.pulldown').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
|
|
|
|
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
|
|
|
|
pdShowSpinner: ->
|
|
$('.pulldown').html '<div class="pd-spinner"><img src="/images/loader.gif" alt=""/></div>'
|
|
false
|
|
|
|
pdHideSpinner: ->
|
|
$('.pulldown').html ''
|
|
false
|
|
|
|
|
|
String::htmlsafe = ->
|
|
replaces = [
|
|
["\\", "\\\\"]
|
|
["\"", """]
|
|
["<", "<"]
|
|
[">", ">"]
|
|
]
|
|
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
|