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/skin/developer-jquery/js/blocks.js

91 lines
2.1 KiB
JavaScript
Raw Normal View History

var ls = ls || {};
/**
* Динамическая подгрузка блоков
*/
ls.blocks = (function ($) {
/**
* Опции
*/
this.options = {
active: 'active',
loader: DIR_STATIC_SKIN + '/images/loader.gif',
type: {
block_stream_item_comment: {
url: aRouter['ajax']+'stream/comment/'
},
block_stream_item_topic: {
url: aRouter['ajax']+'stream/topic/'
},
block_blogs_item_top: {
url: aRouter['ajax']+'blogs/top/'
},
block_blogs_item_join: {
url: aRouter['ajax']+'blogs/join/'
},
block_blogs_item_self: {
url: aRouter['ajax']+'blogs/self/'
}
2011-04-01 10:49:36 +03:00
}
};
/**
* Метод загрузки содержимого блока
*/
this.load = function(obj, block, params){
var id = $(obj).attr('id');
2012-01-17 21:15:52 +02:00
'*loadBefore*'; '*/loadBefore*';
if(!id) return;
params=$.extend(true,{},this.options.type[id].params || {},params || {});
2011-05-03 00:28:36 +03:00
var content = $('#'+block+'_content');
this.showProgress(content);
$('[id^="'+block+'_item"]').removeClass(this.options.active);
2011-04-01 10:49:36 +03:00
$(obj).addClass(this.options.active);
2011-05-03 00:28:36 +03:00
ls.ajax(this.options.type[id].url, params, function(result){
this.onLoad(content,id,result);
}.bind(this));
};
/**
* Отображение процесса загрузки
*/
this.showProgress = function(content) {
content.html($('<div />').css('text-align','center').append($('<img>', {src: this.options.loader})));
};
/**
* Обработка результатов загрузки
*/
this.onLoad = function(content,id,result) {
$(this).trigger('loadSuccessful',[content,id,result]);
content.empty();
if (result.bStateError) {
2011-05-03 00:28:36 +03:00
ls.msg.error(null, result.sMsg);
} else {
content.html(result.sText);
ls.hook.run('ls_block_onload_html_after',[content,id,result],this);
}
};
2011-04-01 10:49:36 +03:00
return this;
}).call(ls.blocks || {},jQuery);
2011-04-01 10:49:36 +03:00
/**
* Подключаем действующие блоки
*/
jQuery(function($){
2011-04-01 10:49:36 +03:00
$('[id^="block_stream_item"]').click(function(){
ls.blocks.load(this, 'block_stream');
2011-04-01 10:49:36 +03:00
return false;
});
2011-04-01 10:49:36 +03:00
$('[id^="block_blogs_item"]').click(function(){
ls.blocks.load(this, 'block_blogs');
2011-04-01 10:49:36 +03:00
return false;
});
});