PageSourceSearch

https://mikmag.ru/wa-apps/shop/plugins/quickorder/js/dialog/jquery.dialog.js?2.11.2.1791159433

js mikmag.ru collected 2026-10-05 00:17:25 UTC 20,771 bytes, 500 lines download raw bytes

1/**
2 * Всплывающее окно v.1.0
3 *
4 * Входящие параметры:
5 * - 'locale' Локаль
6 * - 'messages' Локализованные строки. Объект. Смотри структуру that.messages
7 * - 'html' Всё содержимое всплывающего окна. Если указано, то параметры ниже игнорируются
8 * -= 'content' Контент внутри всплывающего окна
9 * -= 'title' Заголовок всплывающего окна
10 * -= 'buttons' Кнопки всплывающего окна
11 * -= 'loadingContent' Вместо содержимого появляется иконка загрузки.
12 * -= 'closeBtn' Кнопка закрытия всплывающего окна (true | html)
13 * - 'block' Блок с содержимым. Если не указан, то в качестве блока будет w-dialog-wrapper
14 * - 'url' Ссылка, которая при обращении отдаст содержимое всплывающего окна
15 * - 'class' Произвольный класс всплывающего окна
16 * - 'closeOnlyByLink' Закрывать всплывающее окно только при клике на ссылку
17 * - 'position' Расположение блока. Параметры { left: , top: }
18 * - 'setPosition' Пользовательская функция для определения расположения окна. Принимает параметры { width: , height: }
19 * - 'saveUrl' Ссылка, куда будут отправлены данные формы окна при нажатии "Сохранить"
20 * - 'onBgClick' Событие клика в любую область вне окна. Параметры (event, dialog)
21 * - 'onBlockClick' Событие клика в область окна. Параметры (event, dialog)
22 * - 'onOpen' Событие открытия окна. Параметры ($wrapper, dialog)
23 * - 'onClose' Событие закрытия окна. Параметры ($wrapper, dialog)
24 * - 'onRefresh' Событие перезагрузки формы. Принимает параметры настроек формы
25 * - 'onResize' Событие изменения размеров окна
26 * - 'onSubmit' Событие отправки данных формы. Параметры (form, dialog)
27 * - 'onSuccess' Событие успешной отправки данных
28 * - 'onSuccessCallback' Функция, выполняемая после успешной отправки данных
29 */
30if (typeof igaponovDialog === 'undefined') {
31
32    var igaponovDialog = (function ($) {
33
34        igaponovDialog = function (options) {
35            var that = this;
36
37            that.locale = options.locale || 'ru_RU';
38            that.messages = {
39                'ru_RU': {
40                    "Save": "Сохранить",
41                    "or": "или",
42                    "cancel": "отмена",
43                    "Something wrong": "Произошла ошибка",
44                    "Fill in required fields": "Заполните обязательные поля",
45                    "Your title": "Ваш заголовок"
46                }
47            };
48
49            if (options.messages !== undefined && typeof options.messages == 'object') {
50                $.extend(that.messages, options.messages);
51            }
52            // DOM
53            that.$wrapper = (options["html"] ? $(options["html"]) : '');
54            that.url = (options["url"] || '');
55            if ((that.url && !that.$wrapper) || options.loadingContent) {
56                that.$wrapper = $('<div class="ig-dialog-wrap is-full-screen"><div class="w-dialog-background"></div><div class="w-dialog-wrapper"><div class="w-dialog-block gray-header compact-header"><i class="big-loader"></i></div></div></div>');
57            }
58            if (!that.url && options.content && !that.$wrapper) {
59                options.title = options.title || that.translate('Your title');
60                that.$wrapper = $('<div class="ig-dialog-wrap is-full-screen">' +
61                    '<div class="w-dialog-background"></div>' +
62                    '<div class="w-dialog-wrapper">' +
63                    '<div class="w-dialog-block gray-header compact-header">' +
64                    '<form action="" method="post">' +
65                    '<header class="w-dialog-header">' +
66                    '<h1>' + options.title + '</h1>' + '</header>' +
67                    '<div class="w-dialog-content margin-block">' + options.content + '</div>' +
68                    '<footer class="w-dialog-footer">' +
69                    '<div class="margin-block errormsg"></div>' +
70                    '<div class="t-actions">' +
71                    '<div class="t-layout">' +
72                    '<div class="t-column left">' +
73                    (options.buttons ? options.buttons : '<input type="submit" class="button green t-button" value="' + that.translate('Save') + '"> ' + that.translate('or') + ' <a href="javascript:void(0)" class="js-close-dialog">' + that.translate('cancel') + '</a>') +
74                    '</div>' +
75                    '</div>' +
76                    '</div>' +
77                    '</footer>' +
78                    '</form></div></div></div>');
79            }
80            that.options = options;
81            that.closeBtnTemplate = $('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 9.9 9.9"><path d="M0,8.5l3.5-3.5L0,1.4L1.4,0l3.5,3.5L8.5,0l1.4,1.4L6.4,4.9l3.5,3.5L8.5,9.9L4.9,6.4L1.4,9.9L0,8.5z"></path></svg>');
82            that.initVars();
83
84            // VARS
85            that.position = (options["position"] || false);
86            that.dialogClass = 't-' + Date.now();
87            that.saveUrl = (options["saveUrl"] || '');
88
89            // DYNAMIC VARS
90            that.is_closed = false;
91            that.is_locked = false;
92            that.xhr = false;
93
94            that.userPosition = (options["setPosition"] || false);
95
96            // HELPERS
97            that.onBgClick = (options["onBgClick"] || false);
98            that.onBlockClick = (options["onBlockClick"] || false);
99            that.onOpen = (options["onOpen"] || function () {
100            });
101            that.onClose = (options["onClose"] || function () {
102            });
103            that.onRefresh = (options["onRefresh"] || false);
104            that.onResize = (options["onResize"] || false);
105            that.onSubmit = (options["onSubmit"] || null);
106            that.onSuccess = (options["onSuccess"] || null);
107            that.onSuccessCallback = (options["onSuccessCallback"] || null);
108
109            // INIT
110            that.initClass();
111        };
112
113        igaponovDialog.prototype.initClass = function () {
114            var that = this;
115
116            that.$wrapper.data('igaponovDialog', that).addClass(that.dialogClass).find('.w-dialog-background').addClass(that.dialogClass);
117
118            that.show();
119            if (that.url) {
120                that.loadDataFromUrl();
121            } else {
122                that.addCloseBtn();
123                that.bindEvents();
124            }
125        };
126
127        igaponovDialog.prototype.loadDataFromUrl = function () {
128            var that = this,
129                href = that.url;
130            that.is_locked = true;
131
132            if (that.xhr) {
133                that.xhr.abort();
134                that.xhr = false;
135            }
136
137            that.xhr = $.ajax({
138                url: href,
139                dataType: "html",
140                type: "get",
141                success: function (html) {
142                    var params = {
143                        html: html,
144                        onBgClick: function (e, d) {
145                            if (typeof that.options.closeOnlyByLink === 'undefined') {
146                                d.close();
147                            }
148                        },
149                        url: ''
150                    };
151                    that.close();
152                    new igaponovDialog($.extend(that.options, params));
153
154                    that.is_locked = false;
155                },
156                error: function (jqXHR, textStatus, errorThrown) {
157                    that.is_locked = false;
158                    that.close();
159                    if (console) {
160                        console.log(jqXHR, textStatus, errorThrown);
161                    }
162                }
163            });
164        };
165
166        igaponovDialog.prototype.bindEvents = function () {
167            var that = this,
168                $document = $(document),
169                $block = (that.$block) ? that.$block : that.$wrapper;
170
171            that.$form.on("submit", function (event) {
172                event.preventDefault();
173                if (!that.is_locked) {
174                    if (typeof that.onSubmit == 'function') {
175                        that.onSubmit(that.$form, that);
176                    } else {
177                        that.save();
178                    }
179                }
180                return false;
181            });
182
183            $document.on('focus', 'input.error, textarea.error', function () {
184                $(this).removeClass("error");
185            });
186
187            // Delay binding close events so that dialog does not close immidiately
188            // from the same click that opened it.
189            setTimeout(function () {
190
191                // $document.on("click", close);
192                $document.on("wa_before_load", close);
193                that.$wrapper.on("close", close);
194
195                // Click on background, default nothing
196                if (that.is_full_screen) {
197                    that.$wrapper.off('click').on("click", function (event) {
198                        if (!that.onBgClick) {
199                            event.stopPropagation();
200                        } else {
201                            that.onBgClick(event, that);
202                        }
203                    });
204                }
205
206                $block.off('click').on("click", function (event) {
207                    if (!that.onBlockClick) {
208                        event.stopPropagation();
209                    } else {
210                        that.onBlockClick(event, that);
211                    }
212                });
213
214                $(document).on("keyup", function (event) {
215                    var escape_code = 27;
216                    if (event.keyCode === escape_code) {
217                        that.close();
218                    }
219                });
220
221                $block.off("click", ".js-close-dialog").on("click", ".js-close-dialog", function () {
222                    close();
223                });
224
225                function close() {
226                    if (!that.is_closed) {
227                        that.close();
228                    }
229                    // $document.off("click", close);
230                    $document.off("wa_before_load", close);
231                }
232
233                if (that.is_full_screen) {
234                    $(window).on("resize", onResize);
235                }
236
237                function onResize() {
238                    var is_exist = $.contains(document, that.$wrapper[0]);
239                    if (is_exist) {
240                        that.resize();
241                    } else {
242                        $(window).off("resize", onResize);
243                    }
244                }
245
246            }, 0);
247
248        };
249
250        igaponovDialog.prototype.addCloseBtn = function () {
251            var that = this;
252
253            if (that.$closeBtn.length && !that.$wrapper.find('.ig-dialog-close-btn').length) {
254                var closeButton = that.$closeBtn;
255                if (typeof that.$closeBtn == 'object') {
256                    closeButton = that.$closeBtn.prop('outerHTML');
257                }
258                closeButton = '<div class="ig-dialog-close-btn js-close-dialog">' + closeButton + '</div>';
259                that.$block.append(closeButton);
260            }
261        };
262
263        igaponovDialog.prototype.initVars = function () {
264            var that = this;
265
266            that.$block = (that.options["block"] ? $(that.options["block"]) : false);
267            that.$form = that.$wrapper.find("form");
268            that.$submitBtn = that.$form.find("input[type='submit']");
269            that.is_full_screen = (that.$wrapper.hasClass("is-full-screen"));
270            if (that.is_full_screen) {
271                that.$block = that.$wrapper.find(".w-dialog-block");
272            }
273            if (that.options.class) {
274                that.$block.addClass(that.options.class);
275            }
276            if (that.$block === false) {
277                that.$block = that.$wrapper;
278            }
279            that.$closeBtn = that.options.closeBtn ? (that.options.closeBtn === true ? that.closeBtnTemplate : $(that.options.closeBtn)) : '';
280        };
281
282        igaponovDialog.prototype.show = function () {
283            var that = this;
284
285            $("body").addClass('igaponov-dialog').append(that.$wrapper);
286            // that.setPosition();
287            if (!that.url) {
288                that.onOpen(that.$wrapper, that);
289            }
290        };
291
292        igaponovDialog.prototype.setPosition = function () {
293            var that = this,
294                $window = $(window),
295                window_w = $window.width(),
296                window_h = (that.is_full_screen) ? $window.height() : $(document).height(),
297                $block = (that.$block) ? that.$block : that.$wrapper,
298                wrapper_w = $block.outerWidth(),
299                wrapper_h = $block.outerHeight(),
300                pad = 10,
301                css;
302            if (that.position) {
303                css = that.position;
304
305            } else {
306                var getPosition = (that.userPosition) ? that.userPosition : getDefaultPosition;
307                css = getPosition({
308                    width: wrapper_w,
309                    height: wrapper_h
310                });
311            }
312
313            if (css.left > 0) {
314                if (css.left + wrapper_w > window_w) {
315                    css.left = window_w - wrapper_w - pad;
316                }
317            }
318
319            if (css.top > 0) {
320                if (css.top + wrapper_h > window_h) {
321                    css.top = window_h - wrapper_h - pad;
322                }
323            } else {
324                css.top = pad;
325
326                if (that.is_full_screen) {
327                    var $content = $block.find(".w-dialog-content");
328
329                    $content.hide();
330
331                    var block_h = $block.outerHeight(),
332                        content_h = window_h - block_h - pad * 2;
333
334                    $content
335                        .height(content_h)
336                        .addClass("is-long-content")
337                        .show();
338                }
339            }
340
341            $block.css(css);
342
343            function getDefaultPosition(area) {
344                return {
345                    left: parseInt((window_w - area.width) / 2),
346                    top: parseInt((window_h - area.height) / 2)
347                };
348            }
349        };
350
351        igaponovDialog.prototype.close = function () {
352            var that = this;
353            that.is_closed = true;
354            if (!that.url) {
355                that.onClose(that.$wrapper, that);
356            }
357            that.$wrapper.remove();
358            $("body").removeClass('igaponov-dialog');
359        };
360
361        igaponovDialog.prototype.refresh = function (options) {
362            var that = this;
363            var params = $.extend(that.options, options);
364
365            if (that.onRefresh) {
366                that.onRefresh(params);
367            } else {
368                new igaponovDialog(params);
369            }
370            that.close();
371        };
372
373        igaponovDialog.prototype.resize = function () {
374            var that = this,
375                animate_class = "is-animated",
376                do_animate = true;
377
378            if (do_animate) {
379                that.$block.addClass(animate_class);
380            }
381
382            // that.setPosition();
383
384            if (that.onResize) {
385                that.onResize(that.$wrapper, that);
386            }
387        };
388
389        igaponovDialog.prototype.translate = function (message) {
390            var that = this;
391
392            if (typeof that.messages[that.locale] !== 'undefined' && that.messages[that.locale][message]) {
393                return that.messages[that.locale][message];
394            }
395            return message;
396        };
397
398        igaponovDialog.prototype.save = function (data, callback) {
399            var that = this,
400                successTimeout = null;
401            if (!that.is_locked) {
402                addLoading();
403
404                that.is_locked = true;
405
406                errorText();
407                successTimeout && clearTimeout(successTimeout);
408                that.$form.find('.w-dynamic-content').html('');
409
410                /* Проверка обязательных полей */
411                if (!checkRequired()) {
412                    that.is_locked = false;
413                    removeLoading();
414                    return false;
415                }
416
417                data = data || that.$form.serializeArray();
418
419                $.ajax({
420                    url: that.saveUrl,
421                    dataType: "json",
422                    type: "post",
423                    data: data,
424                    success: function (response) {
425                        that.is_locked = false;
426                        removeLoading();
427
428                        if (typeof response !== 'undefined' && response.status == 'fail' && response.errors) {
429                            errorText(response.errors);
430                        } else {
431                            if (typeof that.onSuccess == 'function') {
432                                that.onSuccess(that, response);
433                            } else {
434                                successMessage();
435                            }
436                            try {
437                                if (typeof that.onSuccessCallback == 'function') {
438                                    that.onSuccessCallback(response);
439                                }
440                                if (typeof callback === 'function') {
441                                    callback.call(this, that);
442                                }
443                            } catch (e) {
444                                console.log('Callback error: ' + e.message, e);
445                            }
446                        }
447                        that.resize();
448                    },
449                    error: function (jqXHR, textStatus, errorThrown) {
450                        that.is_locked = false;
451                        removeLoading();
452                        if (console) {
453                            console.log(jqXHR, textStatus, errorThrown);
454                        }
455                        errorText(that.translate('Something wrong'));
456                    }
457                });
458            }
459
460            function addLoading() {
461                that.$submitBtn.after("<i class='icon16 loading'></i>");
462            }
463
464            function removeLoading() {
465                that.$submitBtn.next("i").remove();
466            }
467
468            function successMessage() {
469                that.$submitBtn.after("<i class='icon16 yes'></i>");
470                successTimeout = setTimeout(function () {
471                    removeLoading();
472                }, 3000);
473            }
474
475            function errorText(text) {
476                text = text || '';
477                that.$form.find('.errormsg').html(text);
478            }
479
480            function checkRequired() {
481                var error = 0;
482                that.$form.find(".s-required").each(function () {
483                    var elem = $(this);
484                    if ($.trim(elem.val()) == '') {
485                        elem.addClass('error');
486                        error = 1;
487                    }
488                });
489                if (error) {
490                    errorText(that.translate('Fill in required fields'));
491                    return false;
492                }
493                return true;
494            }
495        };
496
497        return igaponovDialog;
498
499    })(jQuery);
500}

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.