PageSourceSearch

https://abapblog.github.io/wp-content/plugins/wp-poll/assets/front/js/scripts.js?ver=5.8.1

js abapblog.github.io collected 2026-10-03 08:32:14 UTC 6,081 bytes, 193 lines download raw bytes

1/**
2 * Front Script
3 */
4
5(function ($, window, document, pluginObject) {
6    "use strict";
7
8    $(document).on('click', '.wpp-get-poll-results', function () {
9
10        let pollID = $(this).data('poll-id');
11
12        if (typeof pollID === 'undefined') {
13            return;
14        }
15
16        let singlePoll = $('#poll-' + pollID);
17
18        singlePoll.find('.wpp-responses').slideUp();
19
20        $.ajax({
21            type: 'POST',
22            context: this,
23            url: pluginObject.ajaxurl,
24            data: {
25                'action': 'wpp_get_poll_results',
26                'poll_id': pollID,
27            },
28            success: function (response) {
29
30                if (!response.success) {
31                    singlePoll.find('.wpp-responses').addClass('wpp-error').html(response.data).slideDown();
32                    return;
33                }
34
35                singlePoll.find('.wpp-options .wpp-option-single').each(function () {
36
37                    let optionID = $(this).data('option-id'),
38                        percentageValue = response.data.percentages[optionID],
39                        singleVoteCount = response.data.singles[optionID],
40                        classTobeAdded = '';
41
42                    if (typeof percentageValue === 'undefined') {
43                        percentageValue = 0;
44                    }
45
46                    if (typeof singleVoteCount === 'undefined' || singleVoteCount.length === 0) {
47                        singleVoteCount = 0;
48                    }
49
50                    if (percentageValue <= 25) {
51                        classTobeAdded = 'results-danger';
52                    } else if (percentageValue > 25 && percentageValue <= 50) {
53                        classTobeAdded = 'results-warning';
54                    } else if (percentageValue > 50 && percentageValue <= 75) {
55                        classTobeAdded = 'results-info';
56                    } else {
57                        classTobeAdded = 'results-success';
58                    }
59
60                    if ($.inArray(optionID, response.data.percentages)) {
61                        $(this).addClass('has-result').find('.wpp-option-result-bar').addClass(classTobeAdded).css('width', percentageValue + '%');
62                        $(this).find('.wpp-option-result').html(singleVoteCount + ' ' +  pluginObject.voteText);
63                    }
64                });
65            }
66        });
67    });
68
69
70    $(document).on('click', '.wpp-submit-poll', function () {
71
72        let pollID = $(this).data('poll-id');
73
74        if (typeof pollID === 'undefined') {
75            return;
76        }
77
78        let singlePoll = $('#poll-' + pollID), checkedData = [];
79
80        singlePoll.find('.wpp-options .wpp-option-single input[name="submit_poll_option"]').each(function () {
81            if ($(this).is(':checked')) {
82                checkedData.push(this.value);
83            }
84        });
85
86        singlePoll.find('.wpp-responses').slideUp();
87
88        $.ajax({
89            type: 'POST',
90            context: this,
91            url: pluginObject.ajaxurl,
92            data: {
93                'action': 'wpp_submit_poll',
94                'poll_id': pollID,
95                'checked_data': checkedData,
96            },
97            success: function (response) {
98                if (!response.success) {
99                    singlePoll.find('.wpp-responses').addClass('wpp-error').html(response.data).slideDown();
100                } else {
101                    /**
102                     * Trigger to enhance on Success of Poll Submission
103                     *
104                     * @trigger wpp_poll_submission_success
105                     */
106                    $(document.body).trigger('wpp_poll_submission_success', response);
107
108                    singlePoll.find('.wpp-responses').addClass('wpp-success').html(response.data).slideDown();
109                }
110            }
111        });
112    });
113
114
115    $(document).on('click', 'p.wpp-responses', function () {
116        $(this).slideUp();
117    });
118
119
120    $(document).on('click', '.wpp-new-option > button', function () {
121
122        let popupBoxContainer = $(this).parent().parent().parent(),
123            pollID = $(this).data('pollid'),
124            optionField = $(this).parent().find('input[type="text"]'),
125            optionValue = optionField.val();
126
127        if (typeof pollID === "undefined" || pollID.length === 0 ||
128            typeof optionValue === "undefined" || optionValue.length === 0) {
129
130            $(this).parent().find('span').fadeIn(100);
131            return;
132        }
133
134        $.ajax({
135            type: 'POST',
136            context: this,
137            url: pluginObject.ajaxurl,
138            data: {
139                'action': 'wpp_front_new_option',
140                'poll_id': pollID,
141                'opt_val': optionValue,
142            },
143            success: function (response) {
144
145                if (response.success) {
146
147                    popupBoxContainer.parent().find('.wpp-options').append(response.data);
148                    popupBoxContainer.fadeOut().find('input[type="text"]').val('');
149                }
150            }
151        });
152
153    });
154
155
156    $(document).on('keyup', '.wpp-new-option input[type="text"]', function (e) {
157        if (e.which === 13) {
158            $(this).parent().find('.wpp-button').trigger('click');
159        }
160
161        if ($(this).val().length > 0) {
162            $(this).parent().find('span').hide();
163        }
164    });
165
166
167    $(document).on('click', '.wpp-button-new-option', function () {
168        $(this).parent().parent().find('.wpp-popup-container').fadeIn().find('input[type="text"]').focus();
169    });
170
171
172    $(document).on('click', '.wpp-popup-container .box-close', function () {
173        $(this).parent().parent().fadeOut();
174    });
175
176
177    $(document).on('click', '.wpp-options .wpp-option-single', function (e) {
178
179        let outsideInputArea = $(this).find('.wpp-option-input');
180
181        if (!outsideInputArea.is(e.target) && outsideInputArea.has(e.target).length === 0) {
182            $(this).find('label').trigger('click');
183        }
184    });
185
186})(jQuery, window, document, wpp_object);
187
188
189
190
191
192
193

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.