PageSourceSearch

https://aihost.com/core/modules/a69a6a67c3/assets/js/review-widget.js?rnd=74365

js aihost.com collected 2026-10-07 16:20:33 UTC 16,501 bytes, 382 lines download raw bytes

1// Store the widgets
2let ps_widgets = [];
3
4// Activate Widget
5let ps_activate_widget = function ($, widget) {
6    'use strict';
7    let widgetContainer = $('.' + widget.name);
8    let render          = {
9        fields      : {
10            name     : {
11                type          : "text",
12                label         : "Name:",
13                placeholder   : "eg. John",
14                altplaceholder: "Your Name",
15                visible       : true
16            },
17            review   : {
18                type          : "textarea",
19                label         : "Review:",
20                placeholder   : "eg. This is really a cool website!",
21                altplaceholder: "Your Review",
22                visible       : true
23            },
24            rating   : {
25                type          : "stars",
26                label         : "Rating:",
27                placeholder   : "",
28                altplaceholder: "",
29                visible       : true
30            },
31            email    : {
32                type          : "email",
33                label         : "E-Mail Address:",
34                placeholder   : "eg. [email protected]",
35                altplaceholder: "E-Mail Address",
36                visible       : false
37            },
38            website  : {
39                type          : "url",
40                label         : "Website:",
41                placeholder   : "eg. http://www.website.com",
42                altplaceholder: "Your Website",
43                visible       : false
44            },
45            title    : {
46                type          : "text",
47                label         : "Title:",
48                placeholder   : "eg. I like this product",
49                altplaceholder: "Your Title",
50                visible       : false
51            },
52            telephone: {
53                type          : "text",
54                label         : "Telephone:",
55                placeholder   : "eg. 1-800-500-6000",
56                altplaceholder: "Your Phone Number",
57                visible       : false
58            },
59            location : {
60                type          : "text",
61                label         : "Location:",
62                placeholder   : "eg. Los Angeles",
63                altplaceholder: "Your Location",
64                visible       : false
65            },
66            age      : {
67                type          : "number",
68                label         : "Age:",
69                placeholder   : "eg. 35",
70                altplaceholder: "Your Age",
71                visible       : false
72            },
73            captcha  : {
74                type          : "captcha",
75                label         : "reCaptcha:",
76                altplaceholder: "",
77                placeholder   : "",
78                visible       : false
79            }
80        },
81        init        : function () {
82            render.firstStart();
83            render.doRender();
84        },
85        firstStart  : function () {
86            let json = widgetContainer.find('[name="ps_review[fields]"]').val();
87            if (json === '' || typeof (json) === 'undefined') return;
88            json = JSON.parse(atob(json));
89
90            let fields_temp = render.fields;
91            render.fields   = $.extend(true, {}, json);
92
93            for (let key in fields_temp) {
94                if (!render.fields.hasOwnProperty(key)) {
95                    render.fields[key] = fields_temp[key];
96                }
97            }
98        },
99        doRender    : function () {
100            let cnt     = widgetContainer.find('.review-widget-block-container');
101            let i       = 0;
102            let allHtml = '';
103            let captcha = false;
104            for (let name in render.fields) {
105
106                i++;
107                let field = render.fields[name];
108                if (field.visible == false || (widget.data.ps_stars_only == 1 && name !== 'rating')) {
109                    allHtml += '<input type="hidden" name="' + name + '" value=""/>';
110                    continue;
111                }
112                let html = '';
113                if (widget.data.ps_stars_only != 1) {
114                    html += '<label class="review-widget-label" for="i' + i + '">' + field.label + '</label>';
115                }
116
117                let attr_required = '';
118                if (field.hasOwnProperty('required')) {
119                    if (field.required) {
120                        attr_required = 'required';
121                    }
122                }
123
124                switch (field.type) {
125                    case "text":
126                        if (field.label === "Name:") {
127                            attr_required = 'required';
128                        }
129                        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 + '" />';
130                        break;
131                    case "textarea":
132                        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>';
133                        break;
134                    case "stars":
135                        html += '<input type="hidden" value="5" name="' + name + '" id="ps-rating"/>';
136                        html += '<div class="review-widget-stars">';
137                        html += '<i data-value="1" class="fa-light fa-star"></i>';
138                        html += '<i data-value="2" class="fa-light fa-star"></i>';
139                        html += '<i data-value="3" class="fa-light fa-star"></i>';
140                        html += '<i data-value="4" class="fa-light fa-star"></i>';
141                        html += '<i data-value="5" class="fa-light fa-star"></i>';
142                        html += '</div>';
143                        break;
144                    case "email":
145                        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 + '" />';
146                        break;
147                    case "url":
148                        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 + '" />';
149                        break;
150                    case "number":
151                        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 + '" />';
152                        break;
153                    case "captcha":
154                        captcha = true;
155                        html += '<div style="transform:scale(0.77);-webkit-transform:scale(0.77);transform-origin:0 0;-webkit-transform-origin:0 0;" id="captcha-element-' + widget.name + '"><p>Your are missing Captcha Site Key from your configuration! Captcha will not appear until you have a Site Key.</p></div>';
156                        break;
157                }
158                html += '<div class="cx"></div>';
159                html = '<div class="review-widget-block">' + html + '</div>';
160                allHtml += html;
161            }
162            cnt.append(allHtml);
163            if (captcha == true) {
164                let captchaContainer = 'captcha-element-' + widget.name;
165                if (widget.data.ps_captcha_k != '') {
166                    widgetContainer.find('#' + captchaContainer).empty();
167                    if ($('#g-recaptcha-response').length < 1) {
168                        setTimeout(function () {
169                            grecaptcha.render(captchaContainer, {
170                                'sitekey': widget.data.ps_captcha_k
171                            });
172                        }, 2500);
173                    }
174                }
175            }
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="fa-light fa-sync fa-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="fa-light fa-check"></i> Review Submitted!');
205                            text.html(widget.data.ps_thank_you);
206                        } else {
207                            title.html('<i class="fa-light fa-times"></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('fa-star')) e.removeClass('fa-star-o').addClass('fa-star');
310        },
311        starEmpty   : function (e) {
312            if (!e.hasClass('fa-star-o')) e.removeClass('fa-star').addClass('fa-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('fa-caret-down').addClass('fa-caret-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('fa-caret-up').addClass('fa-caret-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
366        // Check if there are any widgets to be initialized
367        if (ps_widgets.length > 0) {
368            for (let i = 0; i < ps_widgets.length; i++) {
369                let widget = ps_widgets[i];
370                ps_activate_widget($, widget);
371            }
372        }
373
374        // Display reviews on click
375        render_display.showMoreLess();
376
377        // Init the exit popup stuff
378        exit_popup.init();
379    });
380
381})(jQuery);
382

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.