/* * jQuery mmenu 1.3.1 * * Copyright (c) 2013 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( $ ) { // Global nodes var $wndw = null, $html = null, $body = null, $page = null, $blck = null; var $scrollTopNode = null; // Global vars var _serialnr = 0; $.fn.mmenu = function( opts ) { if ( !$wndw ) { $wndw = $(window); $html = $('html'); $body = $('body'); } opts = extendOptions( opts ); opts = $.extend( true, {}, $.fn.mmenu.defaultOptions, opts ); opts = complementOptions( opts ); $html[ opts.configuration.hardwareAcceleration ? 'addClass' : 'removeClass' ]( cls( 'accelerated' ) ); return this.each( function() { // STORE VARIABLES var $menu = $(this), _opened = false, _direction = ( opts.slidingSubmenus ) ? 'horizontal' : 'vertical'; _serialnr++; // INIT PAGE, MENU, LINKS & LABELS $page = _initPage( $page, opts.configuration ); $blck = _initBlocker( $blck, $menu, opts.configuration ); $menu = _initMenu( $menu, opts.configuration ); _initSubmenus( $menu, _direction, _serialnr ); _initLinks( $menu, opts.onClick, opts.configuration ); _initCounters( $menu, opts.counters, opts.configuration ); _initSearch( $menu, opts.searchfield ); _initOpenClose( $menu, $page ); // BIND EVENTS var $subs = $menu.find( 'ul' ); $menu.add( $subs ) .bind( evt( 'toggle' ) + ' ' + evt( 'open' ) + ' ' + evt( 'close' ), function( e ) { e.preventDefault(); e.stopPropagation(); } ); // menu-events $menu .bind( evt( 'toggle' ), function( e ) { return $menu.triggerHandler( evt( _opened ? 'close' : 'open' ) ); } ) .bind( evt( 'open' ), function( e ) { if ( _opened ) { return false; } _opened = true; return openMenu( $menu, opts.position ); } ) .bind( evt( 'close' ), function( e ) { if ( !_opened ) { return false; } _opened = false; return closeMenu( $menu, opts ); } ); // submenu-events if ( _direction == 'horizontal' ) { $subs .bind( evt( 'toggle' ), function( e ) { return $(this).triggerHandler( evt( 'open' ) ); } ) .bind( evt( 'open' ), function( e ) { return openSubmenuHorizontal( $(this), opts ); } ) .bind( evt( 'close' ), function( e ) { return closeSubmenuHorizontal( $(this), opts ); } ); } else { $subs .bind( evt( 'toggle' ), function( e ) { var $t = $(this); return $t.triggerHandler( evt( ( $t.parent().hasClass( cls( 'opened' ) ) ) ? 'close' : 'open' ) ); } ) .bind( evt( 'open' ), function( e ) { $(this).parent().addClass( cls( 'opened' ) ); return 'open'; } ) .bind( evt( 'close' ), function( e ) { $(this).parent().removeClass( cls( 'opened' ) ); return 'close'; } ); } } ); }; $.fn.mmenu.defaultOptions = { position : 'right', slidingSubmenus : true, counters : { add : false, count : true }, searchfield : { add : false, search : true, showLinksOnly : true, placeholder : 'Search', noResults : 'No results found.' }, onClick : { close : true, delayPageload : true, blockUI : false }, configuration : { hardwareAcceleration: true, selectedClass : 'Selected', labelClass : 'Label', counterClass : 'Counter', pageNodetype : 'div', menuNodetype : 'nav', slideDuration : 500 } }; $.fn.mmenu.debug = function( msg ) { if ( typeof console != 'undefined' && typeof console.log != 'undefined' ) { console.log( 'MMENU: ' + msg ); } }; $.fn.mmenu.deprecated = function( depr, repl ) { if ( typeof console != 'undefined' && typeof console.warn != 'undefined' ) { console.warn( 'MMENU: ' + depr + ' is deprecated, use ' + repl + ' instead.' ); } }; function extendOptions( o ) { if ( typeof o == 'string' ) { if ( o == 'left' || o == 'right' ) { o = { position: o }; } } else if ( typeof o != 'object' ) { o = {}; } // DEPRECATED if ( typeof o.addCounters != 'undefined' ) { $.fn.mmenu.deprecated( 'addCounters-option', 'counters.add-option' ); o.counters = { add: o.addCounters }; } if ( typeof o.closeOnClick != 'undefined' ) { $.fn.mmenu.deprecated( 'closeOnClick-option', 'onClick.close-option' ); o.onClick = { close: o.closeOnClick }; } // /DEPRECATED // Counters if ( typeof o.counters == 'boolean' ) { o.counters = { add : o.counters, count : o.counters }; } else if ( typeof o.counters != 'object' ) { o.counters = {}; } // OnClick if ( typeof o.onClick == 'boolean' ) { o.onClick = { close : o.onClick }; } else if ( typeof o.onClick != 'object' ) { o.onClick = {}; } // Search if ( typeof o.searchfield == 'boolean' ) { o.searchfield = { add : o.searchfield, search : o.searchfield }; } else if ( typeof o.searchfield == 'string' ) { o.searchfield = { add : true, search : true, placeholder : o.searchfield }; } else if ( typeof o.searchfield != 'object' ) { o.searchfield = {}; } return o; } function complementOptions( o ) { if ( typeof o.onClick.delayPageload == 'boolean' ) { o.onClick.delayPageload = ( o.onClick.delayPageload ) ? o.configuration.slideDuration : 0; } return o; } function _initPage( $p, conf ) { if ( !$p ) { $p = $('> ' + conf.pageNodetype, $body); if ( $p.length > 1 ) { $p = $p.wrapAll( '<' + conf.pageNodetype + ' />' ).parent(); } $p.addClass( cls( 'page' ) ); } return $p; } function _initMenu( $m, conf ) { if ( !$m.is( conf.menuNodetype ) ) { $m = $( '<' + conf.menuNodetype + ' />' ).append( $m ); } // $_dummy = $( '