PageSourceSearch

https://adm-severouralsk.ru/static/uil/export/project_mo_theme_sho…/scripts/inova-popup.js?20260220222336

js adm-severouralsk.ru collected 2026-10-02 18:14:29 UTC 12,431 bytes, 356 lines download raw bytes

1inova_popup = new (function () {
2
3    var is_mobile = false;
4    try {
5        document.createEvent('TouchEvent');
6        is_mobile = true;
7    }
8    catch (e) {
9    }
10
11    var OFFSET = 20,
12        PADDING = 20;
13    if (is_mobile) {
14        OFFSET = 10;
15        PADDING = 10;
16    }
17
18    var re_body = new RegExp(/<body[\s.]*?>([^]*)<\/body>/);
19
20    function get_body(html) {
21        var result = html.match(re_body);
22        if (result === null)
23            return html;
24        return result[0];
25    }
26
27    var self = this,
28        $close,
29        $close_btn,
30        is_scroll = true,
31        win_scroll_y,
32        body_padding;
33
34    self.body = undefined;
35    self.wrapper = undefined;
36    self.content = undefined;
37    self.content_body = undefined;
38    self.title = undefined;
39    self.is_title = false;
40
41    function set_title(title) {
42        if (title) {
43            self.title.css('display', 'block').find('span').text(title);
44            self.is_title = true;
45        } else {
46            self.title.css('display', '').find('span').text('');
47            self.is_title = false;
48        }
49    }
50
51    function esc_hide(e) {
52        if (!self.is_freeze() && e.keyCode === 27) {
53            self.hide();
54        }
55    }
56
57    function check_init() {
58        if (self.body === undefined) {
59            $(document.body).append(
60                '<table class="uil-inova-popup" id="INOVA_POPUP"><tbody><tr><td>' +
61                '<div class="uil-inova-popup__wrapper">' +
62                '<div class="uil-inova-popup__content">' +
63                '<h1 class="uil-inova-popup__content__title"><span></span></h1>' +
64                '<div class="uil-inova-popup__content__body">' +
65                '</div>' +
66                '</div>' +
67                '<div class="uil-inova-popup__close" title="Закрыть"><div class="uil-inova-popup__close__btn" title="Закрыть"></div></div>' +
68                '</div>' +
69                '</table></td></tr></tbody>'
70            );
71            self.body = $('#INOVA_POPUP');
72            var $td = self.body.children('tbody').children('tr').children('td');
73            self.wrapper = $td.children('.uil-inova-popup__wrapper');
74            self.content = self.wrapper.children('.uil-inova-popup__content');
75            self.content_body = self.content.children('.uil-inova-popup__content__body');
76            self.title = self.content.children('h1.uil-inova-popup__content__title');
77            $close = self.wrapper.children('.uil-inova-popup__close');
78            $close_btn = $close.children('div');
79            $close_btn.on('click touchend', function (e) {
80                e.stopImmediatePropagation();
81                e.preventDefault();
82                if (!self.is_freeze())
83                    self.hide();
84            });
85        }
86        if (event_list.length > 0 && $._data(self.content_body[0], 'events') === undefined)
87            for (var idx in event_list)
88                if (event_list.hasOwnProperty(idx))
89                    self.content_body.on(event_list[idx][0], event_list[idx][1], event_list[idx][2]);
90    }
91
92    function set_scroll_state(state) {
93        if (!state) {
94            if (is_scroll) {
95                is_scroll = false;
96                win_scroll_y = window.scrollY;
97                var $body = $('body');
98                $body.css({'top': '-' + win_scroll_y + 'px', 'left': $body.offset().left, 'position': 'fixed', 'overflow-y': 'scroll'}).addClass('is-inova-popup');
99            }
100        } else {
101            if (!is_scroll) {
102                is_scroll = true;
103                $('body').css({'top': '', 'left': '', 'position': '', 'overflow-y': ''}).removeClass('is-inova-popup');
104                $('html, body').scrollTop(win_scroll_y);
105                /*var i = 0, interval = setInterval(function () {
106                 i++;
107                 if (i > 3) {
108                 clearInterval(interval);
109                 is_scroll = true;
110                 }
111                 $('html, body').scrollTop(win_scroll_y);
112                 }, 100);*/
113            }
114        }
115    }
116
117    var event_list = [];
118    self.on = function (etype, sel, func) {
119        event_list.push([etype, sel, func]);
120        return self;
121    };
122
123    self.update_position = function () {
124        var max_width = $(window).width() - OFFSET * 2,
125            max_height = $(window).height() - OFFSET * 2;
126        self.content_body.find('> *, > form > *').each(function () {
127            var $this = $(this), _max_width = $this.css('max-width');
128            _max_width = (_max_width.indexOf('px') > -1 ? parseInt(_max_width) : max_width) + body_padding * 2;
129            // console.log([$this.get(0), max_width, _max_width]);
130            max_width = Math.min(max_width, _max_width);
131        });
132        /*console.log({
133            'max-width': max_width + 'px',
134            'max-height': max_height + 'px'
135        });*/
136        self.content.css({
137            'max-width': max_width + 'px'
138        });
139        var max_height_body = max_height;
140        if (self.is_title)
141            max_height_body = max_height - self.title.outerHeight(true);
142        self.content_body.css({
143            'max-width': max_width - body_padding * 2 + 'px',
144            'max-height': max_height_body - body_padding * 2 + 'px'
145        });
146        return self;
147    };
148
149    self.show = function () {
150        set_scroll_state(false);
151        $(document).on('keydown', esc_hide);
152
153        check_init();
154        self.body.show();
155        self.content.css({
156            'max-width': '',
157            'padding-top': '',
158            'padding-bottom': '',
159            'opacity': ''
160        });
161        self.content_body.css({
162            'max-width': '',
163            'max-height': '',
164            'padding-right': '',
165            'padding-left': ''
166        });
167        self.title.css({
168            'margin-right': '',
169            'margin-left': ''
170        });
171        $close_btn.css({
172            'opacity': ''
173        });
174
175        var is_padding = self.is_title;
176        if (!is_padding) {
177            var body_offset = self.content.offset();
178            body_offset.bottom = body_offset.top + self.content.outerHeight();
179            body_offset.right = body_offset.left + self.content.outerWidth();
180            self.content_body.find('*').each(function () {
181                var $el = $(this);
182                $el.contents().each(function () {
183                    if (this.nodeType === 3) {
184                        var text = (this.textContent || this.innerText || '').replace(/^\s+|\s+$/g, '');
185                        if (text) {
186                            var el_offset = $el.offset();
187                            if (el_offset.top - body_offset.top <= 1) {
188                                is_padding = true;
189                                return false;
190                            }
191                            if (el_offset.left - body_offset.left <= 1) {
192                                is_padding = true;
193                                return false;
194                            }
195                            if (body_offset.bottom - (el_offset.top + $el.outerHeight()) <= 1) {
196                                is_padding = true;
197                                return false;
198                            }
199                            if (body_offset.right - (el_offset.left + $el.outerWidth()) <= 1) {
200                                is_padding = true;
201                                return false;
202                            }
203                        }
204                    }
205                    return !is_padding;
206                });
207                return !is_padding;
208            });
209        }
210        body_padding = is_padding ? PADDING : 0;
211
212        self.wrapper.css({
213            'margin': OFFSET + 'px'
214        });
215
216        self.content.css({
217            'padding-top': body_padding + 'px',
218            'padding-bottom': body_padding + 'px',
219            'opacity': 1
220        });
221        self.content_body.css({
222            'padding-right': body_padding + 'px',
223            'padding-left': body_padding + 'px',
224            'opacity': 1
225        });
226        self.title.css({
227            'margin-right': body_padding + 'px',
228            'margin-left': body_padding + 'px'
229        });
230
231        $close.css({
232            'top': '-' + OFFSET + 'px',
233            'right': '-' + OFFSET + 'px'
234        });
235
236        self.update_position();
237
238        self.content_body.find('input[type=text], input[type=password], textarea, select').first().focus();
239
240        return self;
241    };
242
243    self.hide = function () {
244        check_init();
245        $(document).trigger('inova_popup.hide:before', []);
246        self.content_body.html('');
247        self.body.hide();
248        set_title('');
249        set_scroll_state(true);
250        $(document).off('keydown', esc_hide);
251        $(document).trigger('inova_popup.hide:after', []);
252        return self;
253    };
254
255    self.is_shown = function () {
256        return self.body !== undefined && self.body.is(':visible');
257    };
258
259    self.freeze = function (state) {
260        if (self.is_shown()) {
261            check_init();
262            if (state === false)
263                self.body.removeClass('is-freeze');
264            else
265                self.body.addClass('is-freeze');
266        }
267        $(document).trigger('inova_popup.freeze', [state]);
268        return self;
269    };
270
271    self.is_freeze = function () {
272        return self.is_shown() && self.body.hasClass('is-freeze');
273    };
274
275    self.set_html = function (html, title) {
276        check_init();
277        if (typeof html === 'object')
278            html = html.get(0).outerHTML;
279        if (typeof title === 'string')
280            set_title(title);
281        $(document).trigger('inova_popup.set_html:before', [html, title]);
282        self.content_body.html(html);
283        self.body.removeClass('is-freeze');
284        $(document).trigger('inova_popup.set_html:after', [html, title]);
285        return self.show();
286    };
287
288    self.set_message = function (message, title) {
289        if (!(message.match(/^\s*</) !== null && message.match(/>\s*$/) !== null))
290            message = '<p class="center" style="padding: 1em 0">' + message + '</p>';
291        self.set_html('<div class="uil-inova-popup__content__message">' + message + '</div>', title);
292        $(document).trigger('inova_popup.set_message', [message, title]);
293        return self;
294    };
295
296    self.set_url = function (url, title, selector) {
297        $.ajax({
298            type: 'GET',
299            url: url,
300            dataType: 'html',
301            contentType: 'text/html',
302            beforeSend: function () {
303                if (self.is_shown())
304                    self.freeze();
305                else {
306                    self.set_message('Подождите...').freeze();
307                }
308            },
309            success: function (html) {
310                if (selector) {
311                    var $html = $(html);
312                    html = $html.find(selector).add($html.filter(selector));
313                } else {
314                    html = get_body(html);
315                }
316                if (html.length > 0)
317                    self.set_html(html, title);
318                else {
319                    self.set_message('Подождите...').freeze();
320                    setTimeout(function () {
321                        self.refresh_page();
322                    }, 1000);
323                }
324            },
325            error: function (req) {
326                var body = get_body(req.responseText);
327                self.set_message(body, 'Ошибка ' + req.status);
328            }
329        });
330        $(document).trigger('inova_popup.set_url', [url, selector, title]);
331        return self;
332    };
333
334    self.refresh_page = function () {
335        inova_popup.set_message('Подождите...').freeze();
336        $(document).trigger('inova_popup.refresh_page', []);
337        window.location.href = window.location.href.split('#', 1)[0];
338    };
339
340})();
341
342$(document)
343    .on('click', 'a[data-inova-popup]', function () {
344        var $this = $(this);
345        var title = $this.attr('data-title');
346        if (title === undefined) title = $this.attr('title');
347        if (title === undefined) title = $this.text();
348        inova_popup.set_url($this.attr('href'), title, $this.attr('data-inova-popup'));
349        return false;
350    });
351
352$(window)
353    .on('resize', $.debounce(500, function () {
354        if (inova_popup.is_shown())
355            inova_popup.update_position();
356    }));

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.