PageSourceSearch

https://www.ciie.org/resource/static/zbh/default/assets-2019/plugin/infinitypush/jquery.ma.infinitypush.js

js ciie.org collected 2026-10-02 03:06:34 UTC 15,681 bytes, 552 lines download raw bytes

1/*!
2Off Canvas Infinity Push, a infinity push mobile navigation jQuery plugin.
3
4Version 1.0.0
5Full source at https://github.com/marc-andrew/off-canvas-infinity-push
6Copyright (c) 2014 Marc Andrew http://marcandrew.net/off-canvas-infinity-push
7
8MIT License (http://www.opensource.org/licenses/mit-license.html)
9*/
10
11;(function($){
12
13	$.fn.infinitypush = function(options){
14
15		/**
16		 * Default options
17		 */
18
19		var defaults = {
20			offcanvas			: true,
21			offcanvasspeed		: 400,
22			offcanvasleft		: true,
23			openingspeed		: 400,
24			closingspeed		: 400,
25			spacing				: 90,
26			pushdirectionleft	: true,
27			autoScroll			: true,
28			scrollSpeed			: 300,
29			destroy				: false
30		};
31
32		var infinityPushWrapper = this;
33
34		var opts = $.extend( {}, defaults, options );
35
36		/**
37		 * Start Navigation functions
38		 */
39
40		return this.each(function() {
41
42			var oldposition			= $(this).data('oldposition') || $('body'),
43				navWrapper			= 'ma-infinitypush-wrapper',
44				navWrapperDiv		= '<div class="' + navWrapper + '"></div>',
45				navButtonActive		= 'ma-infinitypush-active-button',
46				navButton			= 'ma-infinitypush-button',
47				navButtonDiv		= '<div class="' + navButton + '"></div>',
48				infinityPush		= 'ma-infinitypush',
49				infinityPushOpen	= 'ma-infinitypush-open';
50			
51			function destroy(){
52				$('.' + navButton).unbind();
53				$('.' + infinityPush).unbind();
54				$('body').removeClass(infinityPushOpen);
55				$('.' + navWrapper).next().removeAttr('style');
56				$('.' + navWrapper).find('.ma-infinitypush-inactive').removeClass('ma-infinitypush-inactive');
57				$('.' + navWrapper).find('.ma-infinitypush-active-item').removeClass('ma-infinitypush-active-item');
58				$('.' + navWrapper).find('.ma-infinitypush-close-subnav').remove();
59				$('.' + navWrapper).find('ul').removeAttr('style');
60				infinityPushWrapper.prependTo(oldposition);
61				infinityPushWrapper.removeClass('ma-infinitypush ma-infinitypush-sub-open');
62				$('.' + navWrapper).remove();
63				$(this).removeClass(infinityPush);
64				infinityPushWrapper.stop().removeAttr('style');
65			}
66			
67			if(opts.destroy){
68				if($(this).hasClass(infinityPush))
69					destroy();
70				return;
71			}
72			
73				// Start navigation toggle function
74				function infinityPushToggle() {
75
76					$('.' + navButton).on('click', function(){
77
78						if($('body').hasClass(infinityPushOpen)){
79							closingAnimation();
80						}
81						else {
82							openingAnimation();
83						}
84
85					});
86
87				}	
88			
89			if(!$(this).hasClass(infinityPush)){
90				
91				$(this).data('oldposition', $(this).parent());
92				
93				// Move navigation after body
94				if(!$(this).parent().is('body')) {
95					$('body').prepend($(this));
96				}
97
98				// Wrapping the element & add new class name
99				$(this).before(navWrapperDiv).addClass(infinityPush).appendTo('.' + navWrapper);
100
101				var navWidth	= $('.' + navWrapper).width();
102
103				// Add the mobile menu button
104				if(opts.offcanvas == true) {
105					$(this).before(navButtonDiv);
106
107					if(opts.offcanvasleft == true) {
108						$('.' + navWrapper).css({ left: '-' + navWidth + 'px' });
109						$('.' + navWrapper).addClass('ma-infinitypush-button-left');
110					} else {
111						$('.' + navWrapper).css({ right: '-' + navWidth + 'px' });
112						$('.' + navWrapper).addClass('ma-infinitypush-button-right');
113					}
114
115					if(opts.pushdirectionleft == true) {
116						$('.' + navWrapper).addClass('ma-infinitypush-left');
117					} else {
118						$('.' + navWrapper).addClass('ma-infinitypush-right');
119					}
120
121					$('.' + navWrapper).addClass(navButtonActive);
122					infinityPushToggle();
123				}
124
125
126
127				// Start closing animation function
128				function closingAnimation() {
129
130					if(opts.offcanvasleft == true) {
131						$('.' + navWrapper).stop().animate({
132							left: '-' + navWidth + 'px'
133						}, opts.offcanvasspeed);
134					} else {
135						$('.' + navWrapper).stop().animate({
136							right: '-' + navWidth + 'px'
137						}, opts.offcanvasspeed);
138					}
139
140					$('.' + infinityPush).stop().animate({
141						opacity: 'hide'
142					}, opts.offcanvasspeed);
143
144					if(opts.offcanvasleft == true) {
145						$('.' + navWrapper).next().stop().animate({
146							left: 0
147						}, opts.offcanvasspeed);
148					} else {
149						$('.' + navWrapper).next().stop().animate({
150							right: 0
151						}, opts.offcanvasspeed);
152					}
153
154					$('body').removeClass(infinityPushOpen);
155
156				}
157
158				// Start opening animation
159				function openingAnimation() {
160
161					$('body').addClass(infinityPushOpen);
162
163					if(opts.offcanvasleft == true) {
164						$('.' + navWrapper).stop().animate({
165							left: 0
166						}, opts.offcanvasspeed);
167					} else {
168						$('.' + navWrapper).stop().animate({
169							right: 0
170						}, opts.offcanvasspeed);
171					}
172
173					$('.' + infinityPush).stop().animate({
174						opacity: 'show'
175					}, opts.offcanvasspeed);
176
177					if(opts.offcanvasleft == true) {
178						$('.' + navWrapper).next().stop().animate({
179							left: navWidth + 'px'
180						}, opts.offcanvasspeed);
181					} else {
182						$('.' + navWrapper).next().stop().animate({
183							right: navWidth + 'px'
184						}, opts.offcanvasspeed);
185					}
186
187					clickOutside();
188
189				}
190
191				// Start closing function by clicking outside the infinity navigation
192				function clickOutside() {
193
194					$('.' + infinityPushOpen).on("mousedown touchstart", function (e) {
195
196						if($('.' + infinityPushOpen).length) {
197							if (!$('.' + navWrapper).is(e.target) // if the target of the click isn't the container...
198								&& $('.' + navWrapper).has(e.target).length === 0) // ... nor a descendant of the container
199							{
200								closingAnimation();
201							}
202						}
203
204					});
205
206				}
207
208				// Start infinity push function
209				$('.' + infinityPush).on('click', 'a', function(){
210
211					// General settings
212					var navWidth		= $(infinityPushWrapper).width(),
213						headParentUL	= $(this).parents(infinityPushWrapper).children('ul'),
214						directParentUL	= $(this).closest('ul'),
215						subUL			= $(this).parent().find('ul').first(),
216						closeSubName	= 'ma-infinitypush-close-subnav',
217						closeSubLink	= '<a href="#" class="' + closeSubName +'"></a>',
218						inactiveList	= 'ma-infinitypush-inactive',
219						inactiveItem	= 'ma-infinitypush-active-item',
220						subOpen 		= 'ma-infinitypush-sub-open';
221
222					if ( headParentUL.hasClass(inactiveList) && headParentUL.siblings().not(inactiveList) ) {
223					// Top UL has the class name & the siblings has not the class name
224
225						/**
226						 * If statement for closing or opening the menu list
227						 */
228
229						if( directParentUL.hasClass(inactiveList) ){
230						// Parent UL has the class name, close the sub menu
231
232							// Closing animation
233							if(opts.pushdirectionleft == true) {
234								directParentUL.find('ul').animate({
235									right: -(navWidth - opts.spacing),
236									opacity: 'hide'
237								}, opts.closingspeed);
238							} else {
239								directParentUL.find('ul').animate({
240									left: -(navWidth - opts.spacing),
241									opacity: 'hide'
242								}, opts.closingspeed);
243							}
244
245							// Removing the class name
246							if( $(this).parent().parent().parent().hasClass(subOpen) ) {
247								$(infinityPushWrapper).removeClass(subOpen);
248							} else {
249								// reset the directParentUL width
250								directParentUL.animate({
251									width: navWidth - opts.spacing
252								}, opts.closingspeed);
253							}
254							directParentUL.removeClass(inactiveList);
255							directParentUL.find('ul').removeClass(inactiveList);
256							directParentUL.siblings().removeClass(inactiveList);
257							directParentUL.find('li').removeClass(inactiveItem);
258
259							// Removing the close link
260							directParentUL.find('.' + closeSubName).animate({
261									opacity: 'hide'
262								}, opts.closingspeed, 
263								function() {
264									$(this).remove();
265								}
266							);
267
268							return false;
269
270						} else {
271						// Parent UL has not the class name, open the sub menu if exist or open the link
272
273							if ( ( subUL.length > 0 ) && ( !subUL.is(':visible') ) ) {
274							// If sub UL exist & is visible
275
276								var getScrollPosition = directParentUL.scrollTop();
277
278								// Adding the class names
279								$(this).parent().addClass(inactiveItem);
280								directParentUL.addClass(inactiveList);
281
282								// Scrolling up function
283								if(opts.autoScroll == true) {
284									// Check if scroll position is not 0px
285									if(getScrollPosition >= 1) {
286										directParentUL.animate({ scrollTop: 0 }, opts.scrollSpeed);
287									}
288								}
289
290								// Adding the close link
291								if(opts.autoScroll == true) {
292									// Check if scroll position is not 0px
293									if(getScrollPosition >= 1) {
294										$(closeSubLink).delay(opts.scrollSpeed).insertAfter($(this)).css('display', 'none').animate({
295											opacity: 'show'
296										}, opts.openingspeed);
297									} else {
298										$(closeSubLink).insertAfter($(this)).css('display', 'none').animate({
299											opacity: 'show'
300										}, opts.openingspeed);
301									}
302								} else {
303									if(getScrollPosition >= 1) {
304										$(closeSubLink).insertAfter($(this)).css({
305											display: 'none',
306											top: getScrollPosition
307										}).animate({
308											opacity: 'show'
309										}, opts.openingspeed);
310									} else {
311										$(closeSubLink).insertAfter($(this)).css({
312											display: 'none',
313											top: 0
314										}).animate({
315											opacity: 'show'
316										}, opts.openingspeed);
317									}
318								}
319
320								// Opening animation
321								if(opts.pushdirectionleft == true) {
322									if(opts.autoScroll == true) {
323										// Check if scroll position is not 0px
324										if(getScrollPosition >= 1) {
325											subUL.delay(opts.scrollSpeed).css({
326												right: -(navWidth - opts.spacing)
327											}).animate({
328												right: 0,
329												opacity: 'show',
330												width: navWidth - opts.spacing
331											}, opts.openingspeed);
332										} else {
333											subUL.css({
334												right: -(navWidth - opts.spacing)
335											}).animate({
336												right: 0,
337												opacity: 'show',
338												width: navWidth - opts.spacing
339											}, opts.openingspeed);
340										}
341									} else {
342										if(getScrollPosition >= 1) {
343											subUL.css({
344												right: -(navWidth - opts.spacing),
345												top: getScrollPosition
346											}).animate({
347												right: 0,
348												opacity: 'show',
349												width: navWidth - opts.spacing
350											}, opts.openingspeed);
351										} else {
352											subUL.css({
353												right: -(navWidth - opts.spacing),
354												top: 0
355											}).animate({
356												right: 0,
357												opacity: 'show',
358												width: navWidth - opts.spacing
359											}, opts.openingspeed);
360										}
361										
362									}
363								} else {
364									if(opts.autoScroll == true) {
365										subUL.delay(opts.scrollSpeed).css({
366											left: -(navWidth - opts.spacing)
367										}).animate({
368											left: 0,
369											opacity: 'show',
370											width: navWidth - opts.spacing
371										}, opts.openingspeed);
372									} else {
373										if(getScrollPosition >= 1) {
374											subUL.css({
375												left: -(navWidth - opts.spacing),
376												top: getScrollPosition
377											}).animate({
378												left: 0,
379												opacity: 'show',
380												width: navWidth - opts.spacing
381											}, opts.openingspeed);
382										} else {
383											subUL.css({
384												left: -(navWidth - opts.spacing),
385												top: 0
386											}).animate({
387												left: 0,
388												opacity: 'show',
389												width: navWidth - opts.spacing
390											}, opts.openingspeed);
391										}
392									}
393									
394								}
395
396								// Changing the directParentUL width
397								directParentUL.animate({
398									width: navWidth
399								}, opts.openingspeed);
400
401								return false;
402
403							}
404
405						}
406
407					} else {
408					// Top UL has not the class name & the siblings has not the class name
409							
410						if ( ( subUL.length > 0 ) && ( !subUL.is(':visible') ) ) {
411						// If sub UL exist & is visible
412
413							var getScrollPosition = $('.' + infinityPush).scrollTop();
414
415							// Adding the class names
416							$(this).parent().addClass(inactiveItem);
417							directParentUL.addClass(inactiveList);
418							directParentUL.siblings().addClass(inactiveList);
419							if( $(infinityPushWrapper).find('ul').is(':visible') ) {
420								$(infinityPushWrapper).addClass(subOpen);
421							}
422
423							// Scrolling up function
424							if(opts.autoScroll == true) {
425								// Check if scroll position is not 0px
426								if(getScrollPosition >= 1) {
427									$('.' + infinityPush).animate({ scrollTop: 0 }, opts.scrollSpeed);
428								}
429							}
430
431							// Adding the close link
432							if(opts.autoScroll == true) {
433								// Check if scroll position is not 0px
434								if(getScrollPosition >= 1) {
435									$(closeSubLink).delay(opts.scrollSpeed).insertAfter($(this)).css('display', 'none').animate({
436										opacity: 'show'
437									}, opts.openingspeed);
438								} else {
439									$(closeSubLink).insertAfter($(this)).css('display', 'none').animate({
440										opacity: 'show'
441									}, opts.openingspeed);
442								}
443							} else {
444								if(getScrollPosition >= 1) {
445									$(closeSubLink).insertAfter($(this)).css({
446										display: 'none',
447										top: getScrollPosition
448									}).animate({
449										opacity: 'show'
450									}, opts.openingspeed);
451								} else {
452									$(closeSubLink).insertAfter($(this)).css({
453										display: 'none',
454										top: 0
455									}).animate({
456										opacity: 'show'
457									}, opts.openingspeed);
458								}
459							}
460
461							// Opening animation
462							if(opts.pushdirectionleft == true) {
463								// Check if autoscroll is enabled
464								if(opts.autoScroll == true) {
465									// Check if scroll position is not 0px
466									if(getScrollPosition >= 1) {
467										subUL.delay(opts.scrollSpeed).css({
468											right: -(navWidth - opts.spacing)
469										}).animate({
470											right: 0,
471											opacity: 'show',
472											width: navWidth - opts.spacing
473										}, opts.openingspeed);
474									} else {
475										subUL.css({
476											right: -(navWidth - opts.spacing)
477										}).animate({
478											right: 0,
479											opacity: 'show',
480											width: navWidth - opts.spacing
481										}, opts.openingspeed);
482									}
483								} else {
484									if(getScrollPosition >= 1) {
485										subUL.css({
486											right: -(navWidth - opts.spacing),
487											top: getScrollPosition
488										}).animate({
489											right: 0,
490											opacity: 'show',
491											width: navWidth - opts.spacing
492										}, opts.openingspeed);
493									} else {
494										subUL.css({
495											right: -(navWidth - opts.spacing),
496											top: 0
497										}).animate({
498											right: 0,
499											opacity: 'show',
500											width: navWidth - opts.spacing
501										}, opts.openingspeed);
502									}
503								}
504							} else {
505								if(opts.autoScroll == true) {
506									subUL.delay(opts.scrollSpeed).css({
507										left: -(navWidth - opts.spacing)
508									}).animate({
509										left: 0,
510										opacity: 'show',
511										width: navWidth - opts.spacing
512									}, opts.openingspeed);
513								} else {
514									if(getScrollPosition >= 1) {
515										subUL.css({
516											left: -(navWidth - opts.spacing),
517											top: getScrollPosition
518										}).animate({
519											left: 0,
520											opacity: 'show',
521											width: navWidth - opts.spacing
522										}, opts.openingspeed);
523									} else {
524										subUL.css({
525											left: -(navWidth - opts.spacing),
526											top: 0
527										}).animate({
528											left: 0,
529											opacity: 'show',
530											width: navWidth - opts.spacing
531										}, opts.openingspeed);
532									}
533								}
534							}
535
536							return false;
537
538						}
539
540					}
541
542				});
543
544			}
545
546		});
547
548	};
549
550})(jQuery);
551
552

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.