function document body delegate vote_button click function stopImmedia

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
$(function () {
$(document.body).delegate('.vote_button', 'click', function (e) {
e.stopImmediatePropagation();
e.preventDefault();
e.stopPropagation();
var $this = $(this);
if ($this.hasClass('disabled_button'))
return;
var vote_id = $this.data('vote_id');
var like_up = $this.hasClass('voteUpCnt');
var full_cnt_el = $('#' + vote_id + '_vt_full_cnt'),
vote_wrap = $('#' + vote_id + '_vote_wrapper'),
full_cnt = parseInt(full_cnt_el.text()),
vote_icon = $this.find('.vote_ico'),
like_up_btn = like_up ? $this : vote_wrap.find('.voteUpCnt'),
like_down_btn = !like_up ? $this : vote_wrap.find('.voteDownCnt'),
minus_cnt = like_down_btn.data('cnt'),
plus_cnt = like_up_btn.data('cnt');
var api_method, api_data = {
CK: null,
Oid: $this.data('oid'),
Ot: $this.data('ot'),
};
var voted = vote_icon.hasClass('on');
var opposite_btn = vote_wrap.find(like_up ? '.voteDownCnt' : '.voteUpCnt');
// Удаляем все .on у иконок, заодно проверим, смена полярности ли это
var is_change_polarity = vote_wrap.find('.vote_ico.on').removeClass('on').length > 0 && !voted;
if (voted) {
// Удаление голоса
full_cnt += !like_up ? 1 : -1;
like_up ? --plus_cnt : --minus_cnt;
api_method = "voting.delete";
} else if (is_change_polarity) {
// Смена полярности голоса
full_cnt += like_up ? 2 : -2;
plus_cnt += like_up ? 1 : -1;
minus_cnt += !like_up ? 1 : -1;
vote_icon.addClass('on');
api_method = "voting.like";
api_data.Down = like_up ? 0 : 1;
} else {
// Обычный голос
full_cnt += like_up ? 1 : -1;
like_up ? ++plus_cnt : ++minus_cnt;
vote_icon.addClass('on');
api_method = "voting.like";
api_data.Down = like_up ? 0 : 1;
}
full_cnt_el.text(full_cnt);
if (full_cnt > 0)
full_cnt_el.css('color', 'green');
else if (full_cnt < 0)
full_cnt_el.css('color', 'red');
else
full_cnt_el.css('color', '');
like_up_btn.data('cnt', plus_cnt)
.prop("title", "За " + plus_cnt);
like_down_btn.data('cnt', minus_cnt)
.prop("title", "Против " + minus_cnt);
var counter = $('#' + vote_id + '_vt_cnt');
counter.find('.voteUpInfo').text(plus_cnt);
counter.find('.voteDownInfo').text(minus_cnt);
Spaces.api(api_method, api_data, function (res) {
if (res.code != 0)
Spaces.showError(Spaces.services.processingCodes(res));
});
});
});