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

99 lines
2.5 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
2011-09-09 22:13:02 +00:00
window._page = null
2011-09-07 23:47:11 +00:00
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
2011-09-09 22:13:02 +00:00
class window.BeatHaven
2011-06-27 18:41:36 +00:00
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-09 22:13:02 +00:00
window._page = new Page()
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-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' # Страница для обработки запросов автозаполнения
2011-09-16 01:57:41 +00:00
minChars: 3 # Минимальная длина запроса для срабатывания автозаполнения
2011-09-08 10:56:10 +00:00
delimiter: /(,|;)\s*/ # Разделитель для нескольких запросов, символ или регулярное выражение
maxHeight: 400 # Максимальная высота списка подсказок, в пикселях
width: 415 # Ширина списка
zIndex: 9999 # z-index списка
deferRequestBy: 500 # Задержка запроса (мсек)
containerId: 'autocomplete-container'
containerItemsId: 'autocomplete-items'
onSelect: ->
2011-09-09 22:13:02 +00:00
_search.loadArtistData $('#search').val()
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-06-27 18:41:36 +00: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