PageSourceSearch

https://www.midtowncomics.com/js/mlpushmenu.js

js midtowncomics.com collected 2026-10-01 11:34:32 UTC 10,338 bytes, 249 lines download raw bytes

1/**
2 * mlpushmenu.js v1.0.0
3 * http://www.codrops.com
4 *
5 * Licensed under the MIT license.
6 * http://www.opensource.org/licenses/mit-license.php
7 * 
8 * Copyright 2013, Codrops
9 * http://www.codrops.com
10 */
11( function( window ) {
12	
13	'use strict';
14
15	function extend( a, b ) {
16		for( var key in b ) { 
17			if( b.hasOwnProperty( key ) ) {
18				a[key] = b[key];
19			}
20		}
21		return a;
22	}
23
24	// taken from https://github.com/inuyaksa/jquery.nicescroll/blob/master/jquery.nicescroll.js
25	function hasParent( e, id ) {
26		if (!e) return false;
27		var el = e.target||e.srcElement||e||false;
28		while (el && el.id != id) {
29			el = el.parentNode||false;
30		}
31		return (el!==false);
32	}
33
34	// returns the depth of the element "e" relative to element with id=id
35	// for this calculation only parents with classname = waypoint are considered
36	function getLevelDepth( e, id, waypoint, cnt ) {
37		cnt = cnt || 0;
38		if ( e.id.indexOf( id ) >= 0 ) return cnt;
39		if( classie.has( e, waypoint ) ) {
40			++cnt;
41		}
42		return e.parentNode && getLevelDepth( e.parentNode, id, waypoint, cnt );
43	}
44
45	// http://coveroverflow.com/a/11381730/989439
46	function mobilecheck() {
47		var check = false;
48		(function(a){if(/(android|ipad|playbook|silk|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
49		return check;
50	}
51
52	// returns the closest element to 'e' that has class "classname"
53	function closest( e, classname ) {
54		if( classie.has( e, classname ) ) {
55			return e;
56		}
57		return e.parentNode && closest( e.parentNode, classname );
58	}
59
60	function mlPushMenu( el, trigger, options ) {	
61		this.el = el;
62		this.trigger = trigger;
63		this.options = extend( this.defaults, options );
64		// support 3d transforms
65		this.support = Modernizr.csstransforms3d;
66		if( this.support ) {
67			this._init();
68		}
69	}
70
71	mlPushMenu.prototype = {
72		defaults : {
73			// overlap: there will be a gap between open levels
74			// cover: the open levels will be on top of any previous open level
75			type : 'overlap', // overlap || cover
76			// space between each overlaped level
77			levelSpacing : 0,
78			// classname for the element (if any) that when clicked closes the current level
79			backClass : 'mp-back'
80		},
81		_init : function() {
82			// if menu is open or not
83			this.open = false;
84			// level depth
85			this.level = 0;
86			// the moving wrapper
87			this.wrapper = document.getElementById( 'mp-pusher' );
88			// the mp-level elements
89			this.levels = Array.prototype.slice.call( this.el.querySelectorAll( 'div.mp-level' ) );
90			// save the depth of each of these mp-level elements
91			var self = this;
92			this.levels.forEach( function( el, i ) { el.setAttribute( 'data-level', getLevelDepth( el, self.el.id, 'mp-level' ) ); } );
93			// the menu items
94			this.menuItems = Array.prototype.slice.call( this.el.querySelectorAll( 'li' ) );
95			// if type == "cover" these will serve as hooks to move back to the previous level
96			this.levelBack = Array.prototype.slice.call( this.el.querySelectorAll( '.' + this.options.backClass ) );
97			// event type (if mobile use touch events)
98			this.eventtype = mobilecheck() ? 'touchstart' : 'click';
99			// add the class mp-overlap or mp-cover to the main element depending on options.type
100			classie.add( this.el, 'mp-' + this.options.type );
101			// initialize / bind the necessary events
102			this._initEvents();
103		},
104		_initEvents : function() {
105			var self = this;
106
107			// the menu should close if clicking somewhere on the body
108			var bodyClickFn = function( el ) {
109				self._resetMenu();
110				el.removeEventListener( self.eventtype, bodyClickFn );
111			};
112
113			// open (or close) the menu
114			this.trigger.addEventListener( this.eventtype, function( ev ) {
115				ev.stopPropagation();
116				ev.preventDefault();
117				if( self.open ) {
118					self._resetMenu();
119				}
120				else {
121					self._openMenu();
122					// the menu should close if clicking somewhere on the body (excluding clicks on the menu)
123					document.addEventListener( self.eventtype, function( ev ) {
124						if( self.open && !hasParent( ev.target, self.el.id ) ) {
125							bodyClickFn( this );
126						}
127					} );
128				}
129			} );
130            
131			// opening a sub level menu
132			this.menuItems.forEach( function( el, i ) {
133				// check if it has a sub level
134				var subLevel = el.querySelector( 'div.mp-level' );
135				if( subLevel ) {
136					el.querySelector( 'a' ).addEventListener( self.eventtype, function( ev ) {
137						ev.preventDefault();
138						var level = closest( el, 'mp-level' ).getAttribute( 'data-level' );
139						if( self.level <= level ) {
140							ev.stopPropagation();
141							classie.add( closest( el, 'mp-level' ), 'mp-level-overlay' );
142							self._openMenu( subLevel );
143						}
144					} );
145				}
146			} );
147
148			// closing the sub levels :
149			// by clicking on the visible part of the level element
150			this.levels.forEach( function( el, i ) {
151				el.addEventListener( self.eventtype, function( ev ) {
152					ev.stopPropagation();
153					var level = el.getAttribute( 'data-level' );
154					if( self.level > level ) {
155						self.level = level;
156						self._closeMenu();
157					}
158				} );
159			} );
160
161			// by clicking on a specific element
162			this.levelBack.forEach( function( el, i ) {
163				el.addEventListener( self.eventtype, function( ev ) {
164					ev.preventDefault();
165					var level = closest( el, 'mp-level' ).getAttribute( 'data-level' );
166					if( self.level <= level ) {
167						ev.stopPropagation();
168						self.level = closest( el, 'mp-level' ).getAttribute( 'data-level' ) - 1;
169						self.level === 0 ? self._resetMenu() : self._closeMenu();
170					}
171				} );
172			});
173		},
174		_openMenu : function( subLevel ) {
175			// increment level depth
176			++this.level;
177            dim(true);
178            $("body").addClass('prevent-scroll');
179            
180			// move the main wrapper
181			var levelFactor = ( this.level - 1 ) * this.options.levelSpacing,
182				translateVal = this.options.type === 'overlap' ? this.el.offsetWidth + levelFactor : this.el.offsetWidth;
183			
184			this._setTransform( 'translate(' + translateVal + 'px,0)' );
185
186			if( subLevel ) {
187				// reset transform for sublevel
188				this._setTransform( '', subLevel );
189				// need to reset the translate value for the level menus that have the same level depth and are not open
190				for( var i = 0, len = this.levels.length; i < len; ++i ) {
191					var levelEl = this.levels[i];
192					if( levelEl != subLevel && !classie.has( levelEl, 'mp-level-open' ) ) {
193						this._setTransform( 'translate(-100%,0,0) translate(' + -1*levelFactor + 'px,0)', levelEl );
194					}
195				}
196			}
197			// add class mp-pushed to main wrapper if opening the first time
198			if( this.level === 1 ) {
199				classie.add( this.wrapper, 'mp-pushed' );
200				this.open = true;
201			}
202			// add class mp-level-open to the opening level element
203			classie.add( subLevel || this.levels[0], 'mp-level-open' );
204		},
205		// close the menu
206		_resetMenu : function() {
207            dim(false);
208            $("body").removeClass('prevent-scroll');
209			this._setTransform('translate(0,0)');
210			this.level = 0;
211			// remove class mp-pushed from main wrapper
212			classie.remove( this.wrapper, 'mp-pushed' );
213			this._toggleLevels();
214			this.open = false;
215		},
216		// close sub menus
217		_closeMenu : function() {
218            console.log(this);
219			var translateVal = this.options.type === 'overlap' ? this.el.offsetWidth + ( this.level - 1 ) * this.options.levelSpacing : this.el.offsetWidth;
220			this._setTransform( 'translate(' + translateVal + 'px,0)' );
221			this._toggleLevels();
222		},
223		// translate the el
224		_setTransform : function( val, el ) {
225			el = el || this.wrapper;
226			el.style.WebkitTransform = val;
227			el.style.MozTransform = val;
228			el.style.transform = val;
229		},
230		// removes classes mp-level-open from closing levels
231		_toggleLevels : function() {
232			for( var i = 0, len = this.levels.length; i < len; ++i ) {
233				var levelEl = this.levels[i];
234				if( levelEl.getAttribute( 'data-level' ) >= this.level + 1 ) {
235					classie.remove( levelEl, 'mp-level-open' );
236					classie.remove( levelEl, 'mp-level-overlay' );
237				}
238				else if( Number( levelEl.getAttribute( 'data-level' ) ) == this.level ) {
239					classie.remove( levelEl, 'mp-level-overlay' );
240				}
241			}
242		}  
243	}
244
245	// add to global namespace
246	window.mlPushMenu = mlPushMenu;
247
248} )( window );
249

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.