PageSourceSearch

https://lkg.ru/bitrix/templates/aspro_max/js/jqModal.js

js lkg.ru collected 2026-10-08 03:29:14 UTC 10,972 bytes, 348 lines download raw bytes

1/*
2 * jqModal - Minimalist Modaling with jQuery
3 *
4 * Copyright (c) 2007-2014 Brice Burgess @iceburg_net
5 * Dual licensed under the MIT and GPL licenses:
6 *   http://www.opensource.org/licenses/mit-license.php
7 *   http://www.gnu.org/licenses/gpl.html
8 *
9 * $Version: 1.0.2 (2014.04.10 +r19)
10 * Requires: jQuery 1.2.3+
11 */
12
13(function($) {
14
15	/**
16	 * Initialize a set of elements as "modals". Modals typically are popup dialogs,
17	 * notices, modal windows, &c.
18	 *
19	 * @name jqm
20	 * @param options user defined options, augments defaults.
21	 * @type jQuery
22	 * @cat Plugins/jqModal
23	 */
24
25	$.fn.jqm=function(options){
26
27		var o = $.extend({}, $.jqm.params, options);
28
29		return this.each(function(){
30			var e = $(this),
31				jqm = $(this).data('jqm');
32
33			if(!jqm) jqm = {ID: I++};
34
35			// add/extend options to modal and mark as initialized
36			e.data('jqm',$.extend(o,jqm)).addClass('jqm-init');
37
38			// ... Attach events to trigger showing of this modal
39			o.trigger&&$(this).jqmAddTrigger(o.trigger);
40		});
41	};
42
43
44	/**
45	 * Matching modals will have their jqmShow() method fired by attaching a
46	 *   onClick event to elements matching `trigger`.
47	 *
48	 * @name jqmAddTrigger
49	 * @param trigger a selector String, jQuery collection of elements, or a DOM element.
50	 */
51	$.fn.jqmAddTrigger=function(trigger){
52		return this.each(function(){
53			if(!addTrigger($(this), 'jqmShow', trigger))
54				err("jqmAddTrigger must be called on initialized modals")
55		});
56	};
57
58
59	/**
60	 * Matching modals will have their jqmHide() method fired by attaching an
61	 *   onClick event to elements matching `trigger`.
62	 *
63	 * @name jqmAddClose
64	 * @param trigger a selector String, jQuery collection of elements, or a DOM element.
65	 */
66	$.fn.jqmAddClose=function(trigger){
67		return this.each(function(){
68			if(!addTrigger($(this), 'jqmHide', trigger))
69				err("jqmAddClose must be called on initialized modals")
70		});
71	};
72
73
74	/**
75	 * Open matching modals (if not shown)
76	 */
77	$.fn.jqmShow=function(trigger){
78		return this.each(function(){ !this._jqmShown&&show($(this), trigger); });
79	};
80
81	/**
82	 * Close matching modals
83	 */
84	$.fn.jqmHide=function(trigger){
85		return this.each(function(){ this._jqmShown&&hide($(this), trigger); });
86	};
87
88
89	// utility functions
90
91	var
92		err = function(msg){
93			if(window.console && window.console.error) window.console.error(msg);
94
95
96	}, show = function(e, t){
97		/**
98		 * e = modal element (as jQuery object)
99		 * t = triggering element
100		 *
101		 * o = options
102		 * z = z-index of modal
103		 * v = overlay element (as jQuery object)
104		 * h = hash (for jqModal <= r15 compatibility)
105		 */
106
107		var o = e.data('jqm'),
108			t = t || window.event,
109			z = (parseInt(e.css('z-index'))),
110			z = (z > 0) ? z : 3000;
111
112		if(o.noOverlay === undefined || (o.noOverlay !== undefined && !o.noOverlay) ) {
113			var	v = $('<div></div>').addClass(o.overlayClass).css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:o.overlay/100});
114		} else {
115			var	v = $('');
116		}
117		
118			// maintain legacy "hash" construct
119			h = {w: e, c: o, o: v, t: t};
120
121		e.css('z-index',z);
122
123		if(o.ajax){
124			var target = o.target || e,
125				url = o.ajax;
126
127			target = (typeof target == 'string') ? $(target,e) : $(target);
128			if(url.substr(0,1) == '@') url = $(t).attr(url.substring(1));
129
130			 // Load the Ajax Content (and once loaded);
131			   // Fire the onLoad callback (if exists),
132			   // Attach closing events to elements inside the modal that match the closingClass,
133			   // and Execute the jqModal default Open Callback
134			target.html(o.ajaxText).load(url,function(){
135				o.onLoad && o.onLoad.call(this,h);
136				open(h);
137			});
138		}
139		else { open(h); }
140
141	}, hide = function(e, t){
142		/**
143		 * e = modal element (as jQuery object)
144		 * t = triggering element
145		 *
146		 * o = options
147		 * h = hash (for jqModal <= r15 compatibility)
148		 */
149
150		var o = e.data('jqm'),
151			t = t || window.event,
152
153		// maintain legacy "hash" construct
154		h = {w: e, c: o, o: e.data('jqmv'), t: t};
155
156		close(h);
157
158	}, onShow = function(hash){
159		// onShow callback. Responsible for showing a modal and overlay.
160		//  return false to stop opening modal.
161
162		// hash object;
163	    //  w: (jQuery object) The modal element
164	    //  c: (object) The modal's options object
165	    //  o: (jQuery object) The overlay element
166	    //  t: (DOM object) The triggering element
167
168		// display the overlay (prepend to body) if not disabled
169
170		// prevent double click
171		if( hash.w[0]._jqmShown )
172			return false;
173		
174		if(hash.c.overlay > 0)
175			hash.o.prependTo('#popup_iframe_wrapper');
176
177		// make modal visible
178		hash.w.show();
179
180		// call focusFunc (attempts to focus on first input in modal)
181		$.jqm.focusFunc(hash.w);
182
183		return true;
184
185
186	}, onHide = function(hash){
187		// onHide callback. Responsible for hiding a modal and overlay.
188		//  return false to stop closing modal.
189
190		// hash object;
191	    //  w: (jQuery object) The modal element
192	    //  c: (object) The modal's options object
193	    //  o: (jQuery object) The overlay element
194	    //  t: (DOM object) The triggering element
195
196		// hide modal and if overlay, remove overlay.
197		hash.w.hide() && hash.o && hash.o.remove();
198
199		return true;
200
201
202	},  addTrigger = function(e, key, trigger){
203		// addTrigger: Adds a jqmShow or jqmHide (key) for a modal (e)
204		//  all elements that match trigger string (trigger)\
205
206		// return false if e is not an initialized modal element
207		if(!e.data('jqm')) return false;
208
209		return $(trigger).each(function(){
210			// register modal to trigger elements
211			this[key] = this[key] || [];
212			this[key].push(e);
213
214		}).click(function(){
215
216			var trigger = this;
217
218			// foreadh modal registered to this trigger, call jqmShow ||
219			//   jqmHide (key) on modal passing trigger element (e)
220			$.each(this[key], function(i, e){ e[key](trigger); });
221
222			// stop trigger click event from bubbling
223			return false;
224		});
225
226
227	},  open = function(h){
228		// open: executes the onOpen callback + performs common tasks if successful
229
230		// transform legacy hash into new var shortcuts
231		 var e = h.w,
232		 	v = h.o,
233		 	o = h.c;
234
235		// execute onShow callback
236		if(o.onShow(h) !== false){
237			// mark modal as shown
238			e[0]._jqmShown = true;
239
240			// if modal dialog
241			//
242			// Bind the Keep Focus Function [F] if no other Modals are open (!A[0]) +
243			// Add this modal to the opened modals stack (A) for nested modal support
244			//
245			// else, close dialog when overlay is clicked
246			if(o.modal){ !A[0]&&F('bind'); A.push(e); }
247            else e.jqmAddClose(v);
248
249			//  Attach closing events to elements inside the modal that match the closingClass
250			o.closeClass&&e.jqmAddClose($('.' + o.closeClass,e));
251
252			// IF toTop is true and overlay exists;
253			//  Add placeholder element <span id="jqmP#ID_of_modal"/> before modal to
254			//  remember it's position in the DOM and move it to a child of the body tag (after overlay)
255			o.toTop&&v&&e.before('<span id="jqmP'+o.ID+'"></span>').insertAfter(v);
256
257			// remember overlay (for closing function)
258			e.data('jqmv',v);
259		}
260
261
262	},  close = function(h){
263		// close: executes the onHide callback + performs common tasks if successful
264
265		// transform legacy hash into new var shortcuts
266		 var e = h.w,
267		 	v = h.o,
268		 	o = h.c;
269
270		// execute onShow callback
271		if(o.onHide(h) !== false){
272			// mark modal as !shown
273			e[0]._jqmShown = false;
274
275			 // If modal, remove from modal stack.
276			 // If no modals in modal stack, unbind the Keep Focus Function
277			 if(o.modal){A.pop();!A[0]&&F('unbind');}
278
279			 // IF toTop was passed and an overlay exists;
280			 //  Move modal back to its "remembered" position.
281			 o.toTop&&v&&$('#jqmP'+o.ID).after(e).remove();
282		}
283
284
285	},  F = function(t){
286		// F: The Keep Focus Function (for modal: true dialos)
287		// Binds or Unbinds (t) the Focus Examination Function (X) to keypresses and clicks
288
289		$(document)[t]("keypress keydown mousedown",X);
290
291
292	}, X = function(e){
293		// X: The Focus Examination Function (for modal: true dialogs)
294
295		var modal = $(e.target).data('jqm') || $(e.target).parents('.jqm-init:first').data('jqm'),
296			activeModal = A[A.length-1].data('jqm');
297
298		// allow bubbling if event target is within active modal dialog
299		if(modal && modal.ID == activeModal.ID) return true;
300
301		// else, trigger focusFunc (focus on first input element and halt bubbling)
302		return $.jqm.focusFunc(activeModal);
303	},
304
305	I = 0,   // modal ID increment (for nested modals)
306	A = [];  // array of active modals (used to lock interactivity to appropriate modal)
307
308
309	// $.jqm, overridable defaults
310	$.jqm = {
311		/**
312		 *  default options
313		 *
314		 * (Integer)   overlay      - [0-100] Translucency percentage (opacity) of the body covering overlay. Set to 0 for NO overlay, and up to 100 for a 100% opaque overlay.
315		 * (String)    overlayClass - Applied to the body covering overlay. Useful for controlling overlay look (tint, background-image, &c) with CSS.
316		 * (String)    closeClass   - Children of the modal element matching `closeClass` will fire the onHide event (to close the modal).
317		 * (Mixed)     trigger      - Matching elements will fire the onShow event (to display the modal). Trigger can be a selector String, a jQuery collection of elements, a DOM element, or a False boolean.
318		 * (String)    ajax         - URL to load content from via an AJAX request. False to disable ajax. If ajax begins with a "@", the URL is extracted from the attribute of the triggering element (e.g. use '@data-url' for; <a href="#" class="jqModal" data-url="modal.html">...)
319		 * (Mixed)     target       - Children of the modal element to load the aja
319x response into. If false, modal content will be overwritten by ajax response. Useful for retaining modal design.
320		 *                            Target may be a selector string, jQuery collection of elements, or a DOM element -- and MUST exist as a child of the modal element.
321		 * (String)    ajaxText     - Text shown while waiting for ajax return. Replaces HTML content of `target` element.
322		 * (Boolean)   modal        - If true, user interactivity will be locked to the modal window until closed.
323		 * (Boolean)   toTop        - If true, modal will be posistioned as a first child of the BODY element when opened, and its DOM posistion restored when closed. Useful for overcoming z-Index container issues.
324		 * (Function)  onShow       - User defined callback function fired when modal opened.
325		 * (Function)  onHide       - User defined callback function fired when modal closed.
326		 * (Function)  onLoad       - User defined callback function fired when ajax content loads.
327		 */
328		params: {
329			overlay: 50,
330			overlayClass: 'jqmOverlay',
331			closeClass: 'jqmClose',
332			trigger: '.jqModal',
333			ajax: false,
334			target: false,
335			ajaxText: '',
336			modal: false,
337			toTop: false,
338			onShow: onShow,
339			onHide: onHide,
340			onLoad: false
341		},
342
343		// focusFunc is fired when a modal is shown, or when interaction occurs outside
344		// a modal enabled dialog. Passed the modal element.
345		focusFunc: function(e) { $(':input:visible:first',e).focus(); return false; }
346	};
347
348})( 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.