oldhaven/app/coffeescripts/beathaven.coffee
2011-06-27 22:41:36 +04:00

77 lines
1.9 KiB
CoffeeScript

$ ->
l = document.location
if l.host not in ['beathaven.org', 'localhost']
l.href = 'http://beathaven.org/'+ l.hash
window.beathaven = new BeatHaven()
window.vkontakte = new Vkontakte(if l.host == 'beathaven.org' then 2335068 else 2383163)
beathaven.init()
vkontakte.init()
$(window).resize ->
beathaven.adjustSizes()
window.setTimeout ->
beathaven.checkRedrawScrollbar()
, 500
class BeatHaven
last_height: false
init: ->
this.drawInterface()
this.adjustSizes()
ajax.detectPage()
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()
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 != @last_height
@last_height = outer_height
this.redrawScrollbar()
if focused_id
document.getElementById(focused_id).focus()
focused_id = false
window.setTimeout ->
beathaven.checkRedrawScrollbar()
, 500
redrawScrollbar: ->
$('.data-container').html $('.data-container').find('.inner').first()
$('.data-container').scrollbar()
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