PageSourceSearch

http://ckii.ru/Scripts/advModal.js

js ckii.ru collected 2026-10-08 04:44:22 UTC 17,625 bytes, 488 lines download raw bytes

1(function (jQuery) {
2
3    var modalsTempStorage = [];
4
5    jQuery.extend({
6        advModal: function(o) {
7            var options = jQuery.extend({
8                modalClass: null,
9                modalId: null,
10                title: null,
11                htmlContent: null,
12                buttons: null,
13                isEnableBackground: true,
14                opacityBackground: 0.4,
15                opacityModal: 1,
16                control: null,
17                controlEvent: "click",
18                clickOut: true,
19                forceShow: false,
20                cross: true,
21                closeEsc: true,
22                enableTouch: true,
23                positionShow: true,
24                controlBeforeOpen: null,
25                controlAfterOpen: null,
26                funcCross: null,
27                beforeOpen: null,
28                afterOpen: null,
29                beforeClose: null,
30                afterClose: null,
31                hideError: true,
32                initCallback: null
33            }, o);
34
35            var modal = $("<div>").addClass("modal"), modalBackground = $("<div>").addClass("modal-background");
36
37            if (options.isEnableBackground && !$("div.modal-background").length)
38                $("body, #aspnetForm").append(modalBackground);
39
40            if (options.cross)
41                modal.append("<div class='modal-close cross'></div>");
42
43            if (options.title)
44                modal.append("<div class='title'></div>");
45
46            if (options.htmlContent)
47                modal.append("<div class='content'></div>");
48
49            if (options.buttons)
50                modal.append("<div class='btns'></div>");
51
52            $("body, #aspnetForm").append(modal);
53
54            if (options.modalClass) modal.addClass(options.modalClass);
55            if (options.modalId) modal.attr("id", options.modalId);
56
57            if (options.isEnableBackground && !modalBackground.length)
58                modalBackground = $("div.modal-background");
59
60            if (options.isEnableBackground) {
61                modalBackground = modal.prev("div.modal-background");
62                modalBackground.css({ opacity: options.opacityBackground });
63            }
64
65            var title = modal.children("div.title"),
66                content = modal.children("div.content"),
67                btnsContainer = modal.children("div.btns");
68
69            //title
70            if (title.length)
71                title.append(options.title);
72            //content
73            if (content.length)
74                content.append(options.htmlContent);
75
76            //generate btn
77            if (btnsContainer.length) {
78                var htmlBtns = "";
79                $.each(options.buttons, function(idx, el) {
80                    htmlBtns += "<a href='javascript:void(0)' class='btn btn-middle btn-modal ";
81                    if (el.classBtn)
82                        htmlBtns += el.classBtn + "'>";
83                    else
84                        htmlBtns += "'>";
85                    if (el.textBtn)
86                        htmlBtns += el.textBtn + "</a>";
87                });
88                btnsContainer.html(htmlBtns);
89            }
90
91            //bindEvent
92            if (btnsContainer.length) {
93                var btns = btnsContainer.children("a.btn");
94                btns.each(function(idx, el) {
95                    if (options.buttons[idx].func != null)
96                        $(el).on('click', { modal: modal }, options.buttons[idx].func);
97                    if (options.buttons[idx].isBtnClose == true)
98                        $(el).click(function() {
99                            modalClose.apply(modal);
100                            return false;
101                        });
102                });
103            }
104            if (options.control) {
105                var elem = $(options.control);
106                var resultControlBeforeOpen = true;
107
108
109                if (typeof(options.control) === 'string') {
110                    $(document.body).on(options.controlEvent, options.control, function(event) {
111                        modalControlEvent(event, modal);
112                    })
113                } else {
114                    elem.on(options.controlEvent, function(event) {
115                        modalControlEvent(event, modal);
116                    });
117                }
118            }
119
120            if (options.clickOut) {
121                $("body").on('click.modalClickOut', function(e) {
122                    var isModalOnClick = $(e.target).closest(modal).length;
123
124                    if (!isModalOnClick && modal.is(":visible")) {
125                        modalClose.apply(modal);
126                    }
127
128                });
129            }
130            if (options.closeEsc) {
131                $(document).keyup(function(e) {
132                    if (modal.is(":visible") && e.keyCode == 27) {
133                        modalClose.apply(modal);
134                    }
135                });
136            }
137
138
139            modal.find("div.modal-close").click(function() {
140                modalClose.apply(modal);
141                if (options.funcCross)
142                    (options.funcCross).apply(modal);
143                return false;
144            });
145            $(window).resize(
146                function() {
147                    if (modal.is(":visible")) modalPosition.apply(modal);
148                }
149            );
150
151            //position modal	
152            modalPosition.apply(modal);
153
154            if (window.jQuery.IsTouchDevice && jQuery.IsTouchDevice()) {
155                var modalOffset, docHeight;
156
157                modal.addClass("m-touch");
158
159                if (modalBackground.length > 0)
160                    modalBackground.addClass("mb-touch");
161
162                $(window).scroll(function() {
163                    modalMobilePos.apply(modal);
164                });
165            }
166            //api
167            $.extend(modal, {
168                modalShow: function(callback, forceShow) {
169                    modalShow.apply(modal, [callback, null, forceShow]);
170                },
171                modalClose: function(callback) {
172                    modalClose.apply(modal, [callback]);
173                },
174                modalTitle: function(content, callback) {
175                    modalTitle.apply(modal, [content, callback]);
176                },
177                modalContent: function(content, callback) {
178                    modalContent.apply(modal, [content, callback]);
179                },
180                modalBtns: function(content, callback) {
181                    modalBtns.apply(modal, [content, callback]);
182                },
183                modalPosition: function(callback) {
184                    modalPosition.apply(modal, [callback]);
185                },
186                modalSetClickOut: function(isEnabled) {
187                    if (isEnabled === false) {
188                        $("body").off('click.modalClickOut');
189                    } else {
190                        $("body").on('click.modalClickOut', function(e) {
191                            var isModalOnClick = $(e.target).closest(modal).length;
192
193                            if (!isModalOnClick && modal.is(":visible")) {
194                                modalClose.apply(modal);
195                            }
196                        });
197                    }
198                }
199            }, { options: options });
200
201            if (options.initCallback) {
202                options.initCallback();
203            }
204
205
206            modal.data('modal', modal);
207
208            return modal;
209            //functions
210
211            function modalClose(callback) {
212                var modalPrivate = $(this);
213                if (modalPrivate.is(":visible")) {
214                    if (options.beforeClose) (options.beforeClose).apply(modalPrivate, [modalPrivate]);
215
216
217                    var modalsSiblings = $('.modal:visible').not(modalPrivate),
218                        isBgShowedSiblings = false;
219
220
221                    for (var i = 0, il = modalsSiblings.length; i < il; i += 1) {
222                        if (modalsSiblings.eq(i).data('modal').options.isEnableBackgroun
222d) {
223                            isBgShowedSiblings = true;
224                            break;
225                        }
226                    }
227
228                    if (options.isEnableBackground && isBgShowedSiblings === false) {
229                        modalPrivate.prevAll("div.modal-background").hide();
230                    }
231
232                    modal.hide();
233
234                    if (callback) callback.apply(modalPrivate);
235
236
237                    if (modalsTempStorage.length > 0) {
238                        var temp = modalsTempStorage[0];
239                        modalsTempStorage.splice(0, 1);
240
241                        temp.data('modal').modalShow();
242                    }
243
244                }
245            }
246
247            function modalShow(callback, event, forceShow) {
248                event = event || window.event;
249                if (event) {
250                    if (event.stopPropagation) {
251                        event.stopPropagation();
252                    } else {
253                        event.cancelBubble = true;
254                    }
255                }
256
257                var modalPrivate = $(this);
258
259                if (options.forceShow === false && ($('.modal:visible').not(modalPrivate).length > 0 || $('.js-bubble-zone:visible').length > 0) && (forceShow == false || forceShow == null)) {
260                    modalsTempStorage.push(modalPrivate);
261                    return;
262                }
263
264                if (modalPrivate.is(":hidden")) {
265                    if (options.beforeOpen) (options.beforeOpen).apply(modalPrivate, [modalPrivate]);
266
267                    if (options.isEnableBackground)
268                        modalPrivate.prevAll("div.modal-background").show();
269
270
271                    if (options.hideError) {
272                        var elems = $("input,select,textrea").not(":submit, :reset, :image, [disabled]").filter(function() {
273                            return (this.className.indexOf("valid-") != -1);
274                        });
275                        elems.nextAll(".error-message").hide();
276                    }
277
278                    modalPrivate.show();
279
280                    if (options.positionShow) modalPosition.apply(modalPrivate);
281
282                    if (options.afterOpen) {
283                        (options.afterOpen).apply(modalPrivate, [modalPrivate, event]);
284                    }
285
286                    if (callback) callback.apply(modalPrivate);
287
288                }
289            }
290
291            function modalTitle(newContent, callback) {
292
293                if (!newContent) newContent = " ";
294
295                var modalPrivate = $(this);
296
297                if (!title.length) {
298                    modalPrivate.prepend("<div class='title'></div>");
299                    title = modalPrivate.children("div.title");
300                }
301
302                title.html(newContent);
303
304                if (callback)
305                    callback.apply(modalPrivate, [title]);
306            }
307
308            function modalContent(newContent, callback) {
309
310                if (!newContent) newContent = " ";
311
312                var modalPrivate = $(this),
313                    content = modalPrivate.find('.content'),
314                    title = modalPrivate.find('.title');
315
316                if (content.length === 0) {
317
318                    content = $('<div />', { 'class': 'content' });
319
320                    if (title.length > 0) {
321                        title.after(content);
322                    } else {
323                        modalPrivate.prepend(content);
324                    }
325                }
326
327                content.html(newContent);
328
329                if (callback) callback.apply(modalPrivate, [content]);
330            }
331
332            function modalBtns(arrayBtn) {
333                var modalPrivate = $(this);
334                var btnsContainer = modalPrivate.children("div.btns");
335
336                if (!arrayBtn && btnsContainer.length) btnsContainer.empty();
337
338
339                if (!btnsContainer.length) {
340                    modalPrivate.append("<div class='btns'></div>");
341                    btnsContainer = modalPrivate.children("div.btns");
342                } else {
343                    btnsContainer.empty();
344                }
345
346                var htmlBtns = "";
347
348                $.each(arrayBtn, function(idx, el) {
349                    htmlBtns += "<a href='javascript:void(0);' class='btn  btn-modal ";
350                    if (el.classBtn)
351                        htmlBtns += el.classBtn + "'>";
352                    else
353                        htmlBtns += "'>";
354                    if (el.textBtn)
355                        htmlBtns += el.textBtn + "</a>";
356                });
357
358                btnsContainer.html(htmlBtns);
359
360                var btns = btnsContainer.children("a.btn");
361                btns.each(function(idx, el) {
362                    if (arrayBtn[idx].func != null)
363                        $(el).click(arrayBtn[idx].func);
364                    if (arrayBtn[idx].isBtnClose == true)
365                        $(el).click(function() { modalClose.apply(modalPrivate); });
366                });
367            }
368
369            function modalPosition(callback) {
370                //reset
371                modal.css({
372                    left: 0,
373                    top: 0,
374                });
375
376
377                var modalPrivate = $(this),
378                    widthModal = modalPrivate.outerWidth(),
379                    heightModal = modalPrivate.outerHeight(),
380                    bodyWidth = $(window).width(),
381                    bodyHeight = $(window).height(),
382                    left = 0,
383                    top = 0;
384
385                //check iframe embed
386                if (window != window.top && window.VK != null && window.VK.addCallback != null) {
387                    // I'm in a frame!
388                    VK.addCallback('onScrollTop', function(vkScrollTop, vkWindowHeight, vkMarginApp, isVkWindowActive) {
389
390
391                        if (window.jQuery.IsTouchDevice && jQuery.IsTouchDevice()) {
392                            modalMobilePos.apply(modalPrivate);
393                        } else {
394                            left = (bodyWidth - widthModal) / 2;
395                            top = (vkWindowHeight - vkMarginApp - heightModal + vkScrollTop) / 2;
396
397                            modal.css({
398                                left: left,
399                                top: top,
400                                opacity: options.opacityModal
401                            });
402                        }
403
404                        if (callback) callback.apply(modalPrivate);
405                    });
406
407                    VK.callMethod('scrollTop');
408
409                } else {
410
411
412                    if (window.jQuery.IsTouchDevice && jQuery.IsTouchDevice()) {
413                        modalMobilePos.apply(modalPrivate);
414                    } else {
415                        left = (bodyWidth - widthModal) / 2;
416                        top = (bodyHeight - heightModal) / 2;
417
418                        modal.css({
419                            left: left,
420                            top: top,
421                            opacity: options.opacityModal
422                        });
423                    }
424
425                    if (callback) callback.apply(modalPrivate);
426                }
427
428
429            }
430
431            function modalControlEvent(event, modal) {
432                if (modal.is(":hidden")) {
433                    if (options.controlBeforeOpen) {
434                        resultControlBeforeOpen = (options.controlBeforeOpen).apply(this, [modal, event]);
435
436                        if (resultControlBeforeOpen === false) {
437                            return;
438                        }
439                    }
440
441                    modalShow.apply(modal, [null, event]); //null - callback
442
443                    if (options.controlAfterOpen)
444                        (options.controlAfterOpen).apply(modal, [modal, event]);
445                }
446            }
447
448            function modalMobilePos() {
449                var modal = $(this),
450                    modalBg = options.isEnableBackground === true ? $("div.modal-background") : [],
451                    modalOffset = modal.offset(),
452                    widthModal = modal.outerWidth(),
453                    bodyWidth = $(window).width();
454
455                modal.css({
456                    top: $(window).scrollTop(),
457                    left: (bodyWidth - widthModal) / 2,
458                    opacity: options.opacityModal
459                });
460
461                if (modalBg.length > 0) {
462                    modalBg.css({ height: $(document).height() });
463                }
464
465            }
466
467        }
468    });
469
470
471    jQuery.advModal.reopen = function () {
472
473        if (modalsTempStorage.length > 0 && $('.modal:visible').length === 0) {
474            modalsTempStorage[0].data('modal').modalShow();
475            modalsTempStorage.splice(0, 1);
476        }
477    };
478
479    jQuery.advModal.isQueueEmpty = function () {
480        return modalsTempStorage.length === 0;
481    };
482
483    jQuery.advModal.countModalActive = function () {
484        return $('.modal:visible').length;
485    };
486})(jQuery);
487
488

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.