PageSourceSearch

https://senfeng.ru/bitrix/templates/aspro_max/js/jqModal.js?176466256411783

js senfeng.ru collected 2026-10-08 16:32:44 UTC 11,783 bytes, 366 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
111			if(o.noOverlay === undefined || (o.noOverlay !== undefined && !o.noOverlay) ) {
112				if( isNaN(z) ) {
113					if( window['lastJqmZindex'] ) {
114						window['lastJqmZindex'] = z = window['lastJqmZindex'] + 2;
115					} else {
116						z = 3000;
117					}
118				}
119				window['lastJqmZindex'] = z;
120				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});
121				e.css('z-index',z);
122			} else {
123				var	v = $('');
124				e.css('z-index',2999);
125			}
126		
127			// maintain legacy "hash" construct
128			h = {w: e, c: o, o: v, t: t};
129
130
131		if(o.ajax){
132			var target = o.target || e,
133				url = o.ajax;
134
135			target = (typeof target == 'string') ? $(target,e) : $(target);
136			if(url.substr(0,1) == '@') url = $(t).attr(url.substring(1));
137                        
138                        var currentPath = window.location.pathname + window.location.search + window.location.hash;
139                        var separator = (url.indexOf('?') > -1) ? '&' : '?';
140                        url += separator + 'CURRENT_URL=' + encodeURIComponent(currentPath);
141
142			 // Load the Ajax Content (and once loaded);
143			   // Fire the onLoad callback (if exists),
144			   // Attach closing events to elements inside the modal that match the closingClass,
145			   // and Execute the jqModal default Open Callback
146                           console.log('===');
147                           console.log(url);
148                           console.log(window.location.pathname);
149                           console.log(this);
150                           console.log(h);
151                           console.log('===');
152			target.html(o.ajaxText).load(url,function(){
153				o.onLoad && o.onLoad.call(this,h);
154				open(h);
155			});
156		}
157		else { open(h); }
158
159	}, hide = function(e, t){
160		/**
161		 * e = modal element (as jQuery object)
162		 * t = triggering element
163		 *
164		 * o = options
165		 * h = hash (for jqModal <= r15 compatibility)
166		 */
167
168		var o = e.data('jqm'),
169			t = t || window.event,
170
171		// maintain legacy "hash" construct
172		h = {w: e, c: o, o: e.data('jqmv'), t: t};
173
174		close(h);
175
176	}, onShow = function(hash){
177		// onShow callback. Responsible for showing a modal and overlay.
178		//  return false to stop opening modal.
179
180		// hash object;
181	    //  w: (jQuery object) The modal element
182	    //  c: (object) The modal's options object
183	    //  o: (jQuery object) The overlay element
184	    //  t: (DOM object) The triggering element
185
186		// display the overlay (prepend to body) if not disabled
187
188		// prevent double click
189		if( hash.w[0]._jqmShown )
190			return false;
191		
192		if(hash.c.overlay > 0)
193			hash.o.prependTo('#popup_iframe_wrapper');
194
195		// make modal visible
196		hash.w.show();
197
198		// call focusFunc (attempts to focus on first input in modal)
199		$.jqm.focusFunc(hash.w);
200
201		return true;
202
203
204	}, onHide = function(hash){
205		// onHide callback. Responsible for hiding a modal and overlay.
206		//  return false to stop closing modal.
207
208		// hash object;
209	    //  w: (jQuery object) The modal element
210	    //  c: (object) The modal's options object
211	    //  o: (jQuery object) The overlay element
212	    //  t: (DOM object) The triggering element
213
214		// hide modal and if overlay, remove overlay.
215		hash.w.hide() && hash.o && hash.o.remove();
216
217		return true;
218
219
220	},  addTrigger = function(e, key, trigger){
221		// addTrigger: Adds a jqmShow or jqmHide (key) for a modal (e)
222		//  all elements that match trigger string (trigger)\
223
224		// return false if e is not an initialized modal element
225		if(!e.data('jqm')) return false;
226
227		return $(trigger).each(function(){
228			// register modal to trigger elements
229			this[key] = this[key] || [];
230			this[key].push(e);
231
232		}).click(function(){
233
234			var trigger = this;
235
236			// foreadh modal registered to this trigger, call jqmShow ||
237			//   jqmHide (key) on modal passing trigger element (e)
238			$.each(this[key], function(i, e){ e[key](trigger); });
239
240			// stop trigger click event from bubbling
241			return false;
242		});
243
244
245	},  open = function(h){
246		// open: executes the onOpen callback + performs common tasks if successful
247
248		// transform legacy hash into new var shortcuts
249		 var e = h.w,
250		 	v = h.o,
251		 	o = h.c;
252
253		// execute onShow callback
254		if(o.onShow(h) !== false){
255			// mark modal as shown
256			e[0]._jqmShown = true;
257
258			// if modal dialog
259			//
260			// Bind the Keep Focus Function [F] if no other Modals are open (!A[0]) +
261			// Add this modal to the opened modals stack (A) for nested modal support
262			//
263			// else, close dialog when overlay is clicked
264			if(o.modal){ !A[0]&&F('bind'); A.push(e); }
265            else e.jqmAddClose(v);
266
267			//  Attach closing events to elements inside the modal that match the closingClass
268			o.closeClass&&e.jqmAddClose($('.' + o.closeClass,e));
269
270			// IF toTop is true and overlay exists;
271			//  Add placeholder element <span id="jqmP#ID_of_modal"/> before modal to
272			//  remember it's position in the DOM and move it to a child of the body tag (after overlay)
273			o.toTop&&v&&e.before('<span id="jqmP'+o.ID+'"></span>').insertAfter(v);
274
275			// remember overlay (for closing function)
276			e.data('jqmv',v);
277		}
278
279
280	},  close = function(h){
281		// close: executes the onHide callback + performs common tasks if successful
282
283		// transform legacy hash into new var shortcuts
284		 var e = h.w,
285		 	v = h.o,
286		 	o = h.c;
287
288		// execute onShow callback
289		if(o.onHide(h) !== false){
290			// mark modal as !shown
291			e[0]._jqmShown = false;
292
293			 // If modal, remove from modal stack.
294			 // If no modals in modal stack, unbind the Keep Focus Function
295			 if(o.modal){A.pop();!A[0]&&F('unbind');}
296
297			 // IF toTop was passed and an overlay exists;
298			 //  Move modal back to its "remembered" position.
299			 o.toTop&&v&&$('#jqmP'+o.ID).after(e).remove();
300		}
301
302
303	},  F = function(t){
304		// F: The Keep Focus Function (for modal: true dialos)
305		// Binds or Unbinds (t) the Focus Examination Function (X) to keypresses and clicks
306
307		$(document)[t]("keypress keydown mousedown",X);
308
309
310	}, X = function(e){
311		// X: The Focus Examination Function (for modal: true dialogs)
312
313		var modal = $(e.target).data('jqm') || $(e.target).parents('.jqm-init:first').data('jqm'),
314			activeModal = A[A.length-1].data('jqm');
315
316		// allow bubbling if event target is within active modal dialog
317		if(modal && modal.ID == activeModal.ID) return true;
318
319		// else, trigger focusFunc (focus on first input element and halt bubbling)
320		return $.jqm.focusFunc(activeModal);
321	},
322
323	I = 0,   // modal ID increment (for nested modals)
324	A = [];  // array of active modals (used to lock interactivity to appropriate modal)
325
326
327	// $.jqm, overridable defaults
328	$.jqm = {
329		/**
330		 *  default options
331		 *
332		 * (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.
333		 * (String)    overlayClass - Applied to the body covering overlay. Useful for controlling overlay look (tint, background-image, &c) with CSS.
334		 * (String)    closeClass   - Children of the modal element matching `closeClass` will fire the onHide event (to close the modal).
335		 * (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.
336		 * (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">...)
337		 * (Mixed)     target       - Children of the modal element to load the aja
337x response into. If false, modal content will be overwritten by ajax response. Useful for retaining modal design.
338		 *                            Target may be a selector string, jQuery collection of elements, or a DOM element -- and MUST exist as a child of the modal element.
339		 * (String)    ajaxText     - Text shown while waiting for ajax return. Replaces HTML content of `target` element.
340		 * (Boolean)   modal        - If true, user interactivity will be locked to the modal window until closed.
341		 * (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.
342		 * (Function)  onShow       - User defined callback function fired when modal opened.
343		 * (Function)  onHide       - User defined callback function fired when modal closed.
344		 * (Function)  onLoad       - User defined callback function fired when ajax content loads.
345		 */
346		params: {
347			overlay: 50,
348			overlayClass: 'jqmOverlay',
349			closeClass: 'jqmClose',
350			trigger: '.jqModal',
351			ajax: false,
352			target: false,
353			ajaxText: '',
354			modal: false,
355			toTop: false,
356			onShow: onShow,
357			onHide: onHide,
358			onLoad: false
359		},
360
361		// focusFunc is fired when a modal is shown, or when interaction occurs outside
362		// a modal enabled dialog. Passed the modal element.
363		focusFunc: function(e) { $(':input:visible:first',e).focus(); return false; }
364	};
365
366})( 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.