141 lines
4.2 KiB
JavaScript
141 lines
4.2 KiB
JavaScript
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;
|
|
if ((_ref = l.host) !== 'beathaven.org' && _ref !== 'dev.beathaven.org') {
|
|
l.href = 'http://beathaven.org/' + l.hash;
|
|
}
|
|
_beathaven = new BeatHaven();
|
|
_beathaven.init();
|
|
$(window).resize(function() {
|
|
_beathaven.adjustSizes();
|
|
_beathaven.redrawScrollbar();
|
|
return false;
|
|
});
|
|
return window.setTimeout(function() {
|
|
_beathaven.checkRedrawScrollbar();
|
|
return false;
|
|
}, 500);
|
|
});
|
|
BeatHaven = (function() {
|
|
function BeatHaven() {}
|
|
BeatHaven.prototype.last_height = false;
|
|
BeatHaven.prototype.lang = 'ru';
|
|
BeatHaven.prototype.init = function() {
|
|
this.adjustSizes();
|
|
this.checkRedrawScrollbar();
|
|
_vkontakte = new Vkontakte(2335068);
|
|
_vkontakte.init();
|
|
_ajax = new Ajax();
|
|
_player = new Player();
|
|
_player.initJplayer();
|
|
_search = new Search();
|
|
_pages = new Pages();
|
|
_settings = new Settings();
|
|
return false;
|
|
};
|
|
BeatHaven.prototype.adjustSizes = function() {
|
|
$('.data-container').height($(window).height() - $('.header-container').height() - $('.pulldown').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();
|
|
return false;
|
|
};
|
|
BeatHaven.prototype.checkRedrawScrollbar = function() {
|
|
var focused_id, outer_height;
|
|
focused_id = false;
|
|
if (document.activeElement.id != null) {
|
|
focused_id = document.activeElement.id;
|
|
}
|
|
outer_height = $('.data-container > div').outerHeight();
|
|
if (outer_height > 300 && outer_height !== _beathaven.last_height) {
|
|
_beathaven.last_height = outer_height;
|
|
_beathaven.redrawScrollbar();
|
|
}
|
|
if (focused_id) {
|
|
document.getElementById(focused_id).focus();
|
|
focused_id = false;
|
|
}
|
|
window.setTimeout(function() {
|
|
_beathaven.checkRedrawScrollbar();
|
|
return false;
|
|
}, 500);
|
|
return false;
|
|
};
|
|
BeatHaven.prototype.redrawScrollbar = function() {
|
|
$('.data-container').html($('.data-container').find('.inner').first());
|
|
$('.data-container').scrollbar();
|
|
return false;
|
|
};
|
|
BeatHaven.prototype.localizeHTML = function(obj, lang) {
|
|
if (obj == null) {
|
|
obj = $('body');
|
|
}
|
|
if (lang == null) {
|
|
lang = _beathaven.lang;
|
|
}
|
|
$(obj).find('[data-ls]').each(function() {
|
|
if ((_locale[$(this).attr('data-ls')] != null) && (_locale[$(this).attr('data-ls')][lang] != null)) {
|
|
if (this.nodeName === 'INPUT') {
|
|
return $(this).val(_locale[$(this).attr('data-ls')][lang]);
|
|
} else {
|
|
return $(this).text(_locale[$(this).attr('data-ls')][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;
|
|
}
|
|
};
|
|
BeatHaven.prototype.pdShowSpinner = function() {
|
|
$('.pulldown').html('<div class="pd-spinner"><img src="/images/loader.gif" alt=""/></div>');
|
|
return false;
|
|
};
|
|
BeatHaven.prototype.pdHideSpinner = function() {
|
|
$('.pulldown').html('');
|
|
return false;
|
|
};
|
|
return BeatHaven;
|
|
})();
|
|
String.prototype.htmlsafe = function() {
|
|
var item, replaces, str, _i, _len;
|
|
replaces = [["\\", "\\\\"], ["\"", """], ["<", "<"], [">", ">"]];
|
|
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;
|
|
}; |