1
0
Fork 0
oldhaven/app/assets/javascripts/beathaven.coffee

136 lines
3.7 KiB
CoffeeScript
Raw Normal View History

2011-06-27 20:43:54 +00:00
# Registering global objects
2011-09-07 23:47:11 +00:00
window._beathaven = null
2011-09-08 10:56:10 +00:00
window._session = null
2011-09-07 23:47:11 +00:00
window._vkontakte = null
window._ajax = null
window._player = null
window._search = null
window._pages = null
window._settings = null
2011-06-27 20:43:54 +00:00
2011-06-27 18:41:36 +00:00
$ ->
l = document.location
2011-09-07 23:47:11 +00:00
if l.hostname not in ['beathaven.org', 'dev.beathaven.org']
2011-06-27 18:41:36 +00:00
l.href = 'http://beathaven.org/'+ l.hash
2011-09-07 23:47:11 +00:00
window._beathaven = new BeatHaven()
window._beathaven.init()
2011-06-27 18:41:36 +00:00
class BeatHaven
last_height: false
2011-06-30 05:12:52 +00:00
lang: 'ru'
2011-06-27 18:41:36 +00:00
init: ->
2011-09-07 23:47:11 +00:00
window._vkontakte = new Vkontakte(2335068)
window._vkontakte.init()
2011-06-27 20:43:54 +00:00
2011-09-07 23:47:11 +00:00
window._ajax = new Ajax()
2011-06-27 20:43:54 +00:00
2011-09-07 23:47:11 +00:00
window._player = new Player()
window._player.initJplayer()
2011-06-27 20:43:54 +00:00
2011-09-07 23:47:11 +00:00
window._search = new Search()
2011-06-27 20:43:54 +00:00
2011-09-07 23:47:11 +00:00
window._pages = new Pages()
2011-06-27 20:43:54 +00:00
2011-09-07 23:47:11 +00:00
window._settings = new Settings()
2011-06-30 05:12:52 +00:00
2011-09-08 10:56:10 +00:00
this.setupAutocomplete()
2011-09-08 13:10:52 +00:00
window._ajax.detectPage()
2011-09-08 10:56:10 +00:00
2011-06-30 05:12:52 +00:00
false
2011-06-27 18:41:36 +00:00
2011-09-08 10:56:10 +00:00
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()
2011-06-27 18:41:36 +00:00
adjustSizes: ->
2011-07-04 15:09:44 +00:00
$('.data-container').height $(window).height() - $('.header-container').height() - $('.pulldown').height()
2011-06-27 18:41:36 +00:00
$('.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()
2011-06-30 05:12:52 +00:00
false
2011-06-27 18:41:36 +00:00
checkRedrawScrollbar: ->
focused_id = false
if document.activeElement.id?
focused_id = document.activeElement.id;
outer_height = $('.data-container > div').outerHeight()
2011-07-02 14:10:59 +00:00
if outer_height > 300 and outer_height != _beathaven.last_height
_beathaven.last_height = outer_height
_beathaven.redrawScrollbar()
2011-06-27 18:41:36 +00:00
if focused_id
document.getElementById(focused_id).focus()
focused_id = false
window.setTimeout ->
2011-06-27 20:43:54 +00:00
_beathaven.checkRedrawScrollbar()
2011-06-30 05:12:52 +00:00
false
2011-06-27 18:41:36 +00:00
, 500
2011-06-30 05:12:52 +00:00
false
2011-06-27 18:41:36 +00:00
2011-07-02 14:10:59 +00:00
localizeHTML: (obj, lang) ->
2011-06-30 05:12:52 +00:00
unless obj?
obj = $('body')
2011-07-02 14:10:59 +00:00
unless lang?
lang = _beathaven.lang
2011-06-30 05:12:52 +00:00
$(obj).find('[data-ls]').each ->
2011-07-02 14:10:59 +00:00
if _locale[$(this).attr 'data-ls']? and _locale[$(this).attr 'data-ls'][lang]?
2011-06-30 05:12:52 +00:00
if this.nodeName is 'INPUT'
2011-07-02 14:10:59 +00:00
$(this).val _locale[$(this).attr 'data-ls'][lang]
2011-06-30 05:12:52 +00:00
else
2011-07-02 14:10:59 +00:00
$(this).text _locale[$(this).attr 'data-ls'][lang]
2011-06-30 05:12:52 +00:00
return obj
ls: (id, lang) ->
unless lang?
lang = _beathaven.lang
if _locale[id]? and _locale[id][lang]?
_locale[id][lang]
else
id
2011-07-04 15:09:44 +00:00
pdShowSpinner: ->
$('.pulldown').html '<div class="pd-spinner"><img src="/images/loader.gif" alt=""/></div>'
false
pdHideSpinner: ->
$('.pulldown').html ''
false
2011-06-27 18:41:36 +00:00
String::htmlsafe = ->
replaces = [
["\\", "\\\\"]
["\"", "&quot;"]
["<", "&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