PageSourceSearch

https://www.newhydro.ru/assets/85dbda51/solution/solution.jui.dialog.ajax.js

js newhydro.ru collected 2026-10-01 13:58:30 UTC 9,980 bytes, 233 lines download raw bytes

1/**
2 * Created by pelmen on 14.01.14.
3 */
4(function ($) {
5    $.solution.ajax = $.solution.ajax || {};
6    $.solution.ajax.parseResponse = $.solution.ajax.parseResponse || function (s) {
7        if (/^js:/.test(s)) {
8            eval(s.substr(3));
9            return true;
10        }
11        return false;
12    };
13    $.solution.scrollbarWidth = 0;
14    function getScrollbarWidth() {
15        if ($.solution.scrollbarWidth > 0)
16            return $.solution.scrollbarWidth;
17        var outer = document.createElement("div");
18        outer.style.visibility = "hidden";
19        outer.style.width = "100px";
20        document.body.appendChild(outer);
21
22        var widthNoScroll = outer.offsetWidth;
23        // force scrollbars
24        outer.style.overflow = "scroll";
25
26        // add innerdiv
27        var inner = document.createElement("div");
28        inner.style.width = "100%";
29        outer.appendChild(inner);
30
31        var widthWithScroll = inner.offsetWidth;
32
33        // remove divs
34        outer.parentNode.removeChild(outer);
35
36        $.solution.scrollbarWidth = widthNoScroll - widthWithScroll;
37        return $.solution.scrollbarWidth;
38    }
39
40    $.widget('ui.dialog', $.ui.dialog, {
41        _isReload: false,
42        uiScrollableWrapper: null,
43        options: {
44            ajax: {
45                url: null,
46                data: {},
47                success: $.noop
48            },
49            selector: {
50                header: '.dialog-window-title',
51                content: '.dialog-window-content'
52            },
53            parent: $(document),
54            dialogPadding: 30
55        },
56        _create: function () {
57            if (this.options.modal) {
58                $('body:not([data-hide-scroll]),.solution-window-scroll-hide:not([data-hide-scroll])').each(function () {
59                    var _o = $(this), _p = {
60                        paddingRight: document.body.scrollHeight > document.body.clientHeight ? getScrollbarWidth() : 'initial'
61                    };
62                    if ($(this).hasClass('solution-window-scroll-hide')) {
63                        if (typeof $(this).data('scrollHideTarget') != 'undefined' && $(this).find($(this).data('scrollHideTarget')).length > 0) {
64                            _o = $(this).find($(this).data('scrollHideTarget'));
65                        }
66                    } else {
67                        _p.overflow = 'hidden';
68                    }
69                    $(this).attr('data-hide-scroll', 'data-hide-scroll');
70                    _o.css(_p);
71                });
72            }
73            if (this.options.ajax.url != null) {
74                this.options.autoOpen = false;
75                this._super();
76                if (this.options.modal)
77                    this._toScrollableWrapper();
78                $(this.element[0]).attr('data-ui-dialog-initialized', true).data('ui-dialog', {_emulate: true});
79                var ajaxOpts = $.extend({}, this.options.ajax, {
80                    dataType: 'html',
81                    context: this,
82                    cache: false,
83                    async: true
84                });
85                ajaxOpts.success = function () {
86                    var that = this;
87                    if (!$.solution.ajax.parseResponse(arguments[0])) {
88                        that._setOption('title', $(arguments[0]).find(that.options.selector.header).text());
89                        $(that.element[0]).html($(arguments[0]).find(that.options.selector.content).html());
90                        that.options.ajax.success.apply(that, arguments);
91                        that.open();
92                        that.innerSize();
93                        that.updatePosition();
94                        that.uiDialogTitlebar.find('.ui-dialog-titlebar-buttonpane').append(
95                            $(document.createElement('a'))
96                                .addClass('ui-dialog-titlebar-refresh ui-corner-all ui-state-default')
97                                .attr('role', 'button')
98                                .attr('href', '#')
99                                .click(function () {
100                                    $(this).closest('.ui-dialog').find('.ui-dialog-content').dialog('reload');
101                                    return false;
102                                })
103                                .append($(document.createElement('i')).addClass('icon-refresh'))
104                        );
105                    }
106                };
107                $.ajax(ajaxOpts);
108            } else {
109                this._super();
110                if (this.options.modal)
111                    this._toScrollableWrapper();
112            }
113        },
114        _toScrollableWrapper: function () {
115            this.uiDialog = this.uiDialog.detach();
116            this.uiScrollableWrapper = $(document.createElement('div'));
117            this.uiScrollableWrapper.addClass('ui-scrollable-wrapper');
118            this.uiScrollableWrapper.appendTo('body');
119            this.uiScrollableWrapper.css({
120                top: $(document).scrollTop(),
121                left: $(document).scrollLeft()
122            });
123            this.uiDialog.appendTo(this.uiScrollableWrapper);
124        },
125        open: function () {
126            this._super();
127            if (this.uiScrollableWrapper != null) {
128                this.uiScrollableWrapper.css('zIndex', this.uiDialog.css('zIndex'));
129            }
130        },
131        widget: function () {
132            return this.uiDialog;
133        },
134        reload: function () {
135            this._isReload = true;
136            var ajaxOpts = $.extend({}, this.options.ajax, {
137                dataType: 'html',
138                context: this,
139                cache: false,
140                async: true
141            });
142            ajaxOpts.success = function () {
143                var that = this;
144                if (!$.solution.ajax.parseResponse(arguments[0])) {
145                    that._setOption('title', $(arguments[0]).find(that.options.selector.header).text());
146                    $(that.element[0]).html($(arguments[0]).find(that.options.selector.content).html());
147                    that.innerSize();
148                    that.updatePosition();
149                    that.options.ajax.success.apply(that, arguments);
150                }
151                that._isReload = false;
152            };
153            $.ajax(ajaxOpts);
154        },
155        parent: function () {
156            if (typeof arguments[0] == 'function') {
157                arguments[0].call(this.options.parent, $(this.element[0]));
158            } else {
159                return this.options.parent;
160            }
161        },
162        close: function () {
163            if (this.options.modal && $('.ui-widget-overlay:visible').length == 1) {
164                $('body[data-hide-scroll],.solution-window-scroll-hide[data-hide-scroll]').each(function () {
165                    var _o = $(this);
166                    if ($(this).hasClass('solution-window-scroll-hide')) {
167                        if (typeof $(this).data('scrollHideTarget') != 'undefined' && $(this).find($(this).data('scrollHideTarget')).length > 0) {
168                            _o = $(this).find($(this).data('scrollHideTarget'));
169                        }
170                    }
171                    _o.css({
172                        overflow: '',
173                        paddingRight: ''
174                    });
175                    $(this).removeAttr('data-hide-scroll');
176                });
177            }
178            this._super();
179        },
180        destroy: function () {
181            this.uiDialog.prev('.ui-dialog-normal:first').remove();
182            var sw = this.uiScrollableWrapper;
183            this._super();
184            if (sw != null)
185                sw.remove();
186        },
187        updateTitle: function () {
188            var _t = $(arguments[0]).find(this.options.selector.header);
189            if (_t.length == 1)
190                this._setOption('title', _t.text());
191        },
192        innerSize: function () {
193            var that = this;
194            $(this.element[0])
195                .find('.solution-window-scroll-content')
196                .css({maxHeight: 'none'});
197            $(this.element[0])
198                .find('.solution-window-scroll-content')
199                .css({maxHeight: $(window).height() - this.uiDialogTitlebar.outerHeight() - this.options.dialogPadding});
200            $(this.element[0]).find('.solution-window-outer-scroll-wrapper').each(function () {
201                $(this)
202                    .find('.solution-window-inner-scroll-content')
203                    .css({maxHeight: 'none'});
204                $(this)
205                    .find('.solution-window-inner-scroll-content')
206                    .css({maxHeight: $(window).height() - $(this).find('.solution-window-inner-scroll-header').outerHeight() - 85 - that.options.dialogPadding});
207            });
208        },
209        updatePosition: function () {
210            if (this.options.modal) {
211                if (this.uiScrollableWrapper !== null) {
212                    this.uiScrollableWrapper.scrollTop(0);
213                }
214                this._setOption('position', this.options.position);
215            }
216        }
217    });
218    $(window)
219        .off('resize.solution-jda')
220        .on('resize.solution-jda', function () {
221            $('.ui-dialog .ui-dialog-content[data-ui-dialog-initialized]').dialog('innerSize').dialog('updatePosition');
222        })
223    ;
224    $(document)
225        .off('mousewheel.solution-jda DOMMouseScroll.solution-jda')
226        .on('mousewheel.solution-jda DOMMouseScroll.solution-jda', '.ui-dialog .solution-window-scroll-content,.ui-dialog .solution-window-inner-scroll-content', function (e) {
227            var d = e.originalEvent.wheelDelta || -e.originalEvent.detail,
228                dir = d > 0 ? 'up' : 'down',
229                stop = (dir == 'up' && this.scrollTop == 0) || (dir == 'down' && this.scrollTop >= this.scrollHeight - this.offsetHeight);
230            stop && e.preventDefault();
231        })
232    ;
233})(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.