PageSourceSearch

https://www.goldenstatemint.com/skin/common_files/js/popup_open.js?v=1790419156

js goldenstatemint.com collected 2026-09-26 10:40:06 UTC 10,671 bytes, 452 lines download raw bytes

1/* vim: set ts=2 sw=2 sts=2 et: */
2/**
3 * Popup modal dialog widget
4 * 
5 * @category   X-Cart
6 * @package    X-Cart
7 * @subpackage JS Library
8 * @author     Ruslan R. Fazlyev <[email protected]> 
9 * @version    e1e16d7cc46b8d75b2f817c74bac7008bfcd0383, v43 (xcart_4_7_11), 2019-03-11 10:00:10, popup_open.js, aim
10 * @link       https://www.x-cart.com/
11 * @see        ____file_see____
12 */
13
14/* global ajax */
15
16/**
17 * Extend UI dialog widget
18 */
19
20$.extend($.ui.dialog.prototype, {
21
22  // Load content from script
23  load: function(src, title, postData) {
24
25    var o = this;
26
27    $(ajax.messages).off('popupDialogCall'); /*UnBiNd_deprecated_in_3_0*/
28
29    $(ajax.messages).on( /*BiNd_deprecated_in_3_0*/
30      'popupDialogCall',
31      function(e, data) {
32
33        switch (data.action) {
34
35          case 'message':
36            o.showMessage(data.message);
37            o.element.unblock();
38            break;
39
40          case 'load':
41            o.loadContent(data.src);
42            break;
43          
44          case 'close':
45            o.close();
46            break;
47          
48          case 'jsCall':
49            if (data.toEval) {
50              eval(data.toEval);
51            }
52            break;
53 
54        }
55      }
56    );
57
58    return this.loadContent(src, postData);
59  },
60
61  callback: function(state, a, b, c, d) {
62
63    if (!state) {
64      xAlert(txt_ajax_error_note, lbl_error, 'E');
65      return false;
66    }
67
68    return this.onload(a, 'success');
69  },
70
71  // Get remove content
72  loadContent: function (src, postData) {
73
74    src += (src.search(/\?/) === -1 ? '?' : '&') + 'open_in_layer=Y&is_ajax_request=Y&keep_https=Y';
75    var o = this;
76
77    if (postData === undefined) {
78      var _type = 'GET';
79      var _data = {};
80    } else {
81      var _type = 'POST';
82      var _data = postData;
83    }
84
85    return ajax.query.add(
86      {
87        type: _type,
88        url: src,
89        data: _data,
90        success: function(a, b, c, d) {
91          return o.callback(true, a, b, c, d);
92        },
93        error: function(a, b, c, d) {
94          this.close();
95          return o.callback(false, a, b, c, d);
96        }
97      }
98    ) !== false;
99
100  },
101 
102  // Onsubmit handler
103  submitHandler: function(f) {
104
105    if (undefined !== f.onsubmit && f.onsubmit && f.onsubmit.constructor !== String && (f.popup_open_submit = true) && !f.onsubmit()) {
106        return true;
107    }
108
109    if (!checkFormFields(f)) {
110      return true;
111    }
112
113    var elm = $(f).parents('.popup-dialog').get(0);
114   
115    $(elm).block();
116
117    var url = f.action;
118    url += (url.search(/\?/) === -1 ? '?' : '&') + 'open_in_layer=Y&is_ajax_request=Y&keep_https=Y';
119
120    var o = this;
121
122    return ajax.query.add(
123      {
124        type: f.method ? f.method.toUpperCase() : 'GET',
125        url: url,
126        data: $(f).serialize(),
127        success: function(a, b, c, d) {
128          return o.callback(true, a, b, c, d);
129        },
130        error: function(a, b, c, d) {
131          return o.callback(false, a, b, c, d);
132        }
133      }
134    ) !== false;    
135
136  },
137
138  // Link onclick handler
139  clickHandler: function(l) {
140
141    var url = l.href;
142    url += (url.search(/\?/) === -1 ? '?' : '&') + 'open_in_layer=Y&is_ajax_request=Y&keep_https=Y';
143
144    var o = this;
145
146    return ajax.query.add(
147      {
148        type: 'GET',
149        url: url,
150        data: {},
151        success: function(a, b, c, d) {
152          return o.callback(true, a, b, c, d);
153        },
154        error: function(a, b, c, d) {
155          return o.callback(false, a, b, c, d);
156        }
157      }
158    ) !== false;    
159  },
160
161  // Process onload method
162  onload: function(data, s) {
163
164    if (s != 'success') {
165      return false;
166    }
167    
168    if (!this.processResponse(data)) {
169
170      if (this.insertData(data)) {
171        this.processInsertData();
172        this.activate();
173        // WA for Firefox.For some reason autofocus html5 attr does not work for Firefox
174        $('form', this.element).find("input[autofocus]").eq(0).trigger('focus'); /*FoCUs_trigger_deprecated_in_3_3*/
175      }
176
177    }
178
179    return true;
180  },
181
182  // Activate window
183  activate: function() {
184
185    if (!this.isOpen()) {
186      this.open();
187    }
188
189    this.element.unblock();
190
191    if (this.option('height') > this.option('maxHeight')) {
192      this.option('height', this.option('maxHeight'));
193    }
194    
195    if (this.option('width') > this.option('maxWidth')) {
196      this.option('width', this.option('maxWidth'));
197    }
198  
199    
200    this._position('center');
201   
202  },
203
204  // Show message
205  showMessage: function(data) {
206    
207    if (data === undefined || !data.type || !data.content) {
208      return false;
209    }
210
211    var msgbox = $('.ajax-popup-error-message', this.element).get(0);
212
213    if (msgbox !== undefined) {
214      var icon = $(document.createElement('span')).attr('class', 'ui-icon ' + (data.type == 'I' ? 'ui-icon-info' : 'ui-icon-alert'));
215      var text = $(msgbox).children('p').get(0);
216
217      if (data.type == 'I') {
218        $(msgbox).removeClass('ui-state-error').addClass('ui-state-highlight');
219      } else {
220        $(msgbox).removeClass('ui-state-highlight').addClass('ui-state-error');
221      }
222
223      $(msgbox).width(this.element.width());
224
225      $(text).html(data.content).prepend(icon);
226      if ($(msgbox).not(':visible')) {
227        $(msgbox).show();
228      }
229    }
230
231  },
232
233  // Process service signatures from AJAX response
234  processResponse: function(data) {
235
236    if (!data)
237      return false;
238
239    var m, l;
240
241    if (data.search(/\/\* CMD: opener_reload \*\//) != -1) {
242      if (typeof this.option('close') == 'function' || typeof this.option('beforeClose') == 'function') {
243        // raise close/destroy event https://sd.x-cart.com/view.php?id=147669
244        this.close(); /*can be conditional as we use whole window.location.reload not parent ajax section load.*/
245      }
246      // Opener window reload
247      window.location.reload();
248      return true;
249    }
250    
251    if (data.search(/\/\* CMD: opener_relocate \*\//) != -1) {
252      // Opener window redirect
253      this.close();
254      if (m = data.match(/window.parent.location = '([^']+)'/)) { 
255        window.location = m[1];
256      }
257      return true;
258    }
259
260    if (data.search(/\/\* CMD: window_close \*\//) != -1) {
261      // Close current window
262      this.close();
263      return true;
264    }
265
266    try {
267      if ((m = data.match(/<meta http-equiv="Refresh" content="[0-9]+;URL=([^"]+)" \/>/)) || (this._ajax && (l = this._ajax.getResponseHeader('Location')))) {
268
269        // Redirect
270        if (m)
271          l = m[1];
272
273        this.load(l);
274        return true;
275      }
276    } catch (e) { }
277
278    return false;
279  },
280
281  // Parse page html and insert content
282  insertData: function(data) {
283
284    var m;
285    data = data.replace(/\r/g, '');
286    m = data.match(new RegExp("<!-- MAIN -->\n*((?:.*\n)+.*)<!-- \/MAIN -->"));
287    if (!m)
288      m = data.match(new RegExp("<body[^>]*>\n*((?:.*\n)+.*)<\/body>", 'i'));
289
290    if (!m)
291      return false;
292
293    this.element.html(m[1]);
294
295    if (m = data.match(new RegExp("<title>(.+)<\/title>"))) {
296      this.setTitle(m[1]);
297      this.element.find('h1:first').hide();
298      this.element.prepend('<div class="ajax-popup-error-message ui-state-highlight ui-corner-all"><p><span class="ui-icon ui-icon-info"></span></p></div>');
299    }
300
301    return true;
302  },
303
304  // Set dialog title
305  setTitle: function(title) {
306    $(".ui-dialog-title", this.uiDialogTitlebar).html(title ? title : '');
307  },
308
309  // Bind handlers on some events
310  processInsertData: function() {
311
312    $(this).trigger('onload');
313
314    var o = this; 
315
316    $('form', this.element).on('submit', function() { /*BiNd_deprecated_in_3_0*/
317      return !o.submitHandler(this);
318    });
319
320    $('a:not([href^="javascript:"])', this.element).not(".external_link").on('click', function() { /*BiNd_deprecated_in_3_0*/
321      return !o.clickHandler(this);
322    });
323
324    return true;
325  }
326
327});
328
329
330/**
331 * Popup dialog class (jQuery UI dialog) 
332 */
333
334function popupOpen(src, title, params, postData) {
335
336  // Close existing dialog
337  $('.popup-dialog').dialog('destroy').remove();
338
339  var popup = $(document.createElement('div'))
340    .attr('class', 'popup-dialog')
341    .css('display', 'none')
342    .appendTo('body');
343
344  var popup_width = parseInt($(this).width()) - 20;
345  var popup_height = parseInt($(this).height()) - 20;
346
347  var dialogOpts = {
348    modal:     true,
349    autoOpen:  true,
350    draggable: false,
351    resizable: false,
352    maxWidth:  '800',
353    maxHeight: '800',
354    minWidth:  300,
355    width:     popup_width < 800 ? popup_width : 800,
356    height:    popup_height < 800 ? popup_height : 800,
357    position:  {
358      my : 'center center',
359      at : 'center center'
360    },
361    classes: {
362      'ui-dialog': 'fs-ui-dialog'
363    },
364    zIndex: 5000,
365    closeOnEscape: true,
366    create: function(event, ui) {
367      $('body').addClass('fs-popup-opened');
368    },
369    open: function(event, ui) {
370
371    },
372    beforeClose: function(event, ui) {
373      $('body').removeClass('fs-popup-opened');
374    },
375  };
376
377  if (typeof window.matchMedia !== 'undefined') {
378    dialogOpts.mediaQuery = window.matchMedia("(orientation: portrait)");
379
380    dialogOpts.mediaQuery.addListener(function(m) {
381      var width = $('.popup-dialog').dialog('option', 'width');
382      var height = $('.popup-dialog').dialog('option', 'height');
383
384      var renderDelay = 250; // delay for rerender
385
386      if(m.matches) {
387        setTimeout(function() {
388          $('.popup-dialog').dialog('option', 'width', height);
389          $('.popup-dialog').dialog('option', 'height', width);
390        }, renderDelay);
391      }
392      else {
393        setTimeout(function() {
394          $('.popup-dialog').dialog('option', 'width', height);
395          $('.popup-dialog').dialog('option', 'height', width);
396        }, renderDelay);
397      }
398    });
399  }
400
401  if (undefined !== params) {
402    for (var i in params) {
403      dialogOpts[i] = params[i];
404    }
405  }
406
407  try {
408    $(popup)
409      .dialog(dialogOpts)
410      .block()
411      .dialog('load', src, title, postData);
412
413  } catch(e) {
414    return false;
415  }
416
417  // Small hack to close a dialog on window.close() call
418  window.close = function() {
419    $(popup).dialog('close');
420  };
421
422  return true;
423}
424
425function popupOpenInline(selector, params) {
426
427  $('.popup-dialog').dialog('destroy').remove();
428
429  const popup = $('<div class="popup-dialog"></div>')
430    .append($(selector).show())
431    .appendTo('body');
432
433  const dialogOpts = $.extend({
434    modal: true,
435    width: 400,
436    height: 'auto',
437    draggable: false,
438    resizable: false,
439    classes: {
440      'ui-dialog': 'fs-ui-dialog'
441    },
442    close: function () {
443      console.log('close')
444      $(selector).hide().appendTo('body');
445    }
446  }, params || {});
447
448  popup.dialog(dialogOpts);
449
450  return popup;
451}
452

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.