PageSourceSearch

https://moniker.com/themes/moniker/js/jquery.modal.js?v4042416364

js moniker.com collected 2026-10-02 02:21:31 UTC 7,498 bytes, 244 lines download raw bytes

vendor: 7,498 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	} else {
12		factory(jQuery, window, document);
13	}
14})(function ($, window, document, undefined) {
15	var modals = [],
16		getCurrent = function () {
17			return modals.length ? modals[modals.length - 1] : null;
18		},
19		selectCurrent = function () {
20			var i,
21				selected = false;
22			for (i = modals.length - 1; i >= 0; i--) {
23				if (modals[i].$blocker) {
24					modals[i].$blocker.toggleClass("current", !selected).toggleClass("behind", selected);
25					selected = true;
26				}
27			}
28		};
29
30	$.modal = function (el, options) {
31		var remove, target;
32		this.$body = $("body");
33		this.options = $.extend({}, $.modal.defaults, options);
34		this.options.doFade = !isNaN(parseInt(this.options.fadeDuration, 10));
35		this.$blocker = null;
36		if (this.options.closeExisting) while ($.modal.isActive()) $.modal.close(); // Close any open modals.
37		modals.push(this);
38		if (el.is("a")) {
39			target = el.attr("href");
40			this.anchor = el;
41			//Select element by id from href
42			if (/^#/.test(target)) {
43				this.$elm = $(target);
44				if (this.$elm.length !== 1) return null;
45				this.$body.append(this.$elm);
46				this.open();
47				//AJAX
48			} else {
49				this.$elm = $("<div>");
50				this.$body.append(this.$elm);
51				remove = function (event, modal) {
52					modal.elm.remove();
53				};
54				this.showSpinner();
55				el.trigger($.modal.AJAX_SEND);
56				$.get(target)
57					.done(function (html) {
58						if (!$.modal.isActive()) return;
59						el.trigger($.modal.AJAX_SUCCESS);
60						var current = getCurrent();
61						current.$elm.empty().append(html).on($.modal.CLOSE, remove);
62						current.hideSpinner();
63						current.open();
64						el.trigger($.modal.AJAX_COMPLETE);
65					})
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)
97				.off("keydown.modal")
98				.on("keydown.modal", function (event) {
99					var current = getCurrent();
100					if (event.which === 27 && current.options.escapeClose) current.close();
101				});
102			if (this.options.clickClose)
103				this.$blocker.click(function (e) {
104					if (e.target === this) $.modal.close();
105				});
106		},
107
108		close: function () {
109			modals.pop();
110			this.unblock();
111			this.hide();
112			if (!$.modal.isActive()) $(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) this.$blocker.fadeOut(this.options.fadeDuration, this.unblock.bind(this, true));
128			else {
129				this.$blocker.children().appendTo(this.$body);
130				this.$blocker.remove();
131				this.$blocker = null;
132				selectCurrent();
133				if (!$.modal.isActive()) this.$body.css("overflow", "");
134			}
135		},
136
137		show: function () {
138			this.$elm.trigger($.modal.BEFORE_OPEN, [this._ctx()]);
139			if (this.options.showClose) {
140				this.closeButton = $('<a href="#close-modal" rel="modal:close" class="close-modal ' + this.options.closeClass + '">' + '<i class="fa fa-times"></i>' + this.options.closeText + "</a>");
141				this.$elm.append(this.closeButton);
142			}
143			this.$elm.addClass(this.options.modalClass).appendTo(this.$blocker);
144			if (this.options.doFade) {
145				this.$elm.css({ opacity: 0, display: "inline-block" }).animate({ opacity: 1 }, this.options.fadeDuration);
146			} else {
147        //this.$elm.css('display', 'inline-block');
148				this.$elm.css("display", "flex");
149				this.$elm.css("justify-content", "center");
150				this.$elm.css("align-items", "center");
151			}
152			this.$elm.trigger($.modal.OPEN, [this._ctx()]);
153		},
154
155		hide: function () {
156			this.$elm.trigger($.modal.BEFORE_CLOSE, [this._ctx()]);
157			if (this.closeButton) this.closeButton.remove();
158			var _this = this;
159			if (this.options.doFade) {
160				this.$elm.fadeOut(this.options.fadeDuration, function () {
161					_this.$elm.trigger($.modal.AFTER_CLOSE, [_this._ctx()]);
162				});
163			} else {
164				this.$elm.hide(0, function () {
165					_this.$elm.trigger($.modal.AFTER_CLOSE, [_this._ctx()]);
166				});
167			}
168			this.$elm.trigger($.modal.CLOSE, [this._ctx()]);
169		},
170
171		showSpinner: function () {
172			if (!this.options.showSpinner) return;
173			this.spinner = this.spinner || $('<div class="' + this.options.modalClass + '-spinner"></div>').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: "",
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.