/* * jQuery mmenu v4.2.2 * @requires jQuery 1.7.0 or later * * mmenu.frebsite.nl * * Copyright (c) Fred Heusschen * www.frebsite.nl * * Dual licensed under the MIT and GPL licenses. * http://en.wikipedia.org/wiki/MIT_License * http://en.wikipedia.org/wiki/GNU_General_Public_License */ (function( $ ) { var _PLUGIN_ = 'mmenu', _VERSION_ = '4.2.2'; // Plugin already excists if ( $[ _PLUGIN_ ] ) { return; } // Global variables var glbl = { $wndw: null, $html: null, $body: null, $page: null, $blck: null, $allMenus: null }; var _c = {}, _d = {}, _e = {}, _serialnr = 0, _strollTop = 0; $[ _PLUGIN_ ] = function( $menu, opts, conf ) { glbl.$allMenus = glbl.$allMenus.add( $menu ); this.$menu = $menu; this.opts = opts this.conf = conf; this.serialnr = _serialnr++; this._init(); return this; }; $[ _PLUGIN_ ].prototype = { open: function() { var that = this; this._openSetup(); // For some reason, some browsers need a (pretty long) delay before the .mm-opened class sets the needed styles // Without it, the page isn't animated setTimeout( function() { that._openFinish(); }, 50 ); return 'open'; }, _openSetup: function() { _strollTop = glbl.$wndw.scrollTop(); // Set opened this.$menu.addClass( _c.current ); // Close others glbl.$allMenus.not( this.$menu ).trigger( _e.close ); // Store style and position glbl.$page.data( _d.style, glbl.$page.attr( 'style' ) || '' ); // Trigger window-resize to measure height glbl.$wndw.trigger( _e.resize, [ true ] ); // Add options if ( this.opts.modal ) { glbl.$html.addClass( _c.modal ); } if ( this.opts.moveBackground ) { glbl.$html.addClass( _c.background ); } if ( this.opts.position != 'left' ) { glbl.$html.addClass( _c.mm( this.opts.position ) ); } if ( this.opts.zposition != 'back' ) { glbl.$html.addClass( _c.mm( this.opts.zposition ) ); } if ( this.opts.classes ) { glbl.$html.addClass( this.opts.classes ); } // Open glbl.$html.addClass( _c.opened ); this.$menu.addClass( _c.opened ); }, _openFinish: function() { var that = this; // Callback transitionend( glbl.$page, function() { that.$menu.trigger( _e.opened ); }, this.conf.transitionDuration ); // Opening glbl.$html.addClass( _c.opening ); this.$menu.trigger( _e.opening ); }, close: function() { var that = this; // Callback transitionend( glbl.$page, function() { that.$menu .removeClass( _c.current ) .removeClass( _c.opened ); glbl.$html .removeClass( _c.opened ) .removeClass( _c.modal ) .removeClass( _c.background ) .removeClass( _c.mm( that.opts.position ) ) .removeClass( _c.mm( that.opts.zposition ) ); if ( that.opts.classes ) { glbl.$html.removeClass( that.opts.classes ); } // Restore style and position glbl.$page.attr( 'style', glbl.$page.data( _d.style ) ); // Closed that.$menu.trigger( _e.closed ); }, this.conf.transitionDuration ); // Closing glbl.$html.removeClass( _c.opening ); this.$menu.trigger( _e.closing ); return 'close'; }, _init: function() { this.opts = extendOptions( this.opts, this.conf, this.$menu ); this.direction = ( this.opts.slidingSubmenus ) ? 'horizontal' : 'vertical'; // INIT PAGE & MENU this._initPage( glbl.$page ); this._initMenu(); this._initBlocker(); this._initPanles(); this._initLinks(); this._initOpenClose(); this._bindCustomEvents(); if ( $[ _PLUGIN_ ].addons ) { for ( var a = 0; a < $[ _PLUGIN_ ].addons.length; a++ ) { if ( typeof this[ '_addon_' + $[ _PLUGIN_ ].addons[ a ] ] == 'function' ) { this[ '_addon_' + $[ _PLUGIN_ ].addons[ a ] ](); } } } }, _bindCustomEvents: function() { var that = this; this.$menu .off( _e.open + ' ' + _e.close + ' ' + _e.setPage+ ' ' + _e.update ) .on( _e.open + ' ' + _e.close + ' ' + _e.setPage+ ' ' + _e.update, function( e ) { e.stopPropagation(); } ); // Menu-events this.$menu .on( _e.open, function( e ) { if ( $(this).hasClass( _c.current ) ) { e.stopImmediatePropagation(); return false; } return that.open(); } ) .on( _e.close, function( e ) { if ( !$(this).hasClass( _c.current ) ) { e.stopImmediatePropagation(); return false; } return that.close(); } ) .on( _e.setPage, function( e, $p ) { that._initPage( $p ); that._initOpenClose(); } ); // Panel-events var $panels = this.$menu.find( this.opts.isMenu && this.direction != 'horizontal' ? 'ul, ol' : '.' + _c.panel ); $panels .off( _e.toggle + ' ' + _e.open + ' ' + _e.close ) .on( _e.toggle + ' ' + _e.open + ' ' + _e.close, function( e ) { e.stopPropagation(); } ); if ( this.direction == 'horizontal' ) { $panels .on( _e.open, function( e ) { return openSubmenuHorizontal( $(this), that.$menu ); } ); } else { $panels .on( _e.toggle, function( e ) { var $t = $(this); return $t.triggerHandler( $t.parent().hasClass( _c.opened ) ? _e.close : _e.open ); } ) .on( _e.open, function( e ) { $(this).parent().addClass( _c.opened ); return 'open'; } ) .on( _e.close, function( e ) { $(this).parent().removeClass( _c.opened ); return 'close'; } ); } }, _initBlocker: function() { var that = this; if ( !glbl.$blck ) { glbl.$blck = $( '
' ) .appendTo( glbl.$body ); } glbl.$blck .off( _e.touchstart ) .on( _e.touchstart, function( e ) { e.preventDefault(); e.stopPropagation(); glbl.$blck.trigger( _e.mousedown ); } ) .on( _e.mousedown, function( e ) { e.preventDefault(); if ( !glbl.$html.hasClass( _c.modal ) ) { that.$menu.trigger( _e.close ); } } ); }, _initPage: function( $p ) { if ( !$p ) { $p = $(this.conf.pageSelector, glbl.$body); if ( $p.length > 1 ) { $[ _PLUGIN_ ].debug( 'Multiple nodes found for the page-node, all nodes are wrapped in one <' + this.conf.pageNodetype + '>.' ); $p = $p.wrapAll( '<' + this.conf.pageNodetype + ' />' ).parent(); } } $p.addClass( _c.page ); glbl.$page = $p; }, _initMenu: function() { var that = this; // Clone if needed if ( this.conf.clone ) { this.$menu = this.$menu.clone( true ); this.$menu.add( this.$menu.find( '*' ) ).filter( '[id]' ).each( function() { $(this).attr( 'id', _c.mm( $(this).attr( 'id' ) ) ); } ); } // Strip whitespace this.$menu.contents().each( function() { if ( $(this)[ 0 ].nodeType == 3 ) { $(this).remove(); } } ); // Prepend to body this.$menu .prependTo( 'body' ) .addClass( _c.menu ); // Add direction class this.$menu.addClass( _c.mm( this.direction ) ); // Add options classes if ( this.opts.classes ) { this.$menu.addClass( this.opts.classes ); } if ( this.opts.isMenu ) { this.$menu.addClass( _c.ismenu ); } if ( this.opts.position != 'left' ) { this.$menu.addClass( _c.mm( this.opts.position ) ); } if ( this.opts.zposition != 'back' ) { this.$menu.addClass( _c.mm( this.opts.zposition ) ); } }, _initPanles: function() { var that = this; // Refactor List class this.__refactorClass( $('.' + this.conf.listClass, this.$menu), 'list' ); // Add List class if ( this.opts.isMenu ) { $('ul, ol', this.$menu) .not( '.mm-nolist' ) .addClass( _c.list ); } var $lis = $('.' + _c.list + ' > li', this.$menu); // Refactor Selected class this.__refactorClass( $lis.filter( '.' + this.conf.selectedClass ), 'selected' ); // Refactor Label class this.__refactorClass( $lis.filter( '.' + this.conf.labelClass ), 'label' ); // Refactor Spacer class this.__refactorClass( $lis.filter( '.' + this.conf.spacerClass ), 'spacer' ); // setSelected-event $lis .off( _e.setSelected ) .on( _e.setSelected, function( e, selected ) { e.stopPropagation(); $lis.removeClass( _c.selected ); if ( typeof selected != 'boolean' ) { selected = true; } if ( selected ) { $(this).addClass( _c.selected ); } } ); // Refactor Panel class this.__refactorClass( $('.' + this.conf.panelClass, this.$menu), 'panel' ); // Add Panel class this.$menu .children() .filter( this.conf.panelNodetype ) .add( this.$menu.find( '.' + _c.list ).children().children().filter( this.conf.panelNodetype ) ) .addClass( _c.panel ); var $panels = $('.' + _c.panel, this.$menu); // Add an ID to all panels $panels .each( function( i ) { var $t = $(this), id = $t.attr( 'id' ) || _c.mm( 'm' + that.serialnr + '-p' + i ); $t.attr( 'id', id ); } ); // Add open and close links to menu items $panels .find( '.' + _c.panel ) .each( function( i ) { var $t = $(this), $u = $t.is( 'ul, ol' ) ? $t : $t.find( 'ul ,ol' ).first(), $l = $t.parent(), $a = $l.find( '> a, > span' ), $p = $l.closest( '.' + _c.panel ); $t.data( _d.parent, $l ); if ( $l.parent().is( '.' + _c.list ) ) { var $btn = $( '' ).insertBefore( $a ); if ( !$a.is( 'a' ) ) { $btn.addClass( _c.fullsubopen ); } if ( that.direction == 'horizontal' ) { $u.prepend( '