1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-08 01:14:24 +03:00
ifhub.club/templates/framework/js/livestreet/blocks.js

163 lines
4.2 KiB
JavaScript
Raw Normal View History

var ls = ls || {};
/**
* Динамическая подгрузка блоков
*/
ls.blocks = (function ($) {
/**
* Опции
*/
this.options = {
active: 'active',
loader: DIR_STATIC_SKIN + '/images/loader.gif',
type: {
stream_comment: {
url: aRouter['ajax']+'stream/comment/'
},
stream_topic: {
url: aRouter['ajax']+'stream/topic/'
},
blogs_top: {
url: aRouter['ajax']+'blogs/top/'
},
blogs_join: {
url: aRouter['ajax']+'blogs/join/'
},
blogs_self: {
url: aRouter['ajax']+'blogs/self/'
}
2011-04-01 10:49:36 +03:00
}
};
/**
* Метод загрузки содержимого блока
*/
this.load = function(obj, block, params){
var type = $(obj).data('type');
2012-04-28 09:09:47 +03:00
ls.hook.marker('loadBefore');
if(!type) return;
type=block+'_'+type;
params=$.extend(true,{},this.options.type[type].params || {},params || {});
2011-05-03 00:28:36 +03:00
var content = $('.js-block-'+block+'-content');
this.showProgress(content);
$('.js-block-'+block+'-item').removeClass(this.options.active);
2011-04-01 10:49:36 +03:00
$(obj).addClass(this.options.active);
ls.ajax(this.options.type[type].url, params, function(result){
var args = [content,result];
2012-04-28 09:09:47 +03:00
ls.hook.marker('onLoadBefore');
2012-01-28 17:52:44 +02:00
this.onLoad.apply(this,args);
}.bind(this));
};
/**
* Переключает вкладки в блоке, без использования Ajax
* @param obj
* @param block
*/
this.switchTab = function(obj, block) {
/**
* Если вкладку передаем как строчку - значение data-type
*/
if (typeof(obj)=='string') {
$('.js-block-'+block+'-item').each(function(k,v){
if ($(v).data('type')==obj) {
obj=v;
return;
}
});
}
/**
* Если не нашли такой вкладки
*/
if (typeof(obj)=='string') {
return false;
}
$('.js-block-'+block+'-item').removeClass(this.options.active);
$(obj).addClass(this.options.active);
$('.js-block-'+block+'-content').hide();
$('.js-block-'+block+'-content').each(function(k,v){
if ($(v).data('type')==$(obj).data('type')) {
$(v).show();
}
});
2012-06-30 19:41:41 +03:00
ls.hook.run('ls_blocks_switch_tab_after',[obj, block],this);
return true;
};
/**
* Отображение процесса загрузки
*/
this.showProgress = function(content) {
content.height(content.height());
2012-07-10 17:55:00 +03:00
content.empty().css({'background': 'url(' + this.options.loader + ') no-repeat center top', 'min-height': 70});
};
/**
* Обработка результатов загрузки
*/
this.onLoad = function(content,result) {
2012-02-05 10:11:03 +02:00
$(this).trigger('loadSuccessful',arguments);
2012-07-10 17:55:00 +03:00
content.empty().css({'background': 'none', 'height': 'auto', 'min-height': 0});
if (result.bStateError) {
2011-05-03 00:28:36 +03:00
ls.msg.error(null, result.sMsg);
} else {
content.html(result.sText);
2012-01-28 17:52:44 +02:00
ls.hook.run('ls_block_onload_html_after',arguments,this);
}
};
2011-04-01 10:49:36 +03:00
this.getCurrentItem = function(block) {
if ($('.js-block-'+block+'-nav').is(':visible')) {
return $('.js-block-'+block+'-nav').find('.js-block-'+block+'-item.'+this.options.active);
} else {
return $('.js-block-'+block+'-dropdown-items').find('.js-block-'+block+'-item.'+this.options.active);
}
};
this.initSwitch = function(block) {
$('.js-block-'+block+'-item').click(function(){
ls.blocks.switchTab(this, block);
return false;
});
};
this.init = function(block,params) {
params=params || {};
$('.js-block-'+block+'-item').click(function(){
ls.blocks.load(this, block);
return false;
});
if (params.group_items) {
this.initNavigation(block,params.group_min);
}
var $this=this;
$('.js-block-'+block+'-update').click(function(){
$(this).addClass('active');
ls.blocks.load($this.getCurrentItem(block), block);
setTimeout( function() { $(this).removeClass('active'); }.bind(this), 600 );
});
};
this.initNavigation = function(block,count) {
count=count || 3;
if ($('.js-block-'+block+'-nav').find('li').length >= count) {
$('.js-block-'+block+'-nav').hide();
$('.js-block-'+block+'-dropdown').show();
} else {
// Transform nav to dropdown
$('.js-block-'+block+'-nav').show();
$('.js-block-'+block+'-dropdown').hide();
}
2012-07-01 05:51:31 +03:00
ls.hook.run('ls_blocks_init_navigation_after',[block,count],this);
};
return this;
2012-01-28 17:52:44 +02:00
}).call(ls.blocks || {},jQuery);