PageSourceSearch

https://gvectors.com/wp-content/plugins/woodiscuz-woocommerce-comments/files/js/wpc-ajax.js?ver=2.3.0

js gvectors.com collected 2026-10-02 05:43:15 UTC 19,380 bytes, 433 lines download raw bytes

1jQuery(document).ready(function ($) {
2    var wpc_home_url = $('#wpc_home_url').val();
3    var wpc_plugin_dir_url = $('#wpc_plugin_dir_url').val();
4    var wpc_name;
5    var wpc_email;
6    var wpc_comment;
7    var wpc_captcha;
8    var wpc_comment_post_ID;
9    var wpc_comment_parent;
10    var wpc_form;
11    var wpc_submitID;
12    var wpc_comments_offset;
13    var wpc_new_comment_id;
14    var wpc_loading_image;
15    var wpc_comment_text_before_editting;
16    $(".wpc_comment").autoGrow();
17
18    $(document).on('click', '#wpc_openModalFormAction', function () {
19        $('#wpc_openModalFormAction').css('opacity', '0');
20        $('#wpc_openModalFormAction').css('pointer-events', 'none');
21    });
22
23    $(document).on('click', '#wpc_openModalFormAction .close', function () {
24        $('#wpc_openModalFormAction').css('opacity', '0');
25        $('#wpc_openModalFormAction').css('pointer-events', 'none');
26    });
27
28    wpc_loading_image = "<img width='64' height='64' src='" + wpc_home_url + '/' + wpc_plugin_dir_url + "/files/img/loader/ajax-loader-200x200.gif' />";
29    wpc_comments_offset = $('#wpc_comments_offset');
30    wpc_comments_offset.val('1');
31
32    $(document).on('focus', '.wpc_comment', function () {
33        var uniqueID = getUniqueID($(this));
34        $('#wpc-form-footer-' + uniqueID).slideDown(700);
35    });
36
37
38    $(document).on('click', '.wpc-reply-link', function () {
39        var uniqueID = getUniqueID($(this));
40        $('#wpc-secondary-forms-wrapper-' + uniqueID).slideToggle(700);
41    });
42
43    $(document).on('click', '.wpc-share-link', function () {
44        var uniqueID = getUniqueID($(this));
45        $('#share_buttons_box-' + uniqueID).slideToggle(1000);
46    });
47
48    $(document).on('click', '.wpc_captcha_refresh_img', function () {
49        var uniqueID = getUniqueID($(this));
50        var wpc_commpost_ID = $('#wpc_comment_post_ID-' + uniqueID).val();
51        var wpc_commparent = $('#wpc_comment_parent-' + uniqueID).val();
52        $("#wpc_captcha_img-" + uniqueID).attr("src", wpc_home_url + "/" + wpc_plugin_dir_url + "/captcha/captcha.php?comm_id=" + wpc_commpost_ID + '-' + wpc_commparent + '&r=' + Math.random());
53    });
54
55    $(document).on('click', '.wpc_comm_submit', function () {
56        wpc_submitID = $(this).attr('id');
57        var uniqueID = wpc_submitID.substring(wpc_submitID.lastIndexOf('-') + 1);
58        wpc_name = $('#wpc_name-' + uniqueID).val();
59        wpc_email = $('#wpc_email-' + uniqueID).val();
60        wpc_comment = $('textarea#wpc_comment-' + uniqueID).val();
61        wpc_captcha = $('#wpc_captcha-' + uniqueID).val();
62        wpc_comment_post_ID = $('#wpc_comment_post_ID-' + uniqueID).val();
63        wpc_comment_parent = $('#wpc_comment_parent-' + uniqueID).val();
64        wpc_form = $('#wpc_comm_form-' + uniqueID);
65
66        var depth = '';
67        if (isMainFormSubmit(wpc_submitID, wpc_comment_post_ID)) {
68            depth = 1;
69        } else {
70            depth = getCommentDepth($(this).parents('.wpc-comment'));
71        }
72
73        var submit = true;
74        // evaluate the form using generic validaing
75        if (!woodiscuzValidator.checkAll(wpc_form)) {
76            submit = false;
77            $('#wpc_captcha-' + uniqueID).val('');
78            $("#wpc_captcha_img-" + uniqueID).attr("src", wpc_home_url + "/" + wpc_plugin_dir_url + "/captcha/captcha.php?comm_id=" + wpc_comment_post_ID + '-' + wpc_comment_parent + '&r=' + Math.random());
79        } else {
80            $('#wpc_openModalFormAction .close').css('display', 'none');
81            $('#wpc_openModalFormAction').css('opacity', '1');
82            $('#wpc_openModalFormAction').css('pointer-events', 'auto');
83            $('#wpc_openModalFormAction > #wpc_response_info').html(wpc_loading_image);
84        }
85
86        var notification_type = '';
87        var notification_type_radio = $("input[name='wpc_notification_new_reply-" + uniqueID + "']:checked").length ? $("input[name='wpc_notification_new_reply-" + uniqueID + "']:checked").val() : '';
88
89        if (notification_type_radio.length) {
90            if (notification_type_radio == 'wpc_notification_new_reply') {
91                notification_type = 'reply';
92            }
93        }
94
95        if (submit) {
96            $.ajax({
97                type: 'POST',
98                url: wpc_ajax_obj.url,
99                data: {
100                    name: wpc_name,
101                    email: wpc_email,
102                    comment: wpc_comment,
103                    captcha: wpc_captcha,
104                    comment_depth: depth,
105                    comment_post_ID: wpc_comment_post_ID,
106                    comment_parent: wpc_comment_parent,
107                    notification_type: notification_type,
108                    action: 'wpc_comms_via_ajax'
109                }
110            }).done(function (response) {
111                $("#wpc_captcha_img-" + uniqueID).attr("src", wpc_home_url + "/" + wpc_plugin_dir_url + "/captcha/captcha.php?comm_id=" + wpc_comment_post_ID + '-' + wpc_comment_parent + '&r=' + Math.random());
112                var obj = $.parseJSON(response);
113                wpc_new_comment_id = parseInt(obj.wpc_new_comment_id);
114                if (obj.code === -1) {
115                    $('#wpc_response_info').html(obj.message);
116                } else if (obj.code === -2) {
117                    var html = "<a href='#close' title='Close' class='close'>&nbsp;</a>";
118                    $('#wpc_response_info').html(html + obj.message);
119                    $('#wpc_openModalFormAction .close').css('display', 'block');
120                    $('#wpc_comment-' + uniqueID).val('');
121                    $('.wpc_comm_form textarea').css('height', '46px');
122
123                    if (wpc_submitID === 'wpc_comm-' + wpc_comment_post_ID + '_0') {
124                        $('#wpc-form-footer-' + uniqueID).slideToggle(700);
125                    } else {
126                        $('#wpc-secondary-forms-wrapper-' + uniqueID).slideToggle(700);
127                    }
128                    $.cookie('wpc_author_name', wpc_name);
129                    $.cookie('wpc_author_email', wpc_email);
130                    $.cookie('wpc_poster', wpc_email, 60 * 60 * 24 * 365 * 10);
131
132                } else {
133                    $('#wpc_comment-' + uniqueID).val('');
134                    $('.wpc_comm_form textarea').css('height', '46px');
135
136                    if (wpc_submitID === 'wpc_comm-' + wpc_comment_post_ID + '_0') {
137                        $('.wpc-thread-wrapper').prepend(obj.message);
138                        $('#wpc-form-footer-' + uniqueID).slideToggle(700);
139                    } else {
140                        $('#wpc-secondary-forms-wrapper-' + uniqueID).slideToggle(700);
141
142                        if (obj.is_in_same_container == 1) {
143                            $('#wpc-secondary-forms-wrapper-' + uniqueID).after(obj.message);
144                        } else {
145                            $('#wpc-secondary-forms-wrapper-' + uniqueID).after(obj.message.replace('wpc-reply', 'wpc-reply wpc-no-left-margin'));
146                        }
147                    }
148                    $('#wpc_openModalFormAction').css('opacity', '0');
149                    $('#wpc_openModalFormAction').css('pointer-events', 'none');
150                    if (wpc_name !== '' && wpc_email !== '') {
151                        $.cookie('wpc_author_name', wpc_name);
152                        $.cookie('wpc_author_email', wpc_email);
153                        $('#woopcomm .wpc_name').val(wpc_name);
154                        $('#woopcomm .wpc_email').val(wpc_email);
155                    }
156
157                    $.cookie('wpc_poster', wpc_email, 60 * 60 * 24 * 365 * 10);
158
159                    if (wpc_new_comment_id !== -1) {
160                        notify_on_new_comment(wpc_comment_post_ID, wpc_new_comment_id, wpc_email);
161                    }
162                }
163                $('#wpc_captcha-' + uniqueID).val('');
164                $('.wpc_tooltipster').tooltipster({offsetY: 2,multiple:true});
165                $('.wpc_comm_form input').css('box-shadow', '0 0 4px -2px #d4d0ba');
166                $('.wpc_comm_form textarea').css('box-shadow', '0 0 4px -2px #d4d0ba');
167
168
169                // call redirection if comment added successfully
170                if ((obj.code == 1 || obj.code == -2) && $('form.wpc_main_form').hasClass('wpc-no-comments')) {
171                    $.ajax({
172                        type: 'POST',
173                        url: wpc_ajax_obj.url,
174                        data: {
175                            wpc_new_comment_id: wpc_new_comment_id,
176                            action: 'woodiscuz_comment_redirect'
177                        }
178                    }).done(function (redirectResponse) {
179                        try {
180                            var redirectObj = $.parseJSON(redirectResponse);
181                            if (redirectObj.code == 1) {
182                                setTimeout(function () {
183                                    window.location.href = redirectObj.redirect_to;
184                                }, 5000)
185                            }
186                        } catch (e) {
187
188                        }
189                    });
190                }
191            });
192        }
193        else {
194            return false;
195        }
196    });
197
198
199
200    $(document).on('click', '.wpc_vote', function () {
201        var uniqueID = getUniqueID($(this));
202        var commentID = getCommentID(uniqueID);
203        var voteType;
204
205        $('#wpc_openModalFormAction > #wpc_response_info').html(wpc_loading_image);
206        $('#wpc_openModalFormAction .close').css('display', 'block');
207        $('#wpc_openModalFormAction').css('opacity', '1');
208        $('#wpc_openModalFormAction').css('pointer-events', 'auto');
209        if ($(this).hasClass('wpc-up')) {
210            voteType = 1;
211        } else {
212            voteType = -1;
213        }
214
215        $.ajax({
216            dateType: 'json',
217            type: 'POST',
218            url: wpc_ajax_obj.url,
219            data: {
220                comment_ID: commentID,
221                vote_type: voteType,
222                action: 'wpc_vote_via_ajax'
223            }
224        }).done(function (response) {
225            var obj = $.parseJSON(response);
226
227            if (obj.code !== -1) {
228                $('#vote-count-' + uniqueID).text(parseInt($('#vote-count-' + uniqueID).text()) + voteType);
229                $('#wpc_openModalFormAction').css('opacity', '0');
230                $('#wpc_openModalFormAction').css('pointer-events', 'none');
231            } else {
232                var html = "<a href='#close' title='Close' class='close'>&nbsp;</a>";
233                $('#wpc_response_info').html(html + obj.message);
234                $('#wpc_openModalFormAction .close').css('display', 'block');
235            }
236        });
237    });
238
239    $(document).on('click', '.wpc-load-more-submit', function () {
240        $('#wpc_openModalFormAction > #wpc_response_info').html(wpc_loading_image);
241        $('#wpc_openModalFormAction .close').css('display', 'none');
242        $('#wpc_openModalFormAction').css('opacity', '1');
243        $('#wpc_openModalFormAction').css('pointer-events', 'auto');
244
245        var wpc_comments_offset_value = wpc_comments_offset.val();
246        var wpc_post_id = getPostID($(this).attr('id'));
247        var wpc_parent_comments_count = parseInt($('#wpc_parent_comments_count').val());
248        var wpc_parent_per_page = parseInt($('#wpc_parent_per_page').val());
249
250        wpc_comments_offset_value = parseInt(wpc_comments_offset_value);
251        wpc_comments_offset_value++;
252
253        $.ajax({
254            type: 'POST',
255            url: wpc_ajax_obj.url,
256            data: {
257                comments_offset: wpc_comments_offset_value,
258                wpc_post_id: wpc_post_id,
259                action: 'wpc_load_more_comments'
260            }
261        }).done(function (response) {
262            wpc_comments_offset.val(wpc_comments_offset_value);
263            if (wpc_parent_comments_count <= (wpc_comments_offset_value * wpc_parent_per_page)) {
264                $('.wpc-load-more-submit-wrap').remove();
265            }
266            $('.wpc-thread-wrapper').html(response);
267            $('#wpc_openModalFormAction').css('opacity', '0');
268            $('#wpc_openModalFormAction').css('pointer-events', 'none');
269            $('.wpc_tooltipster').tooltipster({offsetY: 2});
270        });
271    });
272
273    function getUniqueID(field) {
274        var fieldID = field.attr('id');
275        var uniqueID = fieldID.substring(fieldID.lastIndexOf('-') + 1);
276        return uniqueID;
277    }
278
279    function getPostID(uniqueID) {
280        var postID = uniqueID.substring(uniqueID.lastIndexOf('-') + 1);
281        postID = postID.substring(0, postID.lastIndexOf('_'));
282        return postID;
283    }
284
285    function getCommentID(uniqueID) {
286        var commentID = uniqueID.substring(uniqueID.indexOf('_') + 1);
287        return commentID;
288    }
289
290    function notify_on_new_comment(post_id, comment_id, email) {
291        $.ajax({
292            type: 'POST',
293            url: wpc_ajax_obj.url,
294            data: {
295                wpc_post_id: post_id,
296                wpc_comment_id: comment_id,
297                wpc_email: email,
298                action: 'wpc_check_notification_type'
299            }
300        });
301    }
302
303
304    $(document).on('click', '.wpc_editable_comment', function () {
305        var uniqueID = getUniqueID($(this));
306        var commentID = getCommentID(uniqueID);
307
308        $.ajax({
309            type: 'POST',
310            url: wpc_ajax_obj.url,
311            data: {
312                comment_id: commentID,
313                action: 'wpc_get_editable_comment_content'
314            }
315        }).done(function (response) {
316            try {
317                var obj = $.parseJSON(response);
318                if (obj.code == 1) {
319                    wpc_comment_text_before_editting = obj.message;
320                    var editableTextarea = '<textarea required="required" name="wpc_comment" class="wpc_comment wpc_field_input wpc_edit_comment" id="wpc_edit_comment-' + uniqueID + '" style="min-height: 2em;">' + obj.message + '</textarea>';
321                    $('#wpc-comm-' + uniqueID + ' > .wpc-comment-right .wpc-comment-text').replaceWith(editableTextarea);
322                    document.getElementById('wpc_edit_comment-' + uniqueID).trigger('focus');
323                    $('#wpc_save_edited_comment-' + uniqueID).show();
324                    editableTextarea = '';
325                    $('#wpc_editable_comment-' + uniqueID).hide();
326                    $('#wpc_cancel_edit-' + uniqueID).show();
327                } else {
328                    var html = "<a href='#close' title='Close' class='close'>&nbsp;</a>";
329                    $('#wpc_openModalFormAction').css('opacity', '1');
330                    $('#wpc_openModalFormAction').css('pointer-events', 'auto');
331                    $('#wpc_openModalFormAction .close').css('display', 'block');
332                    $('#wpc_openModalFormAction > #wpc_response_info').html(html + obj.phrase_message);
333                }
334            } catch (e) {
335                console.log(e);
336            }
337        });
338    });
339
340    $(document).on('click', '.wpc_save_edited_comment', function () {
341        var uniqueID = getUniqueID($(this));
342        var commentID = getCommentID(uniqueID);
343        var editableTextarea = $('#wpc-comm-' + uniqueID + ' textarea#wpc_edit_comment-' + uniqueID);
344        var commentContent = editableTextarea.val();
345        var submit = true;
346        if ($.trim(commentContent).length <= 0) {
347            submit = false;
348        }
349
350        if (submit) {
351            $('#wpc_openModalFormAction .close').css('display', 'none');
352            $('#wpc_openModalFormAction').css('opacity', '1');
353            $('#wpc_openModalFormAction').css('pointer-events', 'auto');
354            $('#wpc_openModalFormAction > #wpc_response_info').html(wpc_loading_image);
355
356            $.ajax({
357                type: 'POST',
358                url: wpc_ajax_obj.url,
359                data: {
360                    comment_id: commentID,
361                    comment_content: commentContent,
362                    action: 'wpc_save_edited_comment'
363                }
364            }).done(function (response) {
365                try {
366                    var obj = $.parseJSON(response);
367                    if (obj.code == 1) {
368                        $('#wpc_openModalFormAction').css('opacity', '0');
369                        $('#wpc_openModalFormAction').css('pointer-events', 'none');
370                        wpc_cancel_or_save(uniqueID, obj.message);
371                    } else {
372                        var html = "<a href='#close' title='Close' class='close'>&nbsp;</a>";
373                        $('#wpc_openModalFormAction').css('opacity', '1');
374                        $('#wpc_openModalFormAction').css('pointer-events', 'auto');
375                        $('#wpc_openModalFormAction .close').css('display', 'block');
376                        $('#wpc_openModalFormAction > #wpc_response_info').html(html + obj.phrase_message);
377                    }
378                    editableTextarea = '';
379                    commentContent = '';
380                } catch (e) {
381                    console.log(e);
382                }
383            });
384        }
385    });
386
387    $(document).on('click', '.wpc_cancel_edit', function () {
388        var uniqueID = getUniqueID($(this));
389        wpc_cancel_or_save(uniqueID, wpc_comment_text_before_editting);
390    });
391
392    function wpc_cancel_or_save(uniqueID, content) {
393        $('#wpc_editable_comment-' + uniqueID).show();
394        $('#wpc_cancel_edit-' + uniqueID).hide();
395        $('#wpc_save_edited_comment-' + uniqueID).hide();
396        var commentContentWrapper = '<div class="wpc-comment-text">' + nl2br(content) + '</div>';
397        $('#wpc-comm-' + uniqueID + ' #wpc_edit_comment-' + uniqueID).replaceWith(commentContentWrapper);
398    }
399
400    function nl2br(str, is_xhtml) {
401        var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br/>' : '<br>';
402        var string = (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
403        return string.replace('<br><br>', '<br/>');
404    }
405
406    function getCommentDepth(field) {
407        var fieldClasses = field.attr('class');
408        var classesArray = fieldClasses.split(' ');
409        var depth = '';
410        $.each(classesArray, function (index, value) {
411            ;
412            if ('wpc_comment_level' === getParentDepth(value, false)) {
413                depth = getParentDepth(value, true);
414            }
415        });
416        return parseInt(depth) + 1;
417    }
418
419    function getParentDepth(depthValue, isNumberPart) {
420        var depth = '';
421        if (isNumberPart) {
422            depth = depthValue.substring(depthValue.indexOf('-') + 1);
423        } else {
424            depth = depthValue.substring(0, depthValue.indexOf('-'));
425        }
426        return depth;
427    }
428
429    function isMainFormSubmit(wpc_submitID, wpc_comment_post_ID) {
430        return wpc_submitID === 'wpc_comm-' + wpc_comment_post_ID + '_0';
431    }
432    $('.wpc_tooltipster').tooltipster({offsetY: 2});
433});

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.