PageSourceSearch

https://samogon-dolgop.ru/catalog/view/javascript/simplepage.js?v=4.9.7

js samogon-dolgop.ru collected 2026-09-28 22:59:13 UTC 14,053 bytes, 387 lines download raw bytes

1(function($) {
2    window.Simplepage = function(params) {
3        this.params = params;
4
5        this.selectors = {
6            agreementCheckBox: "#agreement_checkbox",
7            agreementWarning: "#agreement_warning",
8            warning: ".warning"
9        };
10
11        this.callback = params.javascriptCallback || function() {};
12
13        this.formSubmitted = false;
14
15        this.callFunc = function(func, $target) {
16            var self = this;
17
18            if (func && typeof self[func] === "function") {
19                self[func]($target);
20            } else if (func) {
21                //console.log(func + " is not registered");
22            }
23        };
24
25        this.init = function() {
26            var self = this;
27
28            var callbackForComplexField = function($target) {
29                var func = $target.attr("data-onchange");
30                if (!func) {
31                    func = $target.attr("data-onchange-delayed");
32                }
33                if (func && typeof self[func] === "function") {
34                    self[func]($target);
35                } else if (func) {
36                    //console.log(func + " is not registered");
37                }
38            };
39
40            self.requestTimerId = 0;
41
42            if (self.params.useGoogleApi) {
43                self.initGoogleApi(callbackForComplexField);
44            }
45
46            if (self.params.useAutocomplete) {
47                self.initAutocomplete(callbackForComplexField);
48            }
49
50            var $redirect = $(self.params.mainContainer).find('#simple_redirect_url');
51
52            if ($redirect.length) {
53                window.location = $redirect.val();
54            }
55
56            self.checkIsHuman();
57            self.initPopups();
58            self.initMasks();
59            self.initTooltips(!self.params.useAutocomplete);
60            self.initDatepickers(callbackForComplexField);
61            self.initTimepickers(callbackForComplexField);
62            self.initSelect2();
63            self.initFileUploader(function() {
64                self.overlay();
65            }, function() {
66                self.removeOverlay();
67            });
68            self.initHandlers();
69            self.scroll();
70            self.displayWarning();
71            self.initValidationRules();
72
73            if (typeof self.callback === "function") {
74                self.callback();
75            }
76        };
77
78        this.initHandlers = function() {
79            var self = this;
80            var $mainContainer = $(self.params.mainContainer);
81
82            $mainContainer.find("*[data-onchange], *[data-onclick]").each(function() {
83                var $element = $(this);
84
85                var funcOnChange = $element.attr("data-onchange");
86                if (funcOnChange) {
87                    $element.on("change", function() {
88                        self.callFunc(funcOnChange, $element);
89                    });
90                }
91
92                var funcOnClick = $element.attr("data-onclick");
93                if (funcOnClick) {
94                    $element.on("click", function() {
95                        self.callFunc(funcOnClick, $element);
96                    });
97                }
98            });
99
100            $mainContainer.submit(function(event) {
101                self.requestReloadAll();
102                event.preventDefault();
103                return false;
104            });
105        };
106
107        this.addSystemFieldsInForm = function() {
108            var self = this;
109            if (self.formSubmitted) {
110                $(self.params.mainContainer).append($("<input/>").attr("type", "hidden").attr("name", "submitted").val(1));
111            }
112        };
113
114        this.validateAgreements = function() {
115            var self = this;
116
117            var result = true;
118
119            var $agreementCheckbox = $(self.params.mainContainer).find(self.selectors.agreementCheckBox).find("input[type=checkbox]");
120            var $agreementCheckboxChecked = $(self.params.mainContainer).find(self.selectors.agreementCheckBox).find("input[type=checkbox]:checked");
121            var $agreementWarning = $(self.params.mainContainer).find(self.selectors.agreementWarning);
122
123            if ($agreementCheckbox.length && $agreementCheckbox.is(":visible") && $agreementCheckbox.length != $agreementCheckboxChecked.length) {
124                if ($agreementWarning.length) {
125                    if (self.params.notificationDefault) {
126                        $agreementWarning.show();
127
128                        $agreementCheckbox.each(function() {
129                            if ($(this).is(":checked")) {
130                                $(".agreement_" + $(this).val()).hide();
131                            } else {
132                                $(".agreement_" + $(this).val()).show();
133                            }                        
134                        });
135                    }
136
137                    if (self.params.notificationToasts) {
138                        $agreementCheckbox.each(function() {
139                            if (!$(this).is(":checked")) {
140                                toastr.error($(".agreement_" + $(this).val()).text());
141                            }                        
142                        });
143                    }
144
145                    result = false;
146                }
147            } else {
148                $agreementWarning.hide();
149            }
150
151            return result;
152        };
153
154        this.validate = function() {
155            var self = this;
156            var promises = [];
157            var result = true;
158
159            if (!self.validateAgreements()) {
160                result = false;
161            }
162
163            var promise = self.checkRules().then(function(r) {
164                if (!r) {
165                    result = false
166                }
167            });
168
169            var deferred = $.Deferred();
170
171            $.when(promise).then(function() {
172                deferred.resolve(result);
173            });
174
175            return deferred.promise();
176        };
177
178        this.submit = function() {
179            var self = this;
180
181            self.validate().then(function(result) {
182                if (result) {
183                    self.formSubmitted = true;
184                    $(self.params.mainContainer).submit();
185                } else {
186                    self.scroll();
187
188                    if (typeof toastr !== 'undefined' && self.params.notificationCheckForm) {
189                        toastr.error(self.params.notificationCheckFormText);
190                    }
191                }
192            });
193        };
194
195        this.openLoginBox = function() {
196            window.location = this.params.loginLink;
197        };
198
199        /**
200         * Adds delay for reload execution on 150 ms, it allows to check 
200sequence of events and to execute only the last request to handle of more events in one reloading
201         * @param  {Function} callback
202         */
203        this.requestReloadAll = function(callback) {
204            var self = this;
205            if (self.requestTimerId) {
206                clearTimeout(self.requestTimerId);
207                self.requestTimerId = 0;
208            }
209            self.requestTimerId = window.setTimeout(function() {
210                self.reloadAll(callback);
211            }, 150);
212        };
213
214        this.overlay = function() {
215            var self = this;
216            var $block = $(self.params.mainContainer);
217            if ($block.length) {
218                $block.find("input,select,textarea").attr("disabled", "disabled");
219                $block.append(
220                    $("<div>")
221                        .addClass("simplepage_overlay")
222                        .attr("id", $block.attr("id") + "_overlay")
223                        .css({
224                            "background": "url(" + self.params.additionalPath + self.resources.loading + ") no-repeat center center",
225                            "opacity": 0.4,
226                            "position": "absolute",
227                            "width": $block.width(),
228                            "height": $block.height(),
229                            "z-index": 5000
230                        })
231                );
232
233                var $overlay = $("#"+$block.attr("id") + "_overlay");
234
235                $overlay.offset({
236                    top: $block.offset().top,
237                    left: $block.offset().left
238                });
239            }
240        };
241
242        this.removeOverlay = function() {
243            var self = this;
244            var $mainContainer = $(self.params.mainContainer);
245
246            $mainContainer.find("input,select,textarea").removeAttr("disabled");
247            $mainContainer.find(".simplepage_overlay").remove();
248        };
249
250        this.displayWarning = function() {
251            var self = this;
252            var $mainContainer = $(self.params.mainContainer);
253
254            var selectors = [self.selectors.warning, self.selectors.agreementWarning]
255                .map(function(item) {
256                    return item + ":visible";
257                })
258                .join(",");
259
260            if ($mainContainer.find(selectors).length) {
261                if (typeof toastr !== 'undefined') {
262                    if (self.params.notificationToasts) {
263                        toastr.error($mainContainer.find(selectors).text());
264                    }
265
266                    if (self.params.notificationCheckForm) {
267                        toastr.error(self.params.notificationCheckFormText);
268                    }                    
269                }
270
271                if (!self.params.notificationDefault) {
272                    $mainContainer.find(selectors).hide();
273                }
274            }
275        },
276
277        this.scroll = function() {
278            var self = this,
279                error = false,
280                top = 10000,
281                bottom = 0;
282
283            var $mainContainer = $(self.params.mainContainer);
284
285            var isOutsideOfVisibleArea = function(y) {
286                if (y < $(document).scrollTop() || y > ($(document).scrollTop() + $(document).height())) {
287                    return true;
288                }
289                return false;
290            };
291
292            if (self.params.popup) {
293                return;
294            }
295
296            if (self.params.scrollToError) {
297                $($mainContainer.find(".simplecheckout-rule:visible, .has-error")).each(function() {
298                    if ($(this).parents(".simpleregister-block-content").length) {
299                        var offset = $(this).parents(".simpleregister-block-content").offset();
300                        if (offset.top < top) {
301                            top = offset.top;
302                        }
303                        if (offset.bottom > bottom) {
304                            bottom = offset.bottom;
305                        }
306                    }
307                });
308
309                if ($mainContainer.find(".warning").length) {
310                    var offset = $mainContainer.find(".warning").offset();
311                    if (offset.top < top) {
312                        top = offset.top;
313                    }
314                    if (offset.bottom > bottom) {
315                        bottom = offset.bottom;
316                    }
317                }
318
319                if (top < 10000 && isOutsideOfVisibleArea(top)) {
320                    jQuery("html, body").animate({
321                        scrollTop: top
322                    }, "slow");
323                    error = true;
324                } else if (bottom && isOutsideOfVisibleArea(bottom)) {
325                    jQuery("html, body").animate({
326                        scrollTop: bottom
327                    }, "slow");
328                    error = true;
329                }
330            }
331        };
332
333        this.reloadAll = function(callback) {
334            var self = this;
335            var postData;
336            if (self.isReloading) {
337                return;
338            }
339            self.addSystemFieldsInForm();
340            self.isReloading = true;
341            postData = $(self.params.mainContainer).find("input,select,textarea").serialize();
342
343            var overlayTimeoutId = 0;
344
345            $.ajax({
346                url: self.params.mainUrl,
347                data: postData + "&simple_ajax=1",
348                type: "POST",
349                dataType: "text",
350                beforeSend: function() {
351                    $('.tooltip ').remove();
352                    
353                    overlayTimeoutId = window.setTimeout(function() {
354                        if (overlayTimeoutId) {
355                            self.overlay();
356                        }
357                    }, 250);
358                },
359                success: function(data) {
360                    clearTimeout(overlayTimeoutId);
361                    overlayTimeoutId = 0;
362                    var newData = $(self.params.mainContainer, $(data)).get(0);
363                    if (!newData && data) {
364                        newData = data;
365                    }
366                    $(self.params.mainContainer).replaceWith(newData);
367                    self.init();
368                    if (typeof callback === "function") {
369                        callback.call(self);
370                    }
371                    self.removeOverlay();
372                    self.isReloading = false;
373                },
374                error: function(xhr, ajaxOptions, thrownError) {
375                    clearTimeout(overlayTimeoutId);
376                    overlayTimeoutId = 0;
377                    self.removeOverlay();
378                    self.isReloading = false;
379                }
380            });
381        };
382
383        this.instances.push(this);
384    };
385
386    Simplepage.prototype = inherit(window.Simple.prototype);
387})(jQuery);

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.