PageSourceSearch

https://adodo.co.uk/wp-content/plugins/xagio-seo/modules/reviews/review_widget_form.js?ver=7.1.0.37

js adodo.co.uk collected 2026-10-04 05:20:31 UTC 16,743 bytes, 383 lines download raw bytes

1// Store the widgets
2let ps_widgets = [];
3if (typeof (ps_widgets) == 'undefined') {
4    jQuery(document).ready(function () {
5        ps_widgets.push({
6                            name: xagio_review_data.unique_id,
7                            data: {
8                                ps_admin_url       : xagio_review_data.ps_admin_url,
9                                ps_thank_you       : xagio_review_data.ps_thank_you,
10                                ps_rating_thank_you: xagio_review_data.ps_rating_thank_you,
11                                ps_stars_only      : xagio_review_data.ps_stars_only,
12                                ps_stars_init      : xagio_review_data.ps_stars_init
13                            }
14                        });
15    });
16} else {
17    ps_widgets.push({
18                        name: xagio_review_data.unique_id,
19                        data: {
20                            ps_admin_url       : xagio_review_data.ps_admin_url,
21                            ps_thank_you       : xagio_review_data.ps_thank_you,
22                            ps_rating_thank_you: xagio_review_data.ps_rating_thank_you,
23                            ps_stars_only      : xagio_review_data.ps_stars_only,
24                            ps_stars_init      : xagio_review_data.ps_stars_init
25                        }
26                    });
27}
28
29// Activate Widget
30let ps_activate_widget = function ($, widget) {
31    'use strict';
32    let widgetContainer = $('.' + widget.name);
33    let render          = {
34        fields      : {
35            name     : {
36                type          : "text",
37                label         : "Name:",
38                placeholder   : "eg. John",
39                altplaceholder: "Your Name",
40                visible       : true
41            },
42            review   : {
43                type          : "textarea",
44                label         : "Review:",
45                placeholder   : "eg. This is really a cool website!",
46                altplaceholder: "Your Review",
47                visible       : true
48            },
49            rating   : {
50                type          : "stars",
51                label         : "Rating:",
52                placeholder   : "",
53                altplaceholder: "",
54                visible       : true
55            },
56            email    : {
57                type          : "email",
58                label         : "E-Mail Address:",
59                placeholder   : "eg. [email protected]",
60                altplaceholder: "E-Mail Address",
61                visible       : false
62            },
63            website  : {
64                type          : "url",
65                label         : "Website:",
66                placeholder   : "eg. http://www.website.com",
67                altplaceholder: "Your Website",
68                visible       : false
69            },
70            title    : {
71                type          : "text",
72                label         : "Title:",
73                placeholder   : "eg. I like this product",
74                altplaceholder: "Your Title",
75                visible       : false
76            },
77            telephone: {
78                type          : "text",
79                label         : "Telephone:",
80                placeholder   : "eg. 1-800-500-6000",
81                altplaceholder: "Your Phone Number",
82                visible       : false
83            },
84            location : {
85                type          : "text",
86                label         : "Location:",
87                placeholder   : "eg. Los Angeles",
88                altplaceholder: "Your Location",
89                visible       : false
90            },
91            age      : {
92                type          : "number",
93                label         : "Age:",
94                placeholder   : "eg. 35",
95                altplaceholder: "Your Age",
96                visible       : false
97            }
98        },
99        init        : function () {
100            render.firstStart();
101            render.doRender();
102        },
103        firstStart  : function () {
104            let json = widgetContainer.find('[name="XAGIO_REVIEW[fields]"]').val();
105            if (json === '' || typeof (json) === 'undefined') return;
106            json = JSON.parse(atob(json));
107
108            let fields_temp = render.fields;
109            render.fields   = $.extend(true, {}, json);
110
111            for (let key in fields_temp) {
112                if (!render.fields.hasOwnProperty(key)) {
113                    render.fields[key] = fields_temp[key];
114                }
115            }
116        },
117        doRender    : function () {
118            let cnt     = widgetContainer.find('.review-widget-block-container');
119            let i       = 0;
120            let allHtml = '';
121            for (let name in render.fields) {
122
123                i++;
124                let field = render.fields[name];
125                if (field.visible == false || (widget.data.ps_stars_only == 1 && name !== 'rating')) {
126                    allHtml += '<input type="hidden" name="' + name + '" value=""/>';
127                    continue;
128                }
129                let html = '';
130                if (widget.data.ps_stars_only != 1) {
131                    html += '<label class="review-widget-label" for="i' + i + '">' + field.label + '</label>';
132                }
133
134                let attr_required = '';
135                if (field.hasOwnProperty('required')) {
136                    if (field.required) {
137                        attr_required = 'required';
138                    }
139                }
140
141                switch (field.type) {
142                    case "text":
143                        if (field.label === "Name:") {
144                            attr_required = 'required';
145                        }
146                        html += '<input name="' + name + '" type="text" class="review-widget-input" ' + attr_required + ' id="i' + i + '" placeholder="' + field.placeholder + '" data-placeholder="' + field.placeholder + '" data-alt-placeholder="' + field.altplaceholder + '" />';
147                        break;
148                    case "textarea":
149                        html += '<textarea name="' + name + '" rows="5" class="review-widget-input" required id="i' + i + '" placeholder="' + field.placeholder + '" data-placeholder="' + field.placeholder + '" data-alt-placeholder="' + field.altplaceholder + '" ></textarea>';
150                        break;
151                    case "stars":
152                        html += '<input type="hidden" value="5" name="' + name + '" id="ps-rating"/>';
153                        html += '<div class="review-widget-stars">';
154                        html += '<i data-value="1" class="xagio-icon xagio-icon-star-o"></i>';
155                        html += '<i data-value="2" class="xagio-icon xagio-icon-star-o"></i>';
156                        html += '<i data-value="3" class="xagio-icon xagio-icon-star-o"></i>';
157                        html += '<i data-value="4" class="xagio-icon xagio-icon-star-o"></i>';
158                        html += '<i data-value="5" class="xagio-icon xagio-icon-star-o"></i>';
159                        html += '</div>';
160                        break;
161                    case "email":
162                        html += '<input name="' + name + '" type="email" class="review-widget-input" ' + attr_required + ' id="i' + i + '" placeholder="' + field.placeholder + '" data-placeholder="' + field.placeholder + '" data-alt-placeholder="' + field.altplaceholder + '" />';
163                        break;
164                    case "url":
165                        html += '<input name="' + name + '" type="url" class="review-widget-input" ' + attr_required + ' id="i' + i + '" placeholder="' + field.placeholder + '" data-placeholder="' + field.placeholder + '" data-alt-placeholder="' + field.altplaceholder + '" />';
166                        break;
167                    case "number":
168                        html += '<input name="' + name + '" type="number" min="18" max="99" class="review-widget-input" ' + attr_required + ' id="i' + i + '" placeholder="' + field.placeholder + '" data-placeholder="' + field.placeholder + '" data-alt-placeholder="' + field.altplaceholder + '" />';
169                        break;
170                }
171                html += '<div class="cx"></div>';
172                html = '<div class="review-widget-block">' + html + '</div>';
173                allHtml += html;
174            }
175            cnt.append(allHtml);
176        },
177        popup       : function () {
178            widgetContainer.find('#review-widget-popup-button').click(function (e) {
179                e.preventDefault();
180                widgetContainer.find('.review-widget-popup-container').fadeIn();
181                widgetContainer.find('.review-widget').fadeIn();
182            });
183            widgetContainer.find('.review-widget-popup-container').click(function () {
184                $(this).fadeOut();
185                widgetContainer.find('.review-widget').fadeOut();
186            });
187        },
188        submitReview: function () {
189
190            if (widget.data.ps_stars_only != 1) {
191
192                widgetContainer.find('.ps-submit-review').submit(function (e) {
193                    e.preventDefault();
194
195                    let btn   = $(this).find('.review-widget-button');
196                    let title = widgetContainer.find('.review-widget-title');
197                    let text  = widgetContainer.find('.review-widget-text');
198
199                    btn.attr('disabled', 'disabled');
200                    btn.html('<i class="xagio-icon xagio-icon-sync xagio-icon-spin"></i> Processing');
201
202                    $.post(widget.data.ps_admin_url, $(this).serialize(), function (d) {
203                        if (d.status == 'success') {
204                            title.html('<i class="xagio-icon xagio-icon-check"></i> Review Submitted!');
205                            text.html(widget.data.ps_thank_you);
206                        } else {
207                            title.html('<i class="xagio-icon xagio-icon-close"></i> Oops!');
208                            text.html(d.message);
209                        }
210
211                        title.prevAll().hide();
212                        text.nextAll().hide();
213
214                        widgetContainer.find('.review-widget').addClass('review-widget-message');
215
216                        if ($('.review-widget-popup-container').is(':visible')) {
217                            setTimeout(function () {
218                                widgetContainer.find('.review-widget-popup-container').fadeOut();
219                                widgetContainer.find('.review-widget').fadeOut();
220                            }, 3000);
221                        }
222                    });
223                });
224
225            } else {
226
227                let stars = widgetContainer.find('.review-widget-stars > i');
228                stars.click(function () {
229
230                    stars.unbind();
231
232                    let data = widgetContainer.find('.ps-submit-review').seri
232alize();
233                    let text = widgetContainer.find('.review-widget-stars-ratings-info');
234
235                    $.post(widget.data.ps_admin_url, data, function (d) {
236
237                        if (d.status == 'success') {
238                            text.html(widget.data.ps_rating_thank_you);
239                        } else {
240                            text.html(d.message);
241                        }
242
243                        if (widgetContainer.find('.review-widget-popup-container').is(':visible')) {
244                            setTimeout(function () {
245                                widgetContainer.find('.review-widget-popup-container').fadeOut();
246                                widgetContainer.find('.review-widget').fadeOut();
247                            }, 3000);
248                        }
249                    });
250
251                });
252
253            }
254
255        },
256        starsHooks  : function () {
257            let starc  = widgetContainer.find('.review-widget-stars');
258            let stars  = widgetContainer.find('.review-widget-stars > i');
259            let rating = widgetContainer.find('#ps-rating');
260            stars.click(function () {
261                let star = $(this);
262                rating.val(star.data('value'));
263            });
264            stars.mouseenter(function () {
265                let star = $(this);
266                render.starFull(star);
267                star.prevAll().each(function () {
268                    render.starFull($(this));
269                });
270                star.nextAll().each(function () {
271                    render.starEmpty($(this));
272                });
273            });
274            starc.mouseleave(function () {
275                let star = widgetContainer.find('i[data-value="' + rating.val() + '"]');
276                render.starFull(star);
277                star.prevAll().each(function () {
278                    render.starFull($(this));
279                });
280                star.nextAll().each(function () {
281                    render.starEmpty($(this));
282                });
283            });
284
285            if (widget.data.ps_stars_init != '') {
286                let starIndex = 0;
287                if (widget.data.ps_stars_init >= 20 && widget.data.ps_stars_init < 40) {
288                    starIndex = 1;
289                }
290                if (widget.data.ps_stars_init >= 40 && widget.data.ps_stars_init < 60) {
291                    starIndex = 2;
292                }
293                if (widget.data.ps_stars_init >= 60 && widget.data.ps_stars_init < 80) {
294                    starIndex = 3;
295                }
296                if (widget.data.ps_stars_init >= 80 && widget.data.ps_stars_init < 100) {
297                    starIndex = 4;
298                }
299                if (widget.data.ps_stars_init == 100) {
300                    starIndex = 4;
301                }
302                stars.eq(starIndex).trigger('click');
303                stars.eq(starIndex).trigger('mouseenter');
304                stars.eq(starIndex).trigger('mouseleave');
305            }
306
307        },
308        starFull    : function (e) {
309            if (!e.hasClass('xagio-icon-star')) e.removeClass('xagio-icon-star-o').addClass('xagio-icon-star');
310        },
311        starEmpty   : function (e) {
312            if (!e.hasClass('xagio-icon-star-o')) e.removeClass('xagio-icon-star').addClass('xagio-icon-star-o');
313        }
314    };
315
316    render.init();
317    render.starsHooks();
318    render.popup();
319    render.submitReview();
320};
321
322(function ($) {
323
324    let render_display = {
325        showMoreLess: function () {
326            $(document).on('click', '.prs-show-reviews', function (e) {
327                e.preventDefault();
328                let btn = $(this);
329                if (btn.find('span').text() === 'Show more') {
330                    btn.find('i').removeClass('xagio-icon-arrow-down').addClass('xagio-icon-arrow-up');
331                    btn.find('span').text('Show less');
332                    $('.review-hidden').addClass('review-hidden-open').removeClass('review-hidden');
333                } else if (btn.find('span').text() === 'Show less') {
334                    btn.find('i').removeClass('xagio-icon-arrow-up').addClass('xagio-icon-arrow-down');
335                    btn.find('span').text('Show more');
336                    $('.review-hidden-open').addClass('review-hidden').removeClass('review-hidden-open');
337                }
338            });
339        }
340    };
341
342    let exit_popup = {
343        init     : function () {
344            $(document).mouseleave(function () {
345                if (exit_popup.getCookie('exit-popup') !== '1') {
346                    if ($('.exit-popup-window').eq(0).length != 0) {
347                        exit_popup.setCookie('exit-popup', '1');
348                        $('.exit-popup-window').eq(0).trigger('click');
349                    }
350                }
351            });
352        },
353        setCookie: function (key, value) {
354            var expires = new Date();
355            expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
356            document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/';
357        },
358        getCookie: function (key) {
359            var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
360            return keyValue ? keyValue[2] : null;
361        }
362    };
363
364    $(document).ready(function () {
365        if (typeof (ps_widgets) == 'undefined') ps_widgets = [];
366
367        // Check if there are any widgets to be initialized
368        if (ps_widgets.length > 0) {
369            for (let i = 0; i < ps_widgets.length; i++) {
370                let widget = ps_widgets[i];
371                ps_activate_widget($, widget);
372            }
373        }
374
375        // Display reviews on click
376        render_display.showMoreLess();
377
378        // Init the exit popup stuff
379        exit_popup.init();
380    });
381
382})(jQuery);
383

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.