PageSourceSearch

https://app.rezedent.com/Content/themes/carrot/js/bootstrap-modal.js

js rezedent.com collected 2026-10-06 00:31:21 UTC 9,413 bytes, 379 lines download raw bytes

1/* ===========================================================
2 * bootstrap-modal.js v2.2.0
3 * ===========================================================
4 * Copyright 2012 Jordan Schroter
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ========================================================== */
18
19
20!function ($) {
21
22	"use strict"; // jshint ;_;
23
24	/* MODAL CLASS DEFINITION
25	* ====================== */
26
27	var Modal = function (element, options) {
28		this.init(element, options);
29	};
30
31	Modal.prototype = {
32
33		constructor: Modal,
34
35		init: function (element, options) {
36			var that = this;
37
38			this.options = options;
39
40			this.$element = $(element)
41				.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this));
42
43			this.options.remote && this.$element.find('.modal-body').load(this.options.remote, function () {
44				var e = $.Event('loaded');
45				that.$element.trigger(e);
46			});
47
48			var manager = typeof this.options.manager === 'function' ?
49				this.options.manager.call(this) : this.options.manager;
50
51			manager = manager.appendModal ?
52				manager : $(manager).modalmanager().data('modalmanager');
53
54			manager.appendModal(this);
55		},
56
57		toggle: function () {
58			return this[!this.isShown ? 'show' : 'hide']();
59		},
60
61		show: function () {
62			var e = $.Event('show');
63
64			if (this.isShown) return;
65
66			this.$element.trigger(e);
67
68			if (e.isDefaultPrevented()) return;
69
70			this.escape();
71
72			this.tab();
73
74			this.options.loading && this.loading();
75		},
76
77		hide: function (e) {
78			e && e.preventDefault();
79
80			e = $.Event('hide');
81
82			this.$element.trigger(e);
83
84			if (!this.isShown || e.isDefaultPrevented()) return (this.isShown = false);
85
86			this.isShown = false;
87
88			this.escape();
89
90			this.tab();
91
92			this.isLoading && this.loading();
93
94			$(document).off('focusin.modal');
95
96			this.$element
97				.removeClass('in')
98				.removeClass('animated')
99				.removeClass(this.options.attentionAnimation)
100				.removeClass('modal-overflow')
101				.attr('aria-hidden', true);
102
103			$.support.transition && this.$element.hasClass('fade') ?
104				this.hideWithTransition() :
105				this.hideModal();
106		},
107
108		layout: function () {
109			var prop = this.options.height ? 'height' : 'max-height',
110				value = this.options.height || this.options.maxHeight;
111
112			if (this.options.width){
113				this.$element.css('width', this.options.width);
114
115				var that = this;
116				this.$element.css('margin-left', function () {
117					if (/%/ig.test(that.options.width)){
118						return -(parseInt(that.options.width) / 2) + '%';
119					} else {
120						return -($(this).width() / 2) + 'px';
121					}
122				});
123			} else {
124				this.$element.css('width', '');
125				this.$element.css('margin-left', '');
126			}
127
128			this.$element.find('.modal-body')
129				.css('overflow', '')
130				.css(prop, '');
131
132			if (value){
133				this.$element.find('.modal-body')
134					.css('overflow', 'auto')
135					.css(prop, value);
136			}
137
138			var modalOverflow = $(window).height() - 10 < this.$element.height();
139            
140			if (modalOverflow || this.options.modalOverflow) {
141				this.$element
142					.css('margin-top', 0)
143					.addClass('modal-overflow');
144			} else {
145				this.$element
146					.css('margin-top', 0 - this.$element.height() / 2)
147					.removeClass('modal-overflow');
148			}
149		},
150
151		tab: function () {
152			var that = this;
153
154			if (this.isShown && this.options.consumeTab) {
155				this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
156			    	if (e.keyCode && e.keyCode == 9){
157						var $next = $(this),
158							$rollover = $(this);
159
160						that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) {
161							if (!e.shiftKey){
162						 		$next = $next.data('tabindex') < $(this).data('tabindex') ?
163									$next = $(this) :
164									$rollover = $(this);
165							} else {
166								$next = $next.data('tabindex') > $(this).data('tabindex') ?
167									$next = $(this) :
168									$rollover = $(this);
169							}
170						});
171
172						$next[0] !== $(this)[0] ?
173							$next.focus() : $rollover.focus();
174
175						e.preventDefault();
176					}
177				});
178			} else if (!this.isShown) {
179				this.$element.off('keydown.tabindex.modal');
180			}
181		},
182
183		escape: function () {
184			var that = this;
185			if (this.isShown && this.options.keyboard) {
186				if (!this.$element.attr('tabindex')) this.$element.attr('tabindex', -1);
187
188				this.$element.on('keyup.dismiss.modal', function (e) {
189					e.which == 27 && that.hide();
190				});
191			} else if (!this.isShown) {
192				this.$element.off('keyup.dismiss.modal')
193			}
194		},
195
196		hideWithTransition: function () {
197			var that = this
198				, timeout = setTimeout(function () {
199					that.$element.off($.support.transition.end);
200					that.hideModal();
201				}, 500);
202
203			this.$element.one($.support.transition.end, function () {
204				clearTimeout(timeout);
205				that.hideModal();
206			});
207		},
208
209		hideModal: function () {
210			var prop = this.options.height ? 'height' : 'max-height';
211			var value = this.options.height || this.options.maxHeight;
212
213			if (value){
214				this.$element.find('.modal-body')
215					.css('overflow', '')
216					.css(prop, '');
217			}
218
219			this.$element
220				.hide()
221				.trigger('hidden');
222		},
223
224		removeLoading: function () {
225			this.$loading.remove();
226			this.$loading = null;
227			this.isLoading = false;
228		},
229
230		loading: function (callback) {
231			callback = callback || function () {};
232
233			var animate = this.$element.hasClass('fade') ? 'fade' : '';
234
235			if (!this.isLoading) {
236				var doAnimate = $.support.transition && animate;
237
238				this.$loading = $('<div class="loading-mask ' + animate + '">')
239					.append(this.options.spinner)
240					.appendTo(this.$element);
241
242				if (doAnimate) this.$loading[0].offsetWidth; // force reflow
243
244				this.$loading.addClass('in');
245
246				this.isLoading = true;
247
248				doAnimate ?
249					this.$loading.one($.support.transition.end, callback) :
250					callback();
251
252			} else if (this.isLoading && this.$loading) {
253				this.$loading.removeClass('in');
254
255				var that = this;
256				$.support.transition && this.$element.hasClass('fade')?
257					this.$loading.one($.support.transition.end, function () { that.removeLoading() }) :
258					that.removeLoading();
259
260			} else if (callback) {
261				callback(this.isLoading);
262			}
263		},
264
265		focus: function () {
266			var $focusElem = this.$element.find(this.options.focusOn);
267
268			$focusElem = $focusElem.length ? $focusElem : this.$element;
269
270			$focusElem.focus();
271		},
272
273		attention: function (){
274			// NOTE: transitionEnd with keyframes causes odd behaviour
275
276			if (this.options.attentionAnimation){
277				this.$element
278					.removeClass('animated')
279					.removeClass(this.options.attentionAnimation);
280
281				var that = this;
282
283				setTimeout(function () {
284					that.$element
285						.addClass('animated')
286						.addClass(that.options.attentionAnimation);
287				}, 0);
288			}
289
290
291			this.focus();
292		},
293
294
295		destroy: function () {
296			var e = $.Event('destroy');
297			this.$element.trigger(e);
298			if (e.isDefaultPrevented()) return;
299
300			this.teardown();
301		},
302
303		teardown: function () {
304			if (!this.$parent.length){
305				this.$element.remove();
306				this.$element = null;
307				return;
308			}
309
310			if (this.$parent !== this.$element.parent()){
311				this.$element.appendTo(this.$parent);
312			}
313
314			this.$element.off('.modal');
315			this.$element.removeData('modal');
316			this.$element
317				.removeClass('in')
318				.attr('aria-hidden', true);
319		}
320	};
321
322
323	/* MODAL PLUGIN DEFINITION
324	* ======================= */
325
326	$.fn.modal = function (option, args) {
327		return this.each(function () {
328			var $this = $(this),
329				data = $this.data('modal'),
330				options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option);
331
332			if (!data) $this.data('modal', (data = new Modal(this, options)));
333			if (typeof option == 'string') data[option].apply(data, [].concat(args));
334			else if (options.show) data.show()
335		})
336	};
337
338	$.fn.modal.defaults = {
339		keyboard: true,
340		backdrop: true,
341		loading: false,
342		show: true,
343		width: null,
344		height: null,
345		maxHeight: null,
346		modalOverflow: false,
347		consumeTab: true,
348		focusOn: null,
349		replace: false,
350		resize: false,
351		attentionAnimation: 'shake',
352		manager: 'body',
353		spinner: '<div class="loading-spinner" style="width: 200px; margin-left: -100px;"><div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div></div>',
354		backdropTemplate: '<div class="modal-backdrop" />'
355	};
356
357	$.fn.modal.Constructor = Modal;
358
359
360	/* MODAL DATA-API
361	* ============== */
362
363	$(function () {
364		$(document).off('click.modal').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
365			var $this = $(this),
366				href = $this.attr('href'),
367				$target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7
368				option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data());
369
370			e.preventDefault();
371			$target
372				.modal(option)
373				.one('hide', function () {
374					$this.focus();
375				})
376		});
377	});
378
379}(window.jQuery);

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.