PageSourceSearch

https://www.mark-schramm.com/wp-content/themes/wezen/js/jquery.dlmenu.js?ver=1.0.0

js mark-schramm.com collected 2026-09-29 10:37:58 UTC 6,573 bytes, 225 lines download raw bytes

1;( function( $, window, undefined ) {
2
3	'use strict';
4
5	var Modernizr = window.Modernizr, $body = $( 'body' );
6
7	$.DLMenu = function( options, element ) {
8		this.$el = $( element );
9		this._init( options );
10	};
11
12	// the options
13	$.DLMenu.defaults = {
14		animationClasses : { classin : 'dl-animate-in-2', classout : 'dl-animate-out-2' },
15		onLevelClick : function( el, name ) { return false; },
16		onLinkClick : function( el, ev ) { return false; }
17	};
18
19	$.DLMenu.prototype = {
20		_init : function( options ) {
21
22			// options
23			this.options = $.extend( true, {}, $.DLMenu.defaults, options );
24			// cache some elements and initialize some variables
25			this._config();
26			
27			var animEndEventNames = {
28					'WebkitAnimation' : 'webkitAnimationEnd',
29					'OAnimation' : 'oAnimationEnd',
30					'msAnimation' : 'MSAnimationEnd',
31					'animation' : 'animationend'
32				},
33				transEndEventNames = {
34					'WebkitTransition' : 'webkitTransitionEnd',
35					'MozTransition' : 'transitionend',
36					'OTransition' : 'oTransitionEnd',
37					'msTransition' : 'MSTransitionEnd',
38					'transition' : 'transitionend'
39				};
40			// animation end event name
41			this.animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ] + '.dlmenu';
42			// transition end event name
43			this.transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ] + '.dlmenu',
44			// support for css animations and css transitions
45			this.supportAnimations = Modernizr.cssanimations,
46			this.supportTransitions = Modernizr.csstransitions;
47
48			this._initEvents();
49
50		},
51		_config : function() {
52			this.open = false;
53			this.$trigger = this.$el.children( '.dl-trigger' );
54			this.$menu = this.$el.children( 'ul.dl-menu' );
55			this.$menuitems = this.$menu.find( 'li:not(.dl-back)' );
56			this.$el.find( 'ul.sub-menu' ).prepend( '<li class="dl-back"><a href="#"><i class="lnr lnr-arrow-left"></i></a></li>' );
57			this.$menuitems.clone().appendTo(".dl-back").find("a").val("");
58			this.$back = this.$menu.find( 'li.dl-back' );
59		},
60		_initEvents : function() {
61
62			var self = this;
63
64			jQuery(document).on( 'click', 'li.menu-item-has-children > a', function( event ) {
65				
66				event.stopPropagation();
67
68				var elem = jQuery(this),
69                    link_clear = elem['0'],
70					$item = jQuery(link_clear.parentNode),
71                    $submenu = $item.children( 'ul.sub-menu' );
72
73				if( $submenu.length > 0 ) {
74					var $flyin = $submenu.clone().css( 'opacity', 0 ).insertAfter( self.$submenu ),
75						onAnimationEndFn = function() {
76							self.$menu.off( self.animEndEventName ).removeClass( self.options.animationClasses.classout ).addClass( 'dl-subview' );
77							$item.addClass( 'dl-subviewopen' ).parents( '.dl-subviewopen:first' ).removeClass( 'dl-subviewopen' ).addClass( 'dl-subview' );
78							$flyin.remove();
79						};
80
81					setTimeout( function() {
82						$flyin.addClass( self.options.animationClasses.classin );
83						self.$menu.addClass( self.options.animationClasses.classout );
84						if( self.supportAnimations ) {
85							self.$menu.on( self.animEndEventName, onAnimationEndFn );
86						} else {
87							onAnimationEndFn.call();
88						}
89
90						self.options.onLevelClick( $item, $item.children( 'a:first' ).text() );
91					} );
92
93					return false;
94
95				}
96				else {
97					self.options.onLinkClick( $item, event );
98				}
99
100			} );
101
102			this.$back.on( 'click.dlmenu', function( event ) {
103				
104				var $this = $( this ),
105					$submenu = $this.parents( 'ul.sub-menu:first' ),
106					$item = $submenu.parent(),
107
108					$flyin = $submenu.clone().insertAfter( self.$submenu );
109
110				var onAnimationEndFn = function() {
111					self.$menu.off( self.animEndEventName ).removeClass( self.options.animationClasses.classin );
112					$flyin.remove();
113				};
114
115				setTimeout( function() {
116					$flyin.addClass( self.options.animationClasses.classout );
117					self.$menu.addClass( self.options.animationClasses.classin );
118					if( self.supportAnimations ) {
119						self.$menu.on( self.animEndEventName, onAnimationEndFn );
120					}
121					else {
122						onAnimationEndFn.call();
123					}
124
125					$item.removeClass( 'dl-subviewopen' );
126					
127					var $subview = $this.parents( '.dl-subview:first' );
128					if( $subview.is( 'li' ) ) {
129						$subview.addClass( 'dl-subviewopen' );
130					}
131					$subview.removeClass( 'dl-subview' );
132				} );
133
134				return false;
135
136			} );
137			
138		},
139		closeMenu : function() {
140			if( this.open ) {
141				this._closeMenu();
142			}
143		},
144		_closeMenu : function() {
145			var self = this,
146				onTransitionEndFn = function() {
147					self.$menu.off( self.transEndEventName );
148					self._resetMenu();
149				};
150			
151			this.$menu.removeClass( 'dl-menuopen' );
152			this.$menu.addClass( 'dl-menu-toggle' );
153			this.$trigger.removeClass( 'dl-active' );
154			
155			if( this.supportTransitions ) {
156				this.$menu.on( this.transEndEventName, onTransitionEndFn );
157			}
158			else {
159				onTransitionEndFn.call();
160			}
161
162			this.open = false;
163		},
164		openMenu : function() {
165			if( !this.open ) {
166				this._openMenu();
167			}
168		},
169		_openMenu : function() {
170			var self = this;
171			// clicking somewhere else makes the menu close
172			$body.off( 'click' ).on( 'click.dlmenu', function() {
173				self._closeMenu() ;
174			} );
175			this.$menu.addClass( 'dl-menuopen dl-menu-toggle' ).on( this.transEndEventName, function() {
176				$( this ).removeClass( 'dl-menu-toggle' );
177			} );
178			this.$trigger.addClass( 'dl-active' );
179			this.open = true;
180		},
181		// resets the menu to its original state (first level of options)
182		_resetMenu : function() {
183			this.$menu.removeClass( 'dl-subview' );
184			this.$menuitems.removeClass( 'dl-subview dl-subviewopen' );
185		}
186	};
187
188	var logError = function( message ) {
189		if ( window.console ) {
190			window.console.error( message );
191		}
192	};
193
194	$.fn.dlmenu = function( options ) {
195		if ( typeof options === 'string' ) {
196			var args = Array.prototype.slice.call( arguments, 1 );
197			this.each(function() {
198				var instance = $.data( this, 'dlmenu' );
199				if ( !instance ) {
200					logError( "cannot call methods on dlmenu prior to initialization; " +
201					"attempted to call method '" + options + "'" );
202					return;
203				}
204				if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {
205					logError( "no such method '" + options + "' for dlmenu instance" );
206					return;
207				}
208				instance[ options ].apply( instance, args );
209			});
210		} 
211		else {
212			this.each(function() {	
213				var instance = $.data( this, 'dlmenu' );
214				if ( instance ) {
215					instance._init();
216				}
217				else {
218					instance = $.data( this, 'dlmenu', new $.DLMenu( options, this ) );
219				}
220			});
221		}
222		return this;
223	};
224
225} )( jQuery, window );

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.