PageSourceSearch

https://yasserdivar.ir/wp-content/themes/studiare/assets/js/comment-votes.js?ver=da7ee7672bd5

js yasserdivar.ir collected 2026-10-03 18:48:15 UTC 4,600 bytes, 133 lines download raw bytes

1jQuery(document).ready(function ($) {
2    function getVoteMessage(type, fallback) {
3        if (
4            typeof studiareCommentVotes !== 'undefined' &&
5            studiareCommentVotes.messages &&
6            studiareCommentVotes.messages[type]
7        ) {
8            return studiareCommentVotes.messages[type];
9        }
10
11        return fallback || '';
12    }
13
14    function showVoteToast(type, messageType, fallbackMessage) {
15        var message = getVoteMessage(messageType, fallbackMessage);
16
17        if (!message) {
18            return;
19        }
20
21        if (typeof toastr === 'undefined') {
22            return;
23        }
24
25        if (typeof toaster_args === 'undefined') {
26            window.toaster_args = {
27                positionClass: 'toast-bottom-left',
28                closeButton: true,
29                progressBar: true,
30                timeOut: 4000
31            };
32        }
33
34        if (type === 'success') {
35            toastr.success(message, '<i class="fal fa-check-circle"></i>', toaster_args);
36            return;
37        }
38
39        if (type === 'warning') {
40            toastr.warning(message, '<i class="fal fa-exclamation-triangle"></i>', toaster_args);
41            return;
42        }
43
44        toastr.error(message, '<i class="fal fa-times-circle"></i>', toaster_args);
45    }
46
47    $(document).on('click', '.studiare-comment-vote-btn', function (e) {
48        e.preventDefault();
49
50        var $btn = $(this);
51        var $wrap = $btn.closest('.studiare-comment-votes');
52        var commentId = $wrap.data('comment-id');
53        var voteType = $btn.data('vote');
54
55        if (!commentId || $wrap.hasClass('loading')) {
56            return;
57        }
58
59        $wrap.addClass('loading');
60
61        $.ajax({
62            url: studiareCommentVotes.ajax_url,
63            type: 'POST',
64            dataType: 'json',
65            data: {
66                action: 'studiare_comment_vote',
67                nonce: studiareCommentVotes.nonce,
68                comment_id: commentId,
69                vote_type: voteType
70            },
71            success: function (response) {
72                if (!response) {
73                    showVoteToast('error', 'error', 'Something went wrong. Please try again.');
74                    return;
75                }
76
77                if (!response.success) {
78                    var errorType = response.data && response.data.type ? response.data.type : 'error';
79                    var errorMessage = response.data && response.data.message ? response.data.message : getVoteMessage(errorType, '');
80
81                    if (errorType === 'login_required') {
82                        showVoteToast('error', 'login_required', errorMessage);
83                        return;
84                    }
85
86                    if (errorType === 'already_voted') {
87                        showVoteToast('warning', 'already_voted', errorMessage);
88                        return;
89                    }
90
91                    if (errorType === 'disabled') {
92                        showVoteToast('warning', 'disabled', errorMessage);
93                        return;
94                    }
95
96                    if (errorType === 'dislike_disabled') {
97                        showVoteToast('warning', 'dislike_disabled', errorMessage);
98                        return;
99                    }
100
101                    showVoteToast('error', errorType, errorMessage);
102                    return;
103                }
104
105                $wrap.find('.studiare-comment-vote-btn').removeClass('voted');
106
107                if (response.data.user_vote === 'like') {
108                    $wrap.find('.studiare-comment-vote-btn.like').addClass('voted');
109                }
110
111                if (response.data.user_vote === 'dislike') {
112                    $wrap.find('.studiare-comment-vote-btn.dislike').addClass('voted');
113                }
114
115                if ($wrap.find('.studiare-comment-vote-btn.like .count').length) {
116                    $wrap.find('.studiare-comment-vote-btn.like .count').text(response.data.likes);
117                }
118
119                if ($wrap.find('.studiare-comment-vote-btn.dislike .count').length) {
120                    $wrap.find('.studiare-comment-vote-btn.dislike .count').text(response.data.dislikes);
121                }
122
123                showVoteToast('success', 'success', response.data.message);
124            },
125            error: function () {
126                showVoteToast('error', 'error', 'Something went wrong. Please try again.');
127            },
128            complete: function () {
129                $wrap.removeClass('loading');
130            }
131        });
132    });
133});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.