1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-05 16:04:24 +03:00
ifhub.club/templates/skin/developer-jquery/js/favourite.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2011-05-03 10:53:06 +03:00
var ls = ls || {};
2011-04-01 10:49:36 +03:00
2011-05-03 10:53:06 +03:00
/**
* Добавление в избранное
*/
ls.favourite = (function ($) {
/**
* Опции
*/
this.options = {
active: 'active',
type: {
topic: {
url: aRouter['ajax']+'favourite/topic/',
targetName: 'idTopic'
},
talk: {
url: aRouter['ajax']+'favourite/talk/',
targetName: 'idTalk'
},
comment: {
url: aRouter['ajax']+'favourite/comment/',
targetName: 'idComment'
}
2011-04-01 10:49:36 +03:00
}
2011-05-03 10:53:06 +03:00
};
2011-04-01 10:49:36 +03:00
2011-05-03 10:53:06 +03:00
/**
* Переключение избранного
*/
this.toggle = function(idTarget, objFavourite, type) {
if (!this.options.type[type]) { return false; }
this.objFavourite = $(objFavourite);
2011-04-01 10:49:36 +03:00
var params = {};
2011-05-03 10:53:06 +03:00
params['type'] = !this.objFavourite.hasClass(this.options.active);
params[this.options.type[type].targetName] = idTarget;
2011-04-01 10:49:36 +03:00
2011-05-03 10:53:06 +03:00
ls.ajax(this.options.type[type].url, params, function(result) {
$(this).trigger('toggle',[idTarget,objFavourite,type,params,result]);
2011-04-01 10:49:36 +03:00
if (result.bStateError) {
2011-05-03 10:53:06 +03:00
ls.msg.error(null, result.sMsg);
2011-04-01 10:49:36 +03:00
} else {
2011-05-03 10:53:06 +03:00
ls.msg.notice(null, result.sMsg);
this.objFavourite.removeClass(this.options.active);
2011-04-01 10:49:36 +03:00
if (result.bState) {
2011-05-03 10:53:06 +03:00
this.objFavourite.addClass(this.options.active);
2011-04-01 10:49:36 +03:00
}
2011-05-03 10:53:06 +03:00
}
}.bind(this));
return false;
2011-04-01 10:49:36 +03:00
}
2011-05-03 10:53:06 +03:00
return this;
}).call(ls.favourite || {},jQuery);