/** * jquery meanmenu v2.0 * copyright (c) 2012-2013 chris wharton (themes@meanthemes.com) * * this program is free software: you can redistribute it and/or modify * it under the terms of the gnu general public license as published by * the free software foundation, either version 3 of the license, or * (at your option) any later version. * * this software and documentation is provided "as is," and copyright * holders make no representations or warranties, express or implied, * including but not limited to, warranties of merchantability or * fitness for any particular purpose or that the use of the software * or documentation will not infringe any third party patents, * copyrights, trademarks or other rights.copyright holders will not * be liable for any direct, indirect, special or consequential * damages arising out of any use of the software or documentation. * * you should have received a copy of the gnu general public license * along with this program. if not, see . * * find more information at http://www.meanthemes.com/plugins/meanmenu/ * */ (function ($) { $.fn.meanmenu = function (options) { var defaults = { meanmenutarget: jquery(this), // target the current html markup you wish to replace meanmenuclose: "x", // single character you want to represent the close menu button meanmenuclosesize: "18px", // set font size of close button meanmenuopen: "", // text/markup you want when menu is closed meanrevealposition: "right", // left right or center positions meanrevealpositiondistance: "0", // tweak the position of the menu meanrevealcolour: "", // override css colours for the reveal background meanrevealhovercolour: "", // override css colours for the reveal hover meanscreenwidth: "960", // set the screen width you want meanmenu to kick in at meannavpush: "", // set a height here in px, em or % if you want to budge your layout now the navigation is missing. meanshowchildren: true, // true to show children in the menu, false to hide them meanexpandablechildren: true, // true to allow expand/collapse children meanexpand: "+", // single character you want to represent the expand for uls meancontract: "-", // single character you want to represent the contract for uls meanremoveattrs: false // true to remove classes and ids, false to keep them }; var options = $.extend(defaults, options); // get browser width currentwidth = window.innerwidth || document.documentelement.clientwidth; return this.each(function () { var meanmenu = options.meanmenutarget; var meanreveal = options.meanreveal; var meanmenuclose = options.meanmenuclose; var meanmenuclosesize = options.meanmenuclosesize; var meanmenuopen = options.meanmenuopen; var meanrevealposition = options.meanrevealposition; var meanrevealpositiondistance = options.meanrevealpositiondistance; var meanrevealcolour = options.meanrevealcolour; var meanrevealhovercolour = options.meanrevealhovercolour; var meanscreenwidth = options.meanscreenwidth; var meannavpush = options.meannavpush; var meanrevealclass = ".meanmenu-reveal"; meanshowchildren = options.meanshowchildren; meanexpandablechildren = options.meanexpandablechildren; var meanexpand = options.meanexpand; var meancontract = options.meancontract; var meanremoveattrs = options.meanremoveattrs; //detect known mobile/tablet usage if ( (navigator.useragent.match(/iphone/i)) || (navigator.useragent.match(/ipod/i)) || (navigator.useragent.match(/ipad/i)) || (navigator.useragent.match(/android/i)) || (navigator.useragent.match(/blackberry/i)) || (navigator.useragent.match(/windows phone/i)) ) { var ismobile = true; } if ( (navigator.useragent.match(/msie 8/i)) || (navigator.useragent.match(/msie 7/i)) ) { // add scrollbar for ie7 & 8 to stop breaking resize function on small content sites jquery('html').css("overflow-y" , "scroll"); } function meancentered() { if (meanrevealposition == "center") { var newwidth = window.innerwidth || document.documentelement.clientwidth; var meancenter = ( (newwidth/2)-22 )+"px"; meanrevealpos = "left:" + meancenter + ";right:auto;"; if (!ismobile) { jquery('.meanmenu-reveal').css("left",meancenter); } else { jquery('.meanmenu-reveal').animate({ left: meancenter }); } } } menuon = false; meanmenuexist = false; if (meanrevealposition == "right") { meanrevealpos = "right:" + meanrevealpositiondistance + ";left:auto;"; } if (meanrevealposition == "left") { meanrevealpos = "left:" + meanrevealpositiondistance + ";right:auto;"; } // run center function meancentered(); // set all styles for mean-reveal meanstyles = "background:"+meanrevealcolour+";color:"+meanrevealcolour+";"+meanrevealpos; function meaninner() { // get last class name if (jquery($navreveal).is(".meanmenu-reveal.meanclose")) { $navreveal.html(meanmenuclose); } else { $navreveal.html(meanmenuopen); } } //re-instate original nav (and call this on window.width functions) function meanoriginal() { jquery('.mean-bar,.mean-push').remove(); jquery('body').removeclass("mean-container"); jquery(meanmenu).show(); menuon = false; meanmenuexist = false; } //navigation reveal function showmeanmenu() { if (currentwidth <= meanscreenwidth) { meanmenuexist = true; // add class to body so we don't need to worry about media queries here, all css is wrapped in '.mean-container' jquery('body').addclass("mean-container"); jquery('.mean-container').prepend(''); //push meanmenu navigation into .mean-nav var meanmenucontents = jquery(meanmenu).html(); jquery('.mean-nav').html(meanmenucontents); // remove all classes from everything inside meanmenu nav if(meanremoveattrs) { jquery('nav.mean-nav *').each(function() { jquery(this).removeattr("class"); jquery(this).removeattr("id"); }); } // push in a holder div (this can be used if removal of nav is causing layout issues) jquery(meanmenu).before('
'); jquery('.mean-push').css("margin-top",meannavpush); // hide current navigation and reveal mean nav link jquery(meanmenu).hide(); jquery(".meanmenu-reveal").show(); // turn 'x' on or off jquery(meanrevealclass).html(meanmenuopen); $navreveal = jquery(meanrevealclass); //hide mean-nav ul jquery('.mean-nav ul').hide(); // hide sub nav if(meanshowchildren) { // allow expandable sub nav(s) if(meanexpandablechildren){ jquery('.mean-nav ul ul').each(function() { if(jquery(this).children().length){ jquery(this,'li:first').parent().append(''+ meanexpand +''); } }); jquery('.mean-expand').on("click",function(e){ e.preventdefault(); if (jquery(this).hasclass("mean-clicked")) { jquery(this).text(meanexpand); console.log("been clicked"); jquery(this).prev('ul').slideup(300, function(){ }); } else { jquery(this).text(meancontract); jquery(this).prev('ul').slidedown(300, function(){ }); } jquery(this).toggleclass("mean-clicked"); }); } else { jquery('.mean-nav ul ul').show(); } } else { jquery('.mean-nav ul ul').hide(); } // add last class to tidy up borders jquery('.mean-nav ul li').last().addclass('mean-last'); $navreveal.removeclass("meanclose"); jquery($navreveal).click(function(e){ e.preventdefault(); if(menuon == false) { $navreveal.css("text-align", "center"); $navreveal.css("text-indent", "0"); $navreveal.css("font-size", meanmenuclosesize); jquery('.mean-nav ul:first').slidedown(); menuon = true; } else { jquery('.mean-nav ul:first').slideup(); menuon = false; } $navreveal.toggleclass("meanclose"); meaninner(); }); } else { meanoriginal(); } } if (!ismobile) { //reset menu on resize above meanscreenwidth jquery(window).resize(function () { currentwidth = window.innerwidth || document.documentelement.clientwidth; if (currentwidth > meanscreenwidth) { meanoriginal(); } else { meanoriginal(); } if (currentwidth <= meanscreenwidth) { showmeanmenu(); meancentered(); } else { meanoriginal(); } }); } // adjust menu positioning on centered navigation window.onorientationchange = function() { meancentered(); // get browser width currentwidth = window.innerwidth || document.documentelement.clientwidth; if (currentwidth >= meanscreenwidth) { meanoriginal(); } if (currentwidth <= meanscreenwidth) { if (meanmenuexist == false) { showmeanmenu(); } } } // run main menumenu function on load showmeanmenu(); }); }; })(jquery);