PageSourceSearch

https://mida.org.il/wp-content/themes/faster/assets/jPanelMenu-1.2.0/jquery.jpanelmenu.js

js mida.org.il collected 2026-10-02 05:40:52 UTC 15,828 bytes, 544 lines download raw bytes

1/**
2  *
3  * jPanelMenu 1.2.0 (http://jpanelmenu.com)
4  * By Anthony Colangelo (http://acolangelo.com)
5  *
6* */
7
8(function($){
9	$.jPanelMenu = function(options) {
10		if ( typeof(options) == "undefined" || options == null ) { options = {}; };
11
12		var jP = {
13			options: $.extend({
14				menu: '#menu',
15				trigger: '.menu-trigger',
16				excludedPanelContent: 'style, script',
17
18				direction: 'left',
19				openPosition: '250px',
20				animated
vendor: 12,343 bytes, lines 20-437
20: true,
21
22				keyboardShortcuts: [
23					{
24						code: 27,
25						open: false,
26						close: true 
27					},
28					{
29						code: 37,
30						open: false,
31						close: true 
32					},
33					{
34						code: 39,
35						open: true,
36						close: true 
37					},
38					{
39						code: 77,
40						open: true,
41						close: true 
42					}
43				],
44
45				duration: 150,
46				openDuration: options.duration || 150,
47				closeDuration: options.duration || 150,
48
49				easing: 'ease-in-out',
50				openEasing: options.easing || 'ease-in-out',
51				closeEasing: options.easing || 'ease-in-out',
52
53				before: function(){ },
54				beforeOpen: function(){ },
55				beforeClose: function(){ },
56
57				after: function(){ },
58				afterOpen: function(){ },
59				afterClose: function(){ },
60
61				beforeOn: function(){ },
62				afterOn: function(){ },
63
64				beforeOff: function(){ },
65				afterOff: function(){ }
66			},options),
67
68			settings: {
69				transitionsSupported:	'WebkitTransition' in document.body.style ||
70										'MozTransition' in document.body.style ||
71										'msTransition' in document.body.style ||
72										'OTransition' in document.body.style ||
73										'Transition' in document.body.style
74				,
75				shiftFixedChildren: false,
76				panelPosition: 'relative',
77				positionUnits: 'px'
78			},
79
80			menu: '#jPanelMenu-menu',
81
82			panel: '.jPanelMenu-panel',
83
84			fixedChildren: [],
85
86			timeouts: {},
87
88			clearTimeouts: function() {
89				clearTimeout(jP.timeouts.open);
90				clearTimeout(jP.timeouts.afterOpen);
91				clearTimeout(jP.timeouts.afterClose);
92			},
93
94			setPositionUnits: function() {
95				var foundUnit = false,
96					allowedUnits = ['%','px','em']
97				;
98
99				for ( unitID in allowedUnits ) {
100					var unit = allowedUnits[unitID];
101					if ( jP.options.openPosition.toString().substr(-unit.length) == unit )
102					{
103						foundUnit = true;
104						jP.settings.positionUnits = unit;
105					}
106				}
107
108				if ( !foundUnit ) { jP.options.openPosition = parseInt(jP.options.openPosition) + jP.settings.positionUnits }
109			},
110
111			checkFixedChildren: function() {
112				jP.disableTransitions();
113
114				var defaultPanelStyle = { position: $(jP.panel).css('position') };
115
116				defaultPanelStyle[jP.options.direction] = ($(jP.panel).css(jP.options.direction) == 'auto')?0:$(jP.panel).css(jP.options.direction);
117
118				$(jP.panel).find('> *').each(function(){
119					if ( $(this).css('position') == 'fixed' && $(this).css(jP.options.direction) == 'auto' ) { jP.fixedChildren.push(this); }
120				});
121				
122				if ( jP.fixedChildren.length > 0 )
123				{
124					var newPanelStyle = { position: 'relative' };
125					newPanelStyle[jP.options.direction] = '1px';
126					jP.setPanelStyle(newPanelStyle);
127
128					if ( parseInt($(jP.fixedChildren[0]).offset().left) == 0 ) { jP.settings.shiftFixedChildren = true; }
129				}
130
131				jP.setPanelStyle(defaultPanelStyle);
132			},
133
134			setjPanelMenuStyles: function() {
135				var bgColor = '#fff';
136				var htmlBG = $('html').css('background-color');
137				var bodyBG = $('body').css('background-color');
138
139				if ( bodyBG != 'transparent' && bodyBG != "rgba(0, 0, 0, 0)") { bgColor = bodyBG; }
140				else if ( htmlBG != 'transparent' && htmlBG != "rgba(0, 0, 0, 0)") { bgColor = htmlBG; }
141				else { bgColor = '#fff'; }
142
143				if ( $('#jPanelMenu-style-master').length == 0 )
144				{
145					$('body').append('<style id="jPanelMenu-style-master">body{width:100%}.jPanelMenu,body{overflow-x:hidden}#jPanelMenu-menu{display:block;position:fixed;top:0;'+jP.options.direction+':0;height:100%;z-index:-1;overflow-x:hidden;overflow-y:scroll;-webkit-overflow-scrolling:touch}.jPanelMenu-panel{position:static;'+jP.options.direction+':0;top:0;z-index:2;width:100%;min-height:100%;background:' + bgColor + '}</style>');
146				}
147			},
148
149			setMenuState: function(open) {
150				var position = (open)?'open':'closed';
151				$('body').attr('data-menu-position', position);
152			},
153
154			getMenuState: function() {
155				return $('body').attr('data-menu-position');
156			},
157
158			menuIsOpen: function() {
159				if ( jP.getMenuState() == 'open' ) return true;
160				else return false;
161			},
162
163			setMenuStyle: function(styles) {
164				$(jP.menu).css(styles);
165			},
166
167			setPanelStyle: function(styles) {
168				$(jP.panel).css(styles);
169			},
170
171			showMenu: function() {
172				jP.setMenuStyle({
173					display: 'block'
174				});
175				jP.setMenuStyle({
176					'z-index': '1'
177				});
178			},
179
180			hideMenu: function() {
181				jP.setMenuStyle({
182					'z-index': '-1'
183				});
184				jP.setMenuStyle({
185					display: 'none'
186				});
187			},
188
189			enableTransitions: function(duration, easing) {
190				var formattedDuration = duration/1000;
191				var formattedEasing = jP.getCSSEasingFunction(easing);
192				jP.disableTransitions();
193				$('body').append('<style id="jPanelMenu-style-transitions">.jPanelMenu-panel{-webkit-transition: all ' + formattedDuration + 's ' + formattedEasing + '; -moz-transition: all ' + formattedDuration + 's ' + formattedEasing + '; -o-transition: all ' + formattedDuration + 's ' + formattedEasing + '; transition: all ' + formattedDuration + 's ' + formattedEasing + ';}</style>');
194			},
195
196			disableTransitions: function() {
197				$('#jPanelMenu-style-transitions').remove();
198			},
199
200			enableFixedTransitions: function(selector, id, duration, easing) {
201				var formattedDuration = duration/1000;
202				var formattedEasing = jP.getCSSEasingFunction(easing);
203				jP.disableFixedTransitions(id);
204				$('body').append('<style id="jPanelMenu-style-fixed-' + id + '">' + selector + '{-webkit-transition: all ' + formattedDuration + 's ' + formattedEasing + '; -moz-transition: all ' + formattedDuration + 's ' + formattedEasing + '; -o-transition: all ' + formattedDuration + 's ' + formattedEasing + '; transition: all ' + formattedDuration + 's ' + formattedEasing + ';}</style>');
205			},
206
207			disableFixedTransitions: function(id) {
208				$('#jPanelMenu-style-fixed-' + id).remove();
209			},
210
211			getCSSEasingFunction: function(name) {
212				switch ( name )
213				{
214					case 'linear':
215						return name;
216						break;
217
218					case 'ease':
219						return name;
220						break;
221
222					case 'ease-in':
223						return name;
224						break;
225
226					case 'ease-out':
227						return name;
228						break;
229
230					case 'ease-in-out':
231						return name;
232						break;
233
234					default:
235						return 'ease-in-out';
236						break;
237				}
238			},
239
240			getJSEasingFunction: function(name) {
241				switch ( name )
242				{
243					case 'linear':
244						return name;
245						break;
246
247					default:
248						return 'swing';
249						break;
250				}
251			},
252
253			openMenu: function(animated) {
254				if ( typeof(animated) == "undefined" || animated == null ) { animated = jP.options.animated };
255				
256				jP.clearTimeouts();
257
258				jP.options.before();
259				jP.options.beforeOpen();
260
261				jP.setMenuState(true);
262
263				jP.setPanelStyle({ position: 'relative' });
264				
265				jP.showMenu();
266
267				var animationChecks = {
268					none: (!animated)?true:false,
269					transitions: (animated && jP.settings.transitionsSupported)?true:false
270				};
271
272				if ( animationChecks.transitions || animationChecks.none ) {
273					if ( animationChecks.none ) jP.disableTransitions();
274					if ( animationChecks.transitions ) jP.enableTransitions(jP.options.openDuration, jP.options.openEasing);
275
276					var newPanelStyle = {};
277					newPanelStyle[jP.options.direction] = jP.options.openPosition;
278					jP.setPanelStyle(newPanelStyle);
279
280					if ( jP.settings.shiftFixedChildren )
281					{
282						$(jP.fixedChildren).each(function(){
283							var id = $(this).prop("tagName").toLowerCase() + ' ' + $(this).attr('class'),
284								selector = id.replace(' ','.'),
285								id = id.replace(' ','-')
286							;
287
288							if ( animationChecks.none ) jP.disableFixedTransitions(id);
289							if ( animationChecks.transitions ) jP.enableFixedTransitions(selector, id, jP.options.openDuration, jP.options.openEasing);
290
291							var newChildrenStyle = {};
292							newChildrenStyle[jP.options.direction] = jP.options.openPosition;
293							$(this).css(newChildrenStyle);
294						});
295					}
296
297					jP.timeouts.afterOpen = setTimeout(function(){
298						jP.disableTransitions();
299						if ( jP.settings.shiftFixedChildren )
300						{
301							$(jP.fixedChildren).each(function(){
302								var id = $(this).prop("tagName").toLowerCase() + ' ' + $(this).attr('class'),
303									id = id.replace(' ','-')
304								;
305
306								jP.disableFixedTransitions(id);
307							});
308						}
309
310						jP.options.after();
311						jP.options.afterOpen();
312						jP.initiateContentClickListeners();
313					}, jP.options.openDuration);
314				}
315				else {
316					var formattedEasing = jP.getJSEasingFunction(jP.options.openEasing);
317
318					var animationOptions = {};
319					animationOptions[jP.options.direction] = jP.options.openPosition;
320					$(jP.panel).stop().animate(animationOptions, jP.options.openDuration, formattedEasing, function(){
321						jP.options.after();
322						jP.options.afterOpen();
323						jP.initiateContentClickListeners();
324					});
325
326					if ( jP.settings.shiftFixedChildren )
327					{
328						$(jP.fixedChildren).each(function(){
329							var childrenAnimationOptions = {};
330							childrenAnimationOptions[jP.options.direction] = jP.options.openPosition;
331							$(this).stop().animate(childrenAnimationOptions, jP.options.openDuration, formattedEasing);
332						});
333					}
334				}
335			},
336
337			closeMenu: function(animated) {
338				if ( typeof(animated) == "undefined" || animated == null ) { animated = jP.options.animated };
339
340				jP.clearTimeouts();
341
342				jP.options.before();
343				jP.options.beforeClose();
344
345				jP.setMenuState(false);
346
347				var animationChecks = {
348					none: (!animated)?true:false,
349					transitions: (animated && jP.settings.transitionsSupported)?true:false
350				};
351
352				if ( animationChecks.transitions || animationChecks.none ) {
353					if ( animationChecks.none ) jP.disableTransitions();
354					if ( animationChecks.transitions ) jP.enableTransitions(jP.options.closeDuration, jP.options.closeEasing);
355
356					var newPanelStyle = {};
357					newPanelStyle[jP.options.direction] = 0 + jP.settings.positionUnits;
358					jP.setPanelStyle(newPanelStyle);
359
360					if ( jP.settings.shiftFixedChildren )
361					{
362						$(jP.fixedChildren).each(function(){
363							var id = $(this).prop("tagName").toLowerCase() + ' ' + $(this).attr('class'),
364								selector = id.replace(' ','.'),
365								id = id.replace(' ','-')
366							;
367
368							if ( animationChecks.none ) jP.disableFixedTransitions(id);
369							if ( animationChecks.transitions ) jP.enableFixedTransitions(selector, id, jP.options.closeDuration, jP.options.closeEasing);
370
371							var newChildrenStyle = {};
372							newChildrenStyle[jP.options.direction] = 0 + jP.settings.positionUnits;
373							$(this).css(newChildrenStyle);
374						});
375					}
376
377					jP.timeouts.afterClose = setTimeout(function(){
378						jP.setPanelStyle({ position: jP.settings.panelPosition });
379
380						jP.disableTransitions();
381						if ( jP.settings.shiftFixedChildren )
382						{
383							$(jP.fixedChildren).each(function(){
384								var id = $(this).prop("tagName").toLowerCase() + ' ' + $(this).attr('class'),
385									id = id.replace(' ','-')
386								;
387
388								jP.disableFixedTransitions(id);
389							});
390						}
391
392						jP.hideMenu();
393						jP.options.after();
394						jP.options.afterClose();
395						jP.destroyContentClickListeners();
396					}, jP.options.closeDuration);
397				}
398				else {
399					var formattedEasing = jP.getJSEasingFunction(jP.options.closeEasing);
400
401					var animationOptions = {};
402					animationOptions[jP.options.direction] = 0 + jP.settings.positionUnits;
403					$(jP.panel).stop().animate(animationOptions, jP.options.closeDuration, formattedEasing, function(){
404						jP.setPanelStyle({ position: jP.settings.panelPosition });
405
406						jP.hideMenu();
407						jP.options.after();
408						jP.options.afterClose();
409						jP.destroyContentClickListeners();
410					});
411
412					if ( jP.settings.shiftFixedChildren )
413					{
414						$(jP.fixedChildren).each(function(){
415							var childrenAnimationOptions = {};
416							childrenAnimationOptions[jP.options.direction] = 0 + jP.settings.positionUnits;
417							$(this).stop().animate(childrenAnimationOptions, jP.options.closeDuration, formattedEasing);
418						});
419					}
420				}
421			},
422
423			triggerMenu: function(animated) {
424				if ( jP.menuIsOpen() ) jP.closeMenu(animated);
425				else jP.openMenu(animated);
426			},
427
428			initiateClickListeners: function() {
429				$(document).on('click',jP.options.trigger,function(){ jP.triggerMenu(jP.options.animated); return false; });
430			},
431
432			destroyClickListeners: function() {
433				$(document).off('click',jP.options.trigger,null);
434			},
435
436			initiateContentClickListeners: function() {
437				
vendor: 3,053 bytes, lines 437-544
437$(document).on('click',jP.panel,function(e){
438					if ( jP.menuIsOpen() ) jP.closeMenu(jP.options.animated);
439				});
440				
441				$(document).on('touchend',jP.panel,function(e){
442					if ( jP.menuIsOpen() ) jP.closeMenu(jP.options.animated);
443				});
444			},
445
446			destroyContentClickListeners: function() {
447				$(document).off('click',jP.panel,null);
448				$(document).off('touchend',jP.panel,null);
449			},
450
451			initiateKeyboardListeners: function() {
452				var preventKeyListeners = ['input', 'textarea'];
453				$(document).on('keydown',function(e){
454					var target = $(e.target),
455					prevent = false;
456					$.each(preventKeyListeners, function(){
457						if (target.is(this.toString())) { prevent = true; }
458					});
459					if ( prevent ) { return true; }
460
461					for ( mapping in jP.options.keyboardShortcuts ) {
462						if ( e.which == jP.options.keyboardShortcuts[mapping].code )
463						{
464							var key = jP.options.keyboardShortcuts[mapping];
465
466							if ( key.open && key.close ) { jP.triggerMenu(jP.options.animated); }
467							else if ( (key.open && !key.close) && !jP.menuIsOpen() ) { jP.openMenu(jP.options.animated); }
468							else if ( (!key.open && key.close) && jP.menuIsOpen() ) { jP.closeMenu(jP.options.animated); }
469
470							return false;
471						}
472					}
473				});
474			},
475
476			destroyKeyboardListeners: function() {
477				$(document).off('keydown',null);
478			},
479
480			setupMarkup: function() {
481				$('html').addClass('jPanelMenu');
482				$('body > *').not(jP.menu + ', ' + jP.options.excludedPanelContent).wrapAll('<div class="' + jP.panel.replace('.','') + '"/>');
483				$(jP.options.menu).clone().attr('id', jP.menu.replace('#','')).insertAfter('body > ' + jP.panel);
484			},
485
486			resetMarkup: function() {
487				$('html').removeClass('jPanelMenu');
488				$('body > ' + jP.panel + ' > *').unwrap();
489				$(jP.menu).remove();
490			},
491
492			init: function() {
493				jP.options.beforeOn();
494
495				jP.initiateClickListeners();
496				if ( Object.prototype.toString.call(jP.options.keyboardShortcuts) === '[object Array]' ) { jP.initiateKeyboardListeners(); }
497
498				jP.setjPanelMenuStyles();
499				jP.setMenuState(false);
500				jP.setupMarkup();
501
502				jP.setMenuStyle({
503					width: jP.options.openPosition
504				});
505
506				jP.checkFixedChildren();
507				jP.setPositionUnits();
508
509				jP.closeMenu(false);
510
511				jP.options.afterOn();
512			},
513
514			destroy: function() {
515				jP.options.beforeOff();
516
517				jP.closeMenu();
518				jP.destroyClickListeners();
519				if ( Object.prototype.toString.call(jP.options.keyboardShortcuts) === '[object Array]' ) { jP.destroyKeyboardListeners(); }
520
521				jP.resetMarkup();
522				var childrenStyles = {};
523				childrenStyles[jP.options.direction] = 'auto';
524				$(jP.fixedChildren).each(function(){ $(this).css(childrenStyles); });
525				jP.fixedChildren = [];
526
527				jP.options.afterOff();
528			}
529		};
530
531		return {
532			on: jP.init,
533			off: jP.destroy,
534			trigger: jP.triggerMenu,
535			open: jP.openMenu,
536			close: jP.closeMenu,
537			isOpen: jP.menuIsOpen,
538			menu: jP.menu,
539			getMenu: function() { return $(jP.menu); },
540			panel: jP.panel,
541			getPanel: function() { return $(jP.panel); }
542		};
543	};
544})(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.