PageSourceSearch

https://www.haveringmind.org.uk/wp-content/plugins/lottery-for-woo…/jquery-modal/jquery.modal.js?ver=13.4.0

js haveringmind.org.uk collected 2026-09-24 12:24:18 UTC 7,463 bytes, 266 lines download raw bytes

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

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.