PageSourceSearch

https://matras-orenburg.ru/components/js/module_popup.js

js matras-orenburg.ru collected 2026-09-28 23:15:29 UTC 9,728 bytes, 277 lines download raw bytes

1function Modal(options = {}) {
2    this.show = {
3        header: true,
4        title: true,
5        content_loading_overlay: true,
6        footer: true
7    }
8
9    this.additional_class = '';
10    this.options = {}
11
12
13    this.setOptions(options);
14}
15
16
17Modal.prototype.setButtons = function(buttons = {})
18{
19
20}
21
22
23Modal.prototype.setCallback = function()
24{
25
26}
27
28
29Modal.prototype.setOptions = function(options = {})
30{
31    this.modal_name = options.name;
32    if(this.modal_name === '')
33    {
34        this.modal_name = this.MD5Time();
35    }
36
37    if(typeof options.show == 'undefined')
38    {
39        options.show = {};
40    }
41
42    this.show.header = options.show.header ?? this.show.header;
43    this.show.content_loading_overlay = options.show.content_loading_overlay ?? this.show.content_loading_overlay;
44    this.show.footer = options.show.footer ?? this.show.footer;
45    this.additional_class = options.additional_class ?? this.additional_class;
46
47    options.name = options.name ?? '';
48    options.title = options.title ?? '';
49    options.body = options.body ?? '';
50    options.href = options.href ?? '';
51    options.footer = options.footer ?? '';
52    options.buttons = options.buttons ?? '';
53    options.href = options.href ?? '';
54    options.href_data = options.href_data ?? '';
55    options.popup_width = options.popup_width ?? '';
56    options.popup_height = options.popup_height ?? '';
57    options.remove_on_close = options.remove_on_close ?? false;
58
59    this.options = options;
60}
61
62
63Modal.prototype.createModal = function(callback = '')
64{
65    var modal = $("#" + this.modal_name);
66
67    if((modal).length) {
68        $("#" + this.modal_name + ' + .modal-backdrop').remove();
69        modal.remove();
70    }
71
72    let modal_html = this.getModalHTML();
73    $('body').append(modal_html);
74    modal = $("#" + this.modal_name);
75
76    modal.modal();
77
78    var remove_on_close = this.options.remove_on_close;
79
80    $('.close', modal).click(function()
81    {       
82        modal.modal('hide');
83        return false;
84    });
85
86    if(remove_on_close)
87    {
88        modal.on('hide', function() {
89          console.log("backdrop-remove");
90            setTimeout(function() {
91                modal.remove();
92                $('.modal-backdrop').remove();
93            }, 500);
94
95
96        })
97    }
98
99    if(!remove_on_close) {
100
101        modal.on('hidden.bs.modal', function() {
102            
103            let video = $('video', modal);
104
105            if(video.length)
106            {
107              video[0].pause();
108            }
109
110        modal.modal('hide');
111
112        });
113        
114        modal.on('shown.bs.modal', function() {
115            
116            let video = $('video', modal);
117
118            if(video.length)
119            {
120              video[0].play();
121            }
122
123        modal.modal('show');
124
125        });        
126      
127    }
128
129    if(this.options.body === '' && this.options.href !== '')
130    {
131        this.loadBodyFromHref(modal, callback);
132    }
133    else
134    {
135        this.callCallback(callback);
136    }
137}
138
139
140Modal.prototype.callCallback = function(callback)
141{
142    var modal = $("#" + this.modal_name);
143
144    if(modal.length)
145    {
146        if($(document).find('.content-loading-overlay', modal))
147        {
148            $(document).find('.content-loading-overlay', modal).remove();
149        }
150
151        if(this.options.play_video_on_start)
152        {
153          var vid = $('video', modal);
154          vid[0].play();
155        }
156
157    }
158
159    if(callback)
160    {
161        callback.call();
162    }
163}
164
165
166Modal.prototype.loadBodyFromHref = function(modal, callback)
167{
168    var _ = this;
169
170    $.ajax({
171        url: this.options.href,
172        data: this.options.href_data,
173        processData: false,
174        contentType: false,
175        type: 'POST',
176        success: function (res)
177        {
178            $('.modal-body', modal).html(res);
179            _.callCallback(callback);
180        }
181    })
182
183}
184
185
186Modal.prototype.refresh = function(options = {})
187{
188
189}
190
191
192Modal.prototype.getModalHTML = function()
193{
194    let header = '';
195    if(this.show.header)
196    {
197        header = `
198            <div class="modal-header"> 
199              <div class="modal-title">${this.options.title}</div> 
200              <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button> 
201            </div> 
202        `;
203    }
204    else
205    {
206        header = `
207          <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button> 
208        `;
209    }
210
211    let content_loading_overlay = '';
212    if(this.show.content_loading_overlay)
213    {
214        content_loading_overlay = `
215            <div class=content-loading-overlay>
216                <img src="/i/ajax-loader.gif">
217            </div> 
218        `;
219    }
220
221
222    let body = `
223        <div class="modal-body"> 
224            ${this.options.body}
225        </div> 
226    `;
227
228
229
230
231    let footer = '';
232    if(this.show.footer)
233    {
234        footer = `
235            <div class="modal-footer">
236            ${this.options.footer}
237            </div>
238        `;
239    }
240
241    let additional_style = 'style="';
242
243    if(this.options.popup_width)
244    {
245        additional_style += `width: ${this.options.popup_width};`;
246    }
247    if(this.options.popup_height)
248    {
249        additional_style += `height: ${this.options.popup_height};`;
250    }
251
252    additional_style += '"';
253
254
255    let modal_html = `
256        <div class="modal fade ${this.additional_class}"  tabindex="-1" id="${this.modal_name}"> 
257            <div class="modal-dialog" ${additional_style}> 
258                <div class="modal-content"> 
259                    ${header}
260                    ${body}                
261                    ${content_loading_overlay}
262                    ${footer}
263                </div> 
264            </div> 
265        </div>
266    `;
267
268    return modal_html;
269}
270
271
272Modal.prototype.MD5Time = function() {
273    var MD5=function(d){d=unescape(encodeURIComponent(d));result=M(V(Y(X(d),8*d.length)));return result.toLowerCase()};function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r<d.length;
273r++)_=d.charCodeAt(r),f+=m.charAt(_>>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<<m%32;return _}function V(d){for(var _="",m=0;m<32*d.length;m+=8)_+=String.fromCharCode(d[m>>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n<d.length;n+=16){var h=m,t=f,g=r,e=i;f=md5_ii(f=md5_ii(f=md5_ii(f=md5_ii(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_ff(f=md5_ff(f=md5_ff(f=md5_ff(f,r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+0],7,-680876936),f,r,d[n+1],12,-389564586),m,f,d[n+2],17,606105819),i,m,d[n+3],22,-1044525330),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+4],7,-176418897),f,r,d[n+5],12,1200080426),m,f,d[n+6],17,-1473231341),i,m,d[n+7],22,-45705983),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+8],7,1770035416),f,r,d[n+9],12,-1958414417),m,f,d[n+10],17,-42063),i,m,d[n+11],22,-1990404162),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+12],7,1804603682),f,r,d[n+13],12,-40341101),m,f,d[n+14],17,-1502002290),i,m,d[n+15],22,1236535329),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+1],5,-165796510),f,r,d[n+6],9,-1069501632),m,f,d[n+11],14,643717713),i,m,d[n+0],20,-373897302),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+5],5,-701558691),f,r,d[n+10],9,38016083),m,f,d[n+15],14,-660478335),i,m,d[n+4],20,-405537848),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+9],5,568446438),f,r,d[n+14],9,-1019803690),m,f,d[n+3],14,-187363961),i,m,d[n+8],20,1163531501),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+13],5,-1444681467),f,r,d[n+2],9,-51403784),m,f,d[n+7],14,1735328473),i,m,d[n+12],20,-1926607734),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+5],4,-378558),f,r,d[n+8],11,-2022574463),m,f,d[n+11],16,1839030562),i,m,d[n+14],23,-35309556),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+1],4,-1530992060),f,r,d[n+4],11,1272893353),m,f,d[n+7],16,-155497632),i,m,d[n+10],23,-1094730640),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+13],4,681279174),f,r,d[n+0],11,-358537222),m,f,d[n+3],16,-722521979),i,m,d[n+6],23,76029189),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+9],4,-640364487),f,r,d[n+12],11,-421815835),m,f,d[n+15],16,530742520),i,m,d[n+2],23,-995338651),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+0],6,-198630844),f,r,d[n+7],10,1126891415),m,f,d[n+14],15,-1416354905),i,m,d[n+5],21,-57434055),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+12],6,1700485571),f,r,d[n+3],10,-1894986606),m,f,d[n+10],15,-1051523),i,m,d[n+1],21,-2054922799),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+8],6,1873313359),f,r,d[n+15],10,-30611744),m,f,d[n+6],15,-1560198380),i,m,d[n+13],21,1309151649),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+4],6,-145523070),f,r,d[n+11],10,-1120210379),m,f,d[n+2],15,718787259),i,m,d[n+9],21,-343485551),m=safe_add(m,h),f=safe_add(f,t),r=safe_add(r,g),i=safe_add(i,e)}return Array(m,f,r,i)}function md5_cmn(d,_,m,f,r,i){return safe_add(bit_rol(safe_add(safe_add(_,d),safe_add(f,i)),r),m)}function md5_ff(d,_,m,f,r,i,n){return md5_cmn(_&m|~_&f,d,_,r,i,n)}function md5_gg(d,_,m,f,r,i,n){return md5_cmn(_&f|m&~f,d,_,r,i,n)}function md5_hh(d,_,m,f,r,i,n){return md5_cmn(_^m^f,d,_,r,i,n)}function md5_ii(d,_,m,f,r,i,n){return md5_cmn(m^(_|~f),d,_,r,i,n)}function safe_add(d,_){var m=(65535&d)+(65535&_);return(d>>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,_){return d<<_|d>>>32-_}
274
275    var seconds = new Date().getTime() / 1000;
276    return MD5(seconds);
277}

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.