PageSourceSearch

http://orangeparents.org/js/jquery.modal8512.js?ver=0.9.1

js orangeparents.org collected 2026-09-26 21:06:36 UTC 7,907 bytes, 244 lines download raw bytes

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

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.