PageSourceSearch

https://hpbexpo.com/wp-content/themes/hpbe2022/js/jquery.modal.js

js hpbexpo.com collected 2026-09-26 00:41:27 UTC 7,998 bytes, 246 lines download raw bytes

vendor: 7,998 bytes, lines 1-246
1/*
2    A simple jQuery modal (http://github.com/kylefox/jquery-modal)
3    Version 0.9.2
4*/
5
6(function (factory) {
7  // Making your jQuery plugin work better with npm tools
8  // http://blog.npmjs.org/post/112712169830/making-your-jquery-plugin-work-better-with-npm
9  if(typeof module === "object" && typeof module.exports === "object") {
10    factory(require("jquery"), window, document);
11  }
12  else {
13    factory(jQuery, window, document);
14  }
15}(function($, window, document, undefined) {
16
17  var modals = [],
18      getCurrent = function() {
19        return modals.length ? modals[modals.length - 1] : null;
20      },
21      selectCurrent = function() {
22        var i,
23            selected = false;
24        for (i=modals.length-1; i>=0; i--) {
25          if (modals[i].$blocker) {
26            modals[i].$blocker.toggleClass('current',!selected).toggleClass('behind',selected);
27            selected = true;
28          }
29        }
30      };
31
32  $.modal = function(el, options) {
33    var remove, target;
34    this.$body = $('body');
35    this.$html = $('html');
36    this.options = $.extend({}, $.modal.defaults, options);
37    this.options.doFade = !isNaN(parseInt(this.options.fadeDuration, 10));
38    this.$blocker = null;
39    if (this.options.closeExisting)
40      while ($.modal.isActive())
41        $.modal.close(); // Close any open modals.
42    modals.push(this);
43    if (el.is('a')) {
44      target = el.attr('href');
45      this.anchor = el;
46      //Select element by id from href
47      if (/^#/.test(target)) {
48        this.$elm = $(target);
49        if (this.$elm.length !== 1) return null;
50        this.$body.append(this.$elm);
51        this.open();
52      //AJAX
53      } else {
54        this.$elm = $('<div>');
55        this.$body.append(this.$elm);
56        remove = function(event, modal) { modal.elm.remove(); };
57        this.showSpinner();
58        el.trigger($.modal.AJAX_SEND);
59        $.get(target).done(function(html) {
60          if (!$.modal.isActive()) return;
61          el.trigger($.modal.AJAX_SUCCESS);
62          var current = getCurrent();
63          current.$elm.empty().append(html).on($.modal.CLOSE, remove);
64          current.hideSpinner();
65          current.open();
66          el.trigger($.modal.AJAX_COMPLETE);
67        }).fail(function() {
68          el.trigger($.modal.AJAX_FAIL);
69          var current = getCurrent();
70          current.hideSpinner();
71          modals.pop(); // remove expected modal from the list
72          el.trigger($.modal.AJAX_COMPLETE);
73        });
74      }
75    } else {
76      this.$elm = el;
77      this.anchor = el;
78      this.$body.append(this.$elm);
79      this.open();
80    }
81  };
82
83  $.modal.prototype = {
84    constructor: $.modal,
85
86    open: function() {
87      var m = this;
88      this.block();
89      this.anchor.blur();
90      if(this.options.doFade) {
91        setTimeout(function() {
92          m.show();
93        }, this.options.fadeDuration * this.options.fadeDelay);
94      } else {
95        this.show();
96      }
97      $(document).off('keydown.modal').on('keydown.modal', function(event) {
98        var current = getCurrent();
99        if (event.which === 27 && current.options.escapeClose) current.close();
100      });
101      if (this.options.clickClose)
102        this.$blocker.click(function(e) {
103          if (e.target === this)
104            $.modal.close();
105        });
106    },
107
108    close: function() {
109      modals.pop();
110      this.unblock();
111      this.hide();
112      if (!$.modal.isActive())
113        $(document).off('keydown.modal');
114    },
115
116    block: function() {
117      this.$elm.trigger($.modal.BEFORE_BLOCK, [this._ctx()]);
118      this.$body.css('overflow','hidden');
119      this.$blocker = $('<div class="' + this.options.blockerClass + ' blocker current"></div>').appendTo(this.$body);
120      selectCurrent();
121      if(this.options.doFade) {
122        this.$blocker.css('opacity',0).animate({opacity: 1}, this.options.fadeDuration);
123      }
124      this.$elm.trigger($.modal.BLOCK, [this._ctx()]);
125    },
126
127    unblock: function(now) {
128      if (!now && this.options.doFade)
129        this.$blocker.fadeOut(this.options.fadeDuration, this.unblock.bind(this,true));
130      else {
131        this.$blocker.children().appendTo(this.$body);
132        this.$blocker.remove();
133        this.$blocker = null;
134        selectCurrent();
135        if (!$.modal.isActive())
136          this.$body.css('overflow','');
137          this.$html.css('overflow','');
138      }
139    },
140
141    show: function() {
142      this.$elm.trigger($.modal.BEFORE_OPEN, [this._ctx()]);
143      if (this.options.showClose) {
144        this.closeButton = $('<a href="#close-modal" rel="modal:close" class="close-modal ' + this.options.closeClass + '">' + this.options.closeText + '</a>');
145        this.$elm.append(this.closeButton);
146      }
147      this.$elm.addClass(this.options.modalClass).appendTo(this.$blocker);
148      if(this.options.doFade) {
149        this.$elm.css({opacity: 0, display: 'inline-block'}).animate({opacity: 1}, this.options.fadeDuration);
150      } else {
151        this.$elm.css('display', 'inline-block');
152      }
153      this.$elm.trigger($.modal.OPEN, [this._ctx()]);
154    },
155
156    hide: function() {
157      this.$elm.trigger($.modal.BEFORE_CLOSE, [this._ctx()]);
158      if (this.closeButton) this.closeButton.remove();
159      var _this = this;
160      if(this.options.doFade) {
161        this.$elm.fadeOut(this.options.fadeDuration, function () {
162          _this.$elm.trigger($.modal.AFTER_CLOSE, [_this._ctx()]);
163        });
164      } else {
165        this.$elm.hide(0, function () {
166          _this.$elm.trigger($.modal.AFTER_CLOSE, [_this._ctx()]);
167        });
168      }
169      this.$elm.trigger($.modal.CLOSE, [this._ctx()]);
170    },
171
172    showSpinner: function() {
173      if (!this.options.showSpinner) return;
174      this.spinner = this.spinner || $('<div class="' + this.options.modalClass + '-spinner"></div>')
175        .append(this.options.spinnerHtml);
176      this.$body.append(this.spinner);
177      this.spinner.show();
178    },
179
180    hideSpinner: function() {
181      if (this.spinner) this.spinner.remove();
182    },
183
184    //Return context for custom events
185    _ctx: function() {
186      return { elm: this.$elm, $elm: this.$elm, $blocker: this.$blocker, options: this.options, $anchor: this.anchor };
187    }
188  };
189
190  $.modal.close = function(event) {
191    if (!$.modal.isActive()) return;
192    if (event) event.preventDefault();
193    var current = getCurrent();
194    current.close();
195    return current.$elm;
196  };
197
198  // Returns if there currently is an active modal
199  $.modal.isActive = function () {
200    return modals.length > 0;
201  };
202
203  $.modal.getCurrent = getCurrent;
204
205  $.modal.defaults = {
206    closeExisting: true,
207    escapeClose: true,
208    clickClose: true,
209    closeText: 'Close',
210    closeClass: '',
211    modalClass: "modal",
212    blockerClass: "jquery-modal",
213    spinnerHtml: '<div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div>',
214    showSpinner: true,
215    showClose: true,
216    fadeDuration: null,   // Number of milliseconds the fade animation takes.
217    fadeDelay: 1.0        // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
218  };
219
220  // Event constants
221  $.modal.BEFORE_BLOCK = 'modal:before-block';
222  $.modal.BLOCK = 'modal:block';
223  $.modal.BEFORE_OPEN = 'modal:before-open';
224  $.modal.OPEN = 'modal:open';
225  $.modal.BEFORE_CLOSE = 'modal:before-close';
226  $.modal.CLOSE = 'modal:close';
227  $.modal.AFTER_CLOSE = 'modal:after-close';
228  $.modal.AJAX_SEND = 'modal:ajax:send';
229  $.modal.AJAX_SUCCESS = 'modal:ajax:success';
230  $.modal.AJAX_FAIL = 'modal:ajax:fail';
231  $.modal.AJAX_COMPLETE = 'modal:ajax:complete';
232
233  $.fn.modal = function(options){
234    if (this.length === 1) {
235      new $.modal(this, options);
236    }
237    return this;
238  };
239
240  // Automatically bind links with rel="modal:close" to, well, close the modal.
241  $(document).on('click.modal', 'a[rel~="modal:close"]', $.modal.close);
242  $(document).on('click.modal', 'a[rel~="modal:open"]', function(event) {
243    event.preventDefault();
244    $(this).modal();
245  });
246}));

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.