mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-01 05:55:02 +03:00
шаблон developer-jquery - начало выноса js функционала в глобальный объект ls
This commit is contained in:
parent
e54dc77a52
commit
12112da96c
|
@ -1,63 +1,87 @@
|
|||
var blocks = {
|
||||
//==================
|
||||
// Опции
|
||||
//==================
|
||||
|
||||
options: {
|
||||
active: 'active',
|
||||
url: {
|
||||
block_stream_item_comment: aRouter['ajax']+'stream/comment/',
|
||||
block_stream_item_topic: aRouter['ajax']+'stream/topic/',
|
||||
block_blogs_item_top: aRouter['ajax']+'blogs/top/',
|
||||
block_blogs_item_join: aRouter['ajax']+'blogs/join/',
|
||||
block_blogs_item_self: aRouter['ajax']+'blogs/self/'
|
||||
}
|
||||
},
|
||||
|
||||
var ls = ls || {};
|
||||
|
||||
//==================
|
||||
// Функции
|
||||
//==================
|
||||
|
||||
load: function(obj, block_id){
|
||||
thisObj = this;
|
||||
objId = $(obj).attr('id');
|
||||
content = $('#'+block_id+'_content');
|
||||
|
||||
content.html($('<div />').css('text-align','center').append($('<img>', {src: IMG_PATH_LOADER})));
|
||||
|
||||
$('[id^="'+block_id+'_item"]').removeClass(this.options.active);
|
||||
$(obj).addClass(this.options.active);
|
||||
|
||||
$.getJSON(this.options.url[objId], {security_ls_key: LIVESTREET_SECURITY_KEY}, function(result){
|
||||
content.empty();
|
||||
|
||||
if (result.bStateError) {
|
||||
$.notifier.error(null, result.sMsg);
|
||||
} else {
|
||||
content.html(result.sText);
|
||||
/**
|
||||
* Динамическая подгрузка блоков
|
||||
*/
|
||||
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/'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Метод загрузки содержимого блока
|
||||
*/
|
||||
this.load = function(obj, block, params){
|
||||
var id = $(obj).attr('id');
|
||||
params=$.extend(true,{},this.options.type[id].params || {},params || {});
|
||||
params.security_ls_key=LIVESTREET_SECURITY_KEY;
|
||||
|
||||
var content = $('#'+block+'_content');
|
||||
this.showProgress(content);
|
||||
|
||||
$(document).ready(function(){
|
||||
$('[id^="'+block+'_item"]').removeClass(this.options.active);
|
||||
$(obj).addClass(this.options.active);
|
||||
|
||||
$.getJSON(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('load',[content,id,result]);
|
||||
content.empty();
|
||||
if (result.bStateError) {
|
||||
$.notifier.error(null, result.sMsg);
|
||||
} else {
|
||||
content.html(result.sText);
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
}).call(ls.blocks || {},jQuery);
|
||||
|
||||
/**
|
||||
* Подключаем действующие блоки
|
||||
*/
|
||||
jQuery(document).ready(function($){
|
||||
$('[id^="block_stream_item"]').click(function(){
|
||||
blocks.load(this, 'block_stream');
|
||||
ls.blocks.load(this, 'block_stream');
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$('[id^="block_blogs_item"]').click(function(){
|
||||
blocks.load(this, 'block_blogs');
|
||||
ls.blocks.load(this, 'block_blogs');
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
|
@ -1,3 +1,10 @@
|
|||
Function.prototype.bind = function(context) {
|
||||
var fn = this;
|
||||
return function() {
|
||||
return fn.apply(context, arguments);
|
||||
};
|
||||
};
|
||||
|
||||
$(document).ready(function(){
|
||||
// Всплывающие окна
|
||||
$('#login_form').jqm({trigger: '#login_form_show'});
|
||||
|
|
|
@ -10,6 +10,7 @@ $config['head']['default']['js'] = array(
|
|||
"___path.static.skin___/js/libs/jquery.rich-array.min.js",
|
||||
"___path.static.skin___/js/libs/markitup/jquery.markitup.js",
|
||||
"___path.static.skin___/js/libs/markitup/sets/default/set.js",
|
||||
"___path.static.skin___/js/main.js",
|
||||
"___path.static.skin___/js/autocomplete.js",
|
||||
"___path.static.skin___/js/favourite.js",
|
||||
"___path.static.skin___/js/blocks.js",
|
||||
|
@ -19,7 +20,6 @@ $config['head']['default']['js'] = array(
|
|||
"___path.static.skin___/js/comments.js",
|
||||
"___path.static.skin___/js/blog.js",
|
||||
"___path.static.skin___/js/friend.js",
|
||||
"___path.static.skin___/js/main.js",
|
||||
);
|
||||
$config['head']['default']['css'] = array(
|
||||
"___path.static.skin___/css/reset.css",
|
||||
|
|
Loading…
Reference in a new issue