129 lines
3.8 KiB
JavaScript
Raw Normal View History

2011-06-28 00:43:54 +04:00
var BeatHaven, _ajax, _beathaven, _pages, _player, _search, _session, _settings, _vkontakte;
_beathaven = null;
_session = 1;
_vkontakte = null;
_ajax = null;
_player = null;
_search = null;
_pages = null;
_settings = null;
$(function() {
var l, _ref;
l = document.location;
2011-06-29 08:11:54 +04:00
if ((_ref = l.host) !== 'beathaven.org' && _ref !== 'local.beathaven.org') {
2011-06-28 00:43:54 +04:00
l.href = 'http://beathaven.org/' + l.hash;
}
_beathaven = new BeatHaven();
_beathaven.init();
$(window).resize(function() {
2011-06-30 09:12:52 +04:00
_beathaven.adjustSizes();
return false;
2011-06-27 22:41:36 +04:00
});
2011-06-28 00:43:54 +04:00
return window.setTimeout(function() {
2011-06-30 09:12:52 +04:00
_beathaven.checkRedrawScrollbar();
return false;
2011-06-28 00:43:54 +04:00
}, 500);
});
BeatHaven = (function() {
function BeatHaven() {}
BeatHaven.prototype.last_height = false;
2011-06-30 09:12:52 +04:00
BeatHaven.prototype.lang = 'ru';
2011-06-28 00:43:54 +04:00
BeatHaven.prototype.init = function() {
this.adjustSizes();
this.checkRedrawScrollbar();
2011-06-29 08:11:54 +04:00
_vkontakte = new Vkontakte(2335068);
2011-06-28 00:43:54 +04:00
_vkontakte.init();
_ajax = new Ajax();
_player = new Player();
_player.initJplayer();
_search = new Search();
_pages = new Pages();
2011-06-30 09:12:52 +04:00
_settings = new Settings();
return false;
2011-06-27 22:41:36 +04:00
};
2011-06-28 00:43:54 +04:00
BeatHaven.prototype.adjustSizes = function() {
$('.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();
2011-06-30 09:12:52 +04:00
$('.playlist').scrollbar();
return false;
2011-06-28 00:43:54 +04:00
};
BeatHaven.prototype.checkRedrawScrollbar = function() {
var focused_id, outer_height;
focused_id = false;
if (document.activeElement.id != null) {
focused_id = document.activeElement.id;
2011-06-27 22:41:36 +04:00
}
2011-06-28 00:43:54 +04:00
outer_height = $('.data-container > div').outerHeight();
if (outer_height > 300 && outer_height !== this.last_height) {
this.last_height = outer_height;
this.redrawScrollbar();
2011-06-27 22:41:36 +04:00
}
2011-06-28 00:43:54 +04:00
if (focused_id) {
document.getElementById(focused_id).focus();
focused_id = false;
2011-06-27 22:41:36 +04:00
}
2011-06-30 09:12:52 +04:00
window.setTimeout(function() {
_beathaven.checkRedrawScrollbar();
return false;
2011-06-28 00:43:54 +04:00
}, 500);
2011-06-30 09:12:52 +04:00
return false;
2011-06-28 00:43:54 +04:00
};
BeatHaven.prototype.redrawScrollbar = function() {
$('.data-container').html($('.data-container').find('.inner').first());
2011-06-30 09:12:52 +04:00
$('.data-container').scrollbar();
return false;
};
BeatHaven.prototype.localizeHTML = function(obj) {
if (obj == null) {
obj = $('body');
}
$(obj).find('[data-ls]').each(function() {
if ((_locale[$(this).attr('data-ls')] != null) && (_locale[$(this).attr('data-ls')][_beathaven.lang] != null)) {
if (this.nodeName === 'INPUT') {
return $(this).val(_locale[$(this).attr('data-ls')][_beathaven.lang]);
} else {
return $(this).text(_locale[$(this).attr('data-ls')][_beathaven.lang]);
}
}
});
return obj;
};
BeatHaven.prototype.ls = function(id, lang) {
if (lang == null) {
lang = _beathaven.lang;
}
if ((_locale[id] != null) && (_locale[id][lang] != null)) {
return _locale[id][lang];
} else {
return id;
}
2011-06-27 22:41:36 +04:00
};
2011-06-28 00:43:54 +04:00
return BeatHaven;
})();
String.prototype.htmlsafe = function() {
var item, replaces, str, _i, _len;
replaces = [["\\", "\\\\"], ["\"", "&quot;"], ["<", "&lt;"], [">", "&gt;"]];
str = this;
for (_i = 0, _len = replaces.length; _i < _len; _i++) {
item = replaces[_i];
str = str.replace(item[0], item[1]);
}
return str;
};
String.prototype.trim = function() {
var str;
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);
}
return str;
};