1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-09 01:44:25 +03:00
ifhub.club/templates/skin/developer-jquery/js/vote.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

2011-04-01 10:49:36 +03:00
var vote = {
//==================
2011-04-01 12:54:47 +03:00
// Опции
2011-04-01 10:49:36 +03:00
//==================
classes: {
voted: 'voted',
plus: 'plus',
minus: 'minus',
positive: 'positive',
negative: 'negative',
2011-05-03 10:53:06 +03:00
total: 'total'
2011-04-01 10:49:36 +03:00
},
typeVote: {
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 12:54:47 +03:00
// Функции
2011-04-01 10:49:36 +03:00
//==================
vote: function(idTarget, objVote, value, type) {
if (!this.typeVote[type]) return false;
this.idTarget = idTarget;
this.objVote = $(objVote);
this.value = value;
thisObj = this;
var params = {};
params['value'] = value;
params[this.typeVote[type].targetName] = idTarget;
params['security_ls_key'] = LIVESTREET_SECURITY_KEY;
$.post(this.typeVote[type].url, params, function(result) {
thisObj.onVote(result, thisObj);
});
},
onVote: function(result, thisObj) {
if (result.bStateError) {
$.notifier.error(null, result.sMsg);
} else {
$.notifier.notice(null, result.sMsg);
var divVoting = thisObj.objVote.parent();
divVoting.addClass(thisObj.classes.voted);
if (thisObj.value > 0) {
divVoting.addClass(thisObj.classes.plus);
}
if (thisObj.value < 0) {
divVoting.addClass(thisObj.classes.minus);
}
var divTotal = divVoting.children('.'+thisObj.classes.total);
result.iRating = parseFloat(result.iRating);
divVoting.removeClass(thisObj.classes.negative);
divVoting.removeClass(thisObj.classes.positive);
if (result.iRating > 0) {
divVoting.addClass(thisObj.classes.positive);
divTotal.text(result.iRating);
}
if (result.iRating < 0) {
divVoting.addClass(thisObj.classes.negative);
divTotal.text(result.iRating);
}
if (result.iRating == 0) {
divTotal.text(0);
}
if (thisObj.type == 'user') {
$('#user_skill_'+thisObj.idTarget).text(result.iSkill);
}
}
}
}