oldhaven/app/assets/javascripts/beathaven.coffee

101 lines
2.6 KiB
CoffeeScript
Raw Normal View History

2011-06-28 00:43:54 +04:00
# Registering global objects
2011-09-08 03:47:11 +04:00
window._beathaven = null
2011-09-08 14:56:10 +04:00
window._session = null
2011-09-08 03:47:11 +04:00
window._vkontakte = null
window._vk_music = null
2011-09-08 03:47:11 +04:00
window._ajax = null
window._player = null
window._search = null
2011-09-10 02:13:02 +04:00
window._page = null
2011-09-08 03:47:11 +04:00
window._settings = null
2011-06-28 00:43:54 +04:00
2011-06-27 22:41:36 +04:00
$ ->
l = document.location
2011-09-08 03:47:11 +04:00
if l.hostname not in ['beathaven.org', 'dev.beathaven.org']
2011-06-27 22:41:36 +04:00
l.href = 'http://beathaven.org/'+ l.hash
2011-09-08 03:47:11 +04:00
window._beathaven = new BeatHaven()
window._beathaven.init()
2011-06-27 22:41:36 +04:00
2011-09-10 02:13:02 +04:00
class window.BeatHaven
2011-06-27 22:41:36 +04:00
last_height: false
2011-06-30 09:12:52 +04:00
lang: 'ru'
2011-06-27 22:41:36 +04:00
init: ->
2011-09-08 03:47:11 +04:00
window._vkontakte = new Vkontakte(2335068)
window._vkontakte.init()
window._vk_music = new VkontakteMusic
2011-06-28 00:43:54 +04:00
2011-09-08 03:47:11 +04:00
window._ajax = new Ajax()
2011-06-28 00:43:54 +04:00
2011-09-08 03:47:11 +04:00
window._player = new Player()
window._player.initJplayer()
2011-06-28 00:43:54 +04:00
2011-09-08 03:47:11 +04:00
window._search = new Search()
2011-06-28 00:43:54 +04:00
2011-09-10 02:13:02 +04:00
window._page = new Page()
2011-06-28 00:43:54 +04:00
2011-09-08 03:47:11 +04:00
window._settings = new Settings()
2011-06-30 09:12:52 +04:00
2011-09-08 14:56:10 +04:00
this.setupAutocomplete()
2011-06-30 09:12:52 +04:00
false
2011-06-27 22:41:36 +04:00
2011-09-08 14:56:10 +04:00
setupAutocomplete: ->
$('#search').first().bh_autocomplete
serviceUrl: '/artist/autocomplete' # Страница для обработки запросов автозаполнения
2011-09-16 05:57:41 +04:00
minChars: 3 # Минимальная длина запроса для срабатывания автозаполнения
2011-09-08 14:56:10 +04:00
delimiter: /(,|;)\s*/ # Разделитель для нескольких запросов, символ или регулярное выражение
maxHeight: 400 # Максимальная высота списка подсказок, в пикселях
width: 415 # Ширина списка
zIndex: 9999 # z-index списка
deferRequestBy: 500 # Задержка запроса (мсек)
containerId: 'autocomplete-container'
containerItemsId: 'autocomplete-items'
onSelect: ->
2011-09-10 02:13:02 +04:00
_search.loadArtistData $('#search').val()
2011-06-27 22:41:36 +04:00
2011-07-02 18:10:59 +04:00
localizeHTML: (obj, lang) ->
2011-06-30 09:12:52 +04:00
unless obj?
obj = $('body')
2011-07-02 18:10:59 +04:00
unless lang?
lang = _beathaven.lang
2011-06-30 09:12:52 +04:00
$(obj).find('[data-ls]').each ->
2011-07-02 18:10:59 +04:00
if _locale[$(this).attr 'data-ls']? and _locale[$(this).attr 'data-ls'][lang]?
2011-06-30 09:12:52 +04:00
if this.nodeName is 'INPUT'
2011-07-02 18:10:59 +04:00
$(this).val _locale[$(this).attr 'data-ls'][lang]
2011-06-30 09:12:52 +04:00
else
2011-07-02 18:10:59 +04:00
$(this).text _locale[$(this).attr 'data-ls'][lang]
2011-06-30 09:12:52 +04:00
return obj
ls: (id, lang) ->
unless lang?
lang = _beathaven.lang
if _locale[id]? and _locale[id][lang]?
_locale[id][lang]
else
id
2011-06-27 22:41:36 +04:00
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