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/vote.js

102 lines
2.4 KiB
JavaScript
Raw Normal View History

2011-05-03 13:10:28 +03:00
var ls = ls || {};
/**
* Динамическая подгрузка блоков
*/
ls.vote = (function ($) {
/**
* Опции
*/
this.options = {
classes: {
voted: 'voted',
plus: 'plus',
minus: 'minus',
positive: 'positive',
negative: 'negative'
2011-04-01 10:49:36 +03:00
},
2011-05-03 13:10:28 +03:00
prefix_area: 'vote_area_',
prefix_total: 'vote_total_',
type: {
comment: {
url: aRouter['ajax']+'vote/comment/',
targetName: 'idComment'
},
topic: {
url: aRouter['ajax']+'vote/topic/',
targetName: 'idTopic'
},
blog: {
url: aRouter['ajax']+'vote/blog/',
targetName: 'idBlog'
},
user: {
url: aRouter['ajax']+'vote/user/',
targetName: 'idUser'
}
2011-04-01 10:49:36 +03:00
}
2011-05-03 13:10:28 +03:00
};
this.vote = function(idTarget, objVote, value, type) {
if (!this.options.type[type]) return false;
objVote = $(objVote);
2011-04-01 10:49:36 +03:00
var params = {};
params['value'] = value;
2011-05-03 13:10:28 +03:00
params[this.options.type[type].targetName] = idTarget;
2011-04-01 10:49:36 +03:00
2011-05-03 13:10:28 +03:00
ls.ajax(this.options.type[type].url, params, function(result) {
this.onVote(idTarget, objVote, value, type, result);
}.bind(this));
return false;
}
this.onVote = function(idTarget, objVote, value, type, result) {
2011-04-01 10:49:36 +03:00
if (result.bStateError) {
2011-05-03 13:10:28 +03:00
ls.msg.error(null, result.sMsg);
2011-04-01 10:49:36 +03:00
} else {
2011-05-03 13:10:28 +03:00
ls.msg.notice(null, result.sMsg);
2011-04-01 10:49:36 +03:00
2011-05-03 13:10:28 +03:00
var divVoting = $('#'+this.options.prefix_area+type+'_'+idTarget);
divVoting.addClass(this.options.classes.voted);
if (value > 0) {
divVoting.addClass(this.options.classes.plus);
2011-04-01 10:49:36 +03:00
}
2011-05-03 13:10:28 +03:00
if (value < 0) {
divVoting.addClass(this.options.classes.minus);
2011-04-01 10:49:36 +03:00
}
2011-05-03 13:10:28 +03:00
var divTotal = $('#'+this.options.prefix_total+type+'_'+idTarget);
result.iRating = parseFloat(result.iRating);
divVoting.removeClass(this.options.classes.negative);
divVoting.removeClass(this.options.classes.positive);
if (result.iRating > 0) {
divVoting.addClass(this.options.classes.positive);
2011-08-16 09:08:26 +03:00
divTotal.text('+'+result.iRating);
2011-04-01 10:49:36 +03:00
}
2011-05-03 13:10:28 +03:00
if (result.iRating < 0) {
divVoting.addClass(this.options.classes.negative);
2011-04-01 10:49:36 +03:00
divTotal.text(result.iRating);
}
if (result.iRating == 0) {
divTotal.text(0);
}
2011-05-03 13:10:28 +03:00
var method='onVote'+ls.tools.ucfirst(type);
if (typeof(this[method])=='function') {
this[method].apply(this,[idTarget, objVote, value, type, result]);
2011-04-01 10:49:36 +03:00
}
2011-05-03 13:10:28 +03:00
}
$(this).trigger('vote',[idTarget, objVote, value, type, result]);
}
this.onVoteUser = function(idTarget, objVote, value, type, result) {
$('#user_skill_'+idTarget).text(result.iSkill);
2011-04-01 10:49:36 +03:00
}
2011-05-03 13:10:28 +03:00
return this;
}).call(ls.vote || {},jQuery);