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