forked from meanthemes/meanMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.meanmenu.js
executable file
·169 lines (152 loc) · 6.63 KB
/
jquery.meanmenu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*!
* jQuery meanMenu v2.0.7
* @Copyright (C) 2012-2014 Chris Wharton @ MeanThemes (https://github.com/meanthemes/meanMenu)
*
*/
/*
* 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 <http://gnu.org/licenses/>.
*
* Find more information at http://www.meanthemes.com/plugins/meanmenu/
*
*/
jQuery(document).ready(function($) {
// which menu do you want to mean-alize?
$('#woocommerce_product_categories-2').meanmenu();
// begin with an open the menu
$( ".meanmenu-reveal" ).trigger( "click" );
});
(function ($) {
"use strict";
$.fn.meanmenu = function (options) {
var defaults = {
meanMenuTarget: jQuery(this), // Target the current HTML markup you wish to replace
meanMenuContainer: '.menu-container', // Choose where meanmenu will be placed within the HTML
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
onePage: false, // set to true for one page sites
removeElements: "" // set to hide page elements
};
options = $.extend(defaults, options);
return this.each(function () {
var meanMenu = options.meanMenuTarget;
var meanContainer = options.meanMenuContainer;
var meanMenuCloseSize = options.meanMenuCloseSize;
var meanRevealClass = ".meanmenu-reveal";
var meanShowChildren = options.meanShowChildren;
var meanExpandableChildren = options.meanExpandableChildren;
var meanExpand = options.meanExpand;
var meanContract = options.meanContract;
var meanRemoveAttrs = options.meanRemoveAttrs;
var onePage = options.onePage;
var removeElements = options.removeElements;
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");
}
var menuOn = false;
var meanMenuExist = false;
// set all styles for mean-reveal
var $navreveal = "";
// navigation reveal
var showMeanMenu = function() {
if (1 === 1) {
jQuery(removeElements).addClass('mean-remove');
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(meanContainer).addClass("mean-container");
jQuery('.mean-container').prepend('<div class="mean-bar"><a href="#nav" class="meanmenu-reveal" style="">Show Navigation</a><nav class="mean-nav"></nav></div>');
//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 ul, nav.mean-nav ul *').each(function() {
jQuery(this).removeAttr("class");
jQuery(this).removeAttr("id");
});
}
// hide current navigation and reveal mean nav link
jQuery(meanMenu).hide();
jQuery(".meanmenu-reveal").show();
// turn 'X' on or off
jQuery(meanRevealClass).html();
$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('<a class="mean-expand" href="#" >'+ meanExpand +'</a>');
}
});
jQuery('.mean-expand').on("click",function(e){
e.preventDefault();
if (jQuery(this).hasClass("mean-clicked")) {
jQuery(this).text(meanExpand);
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 ) {
jQuery('.mean-nav ul:first').slideDown();
menuOn = true;
} else {
jQuery('.mean-nav ul:first').slideUp();
menuOn = false;
}
$navreveal.toggleClass("meanclose");
meanInner();
jQuery(removeElements).addClass('mean-remove');
});
// for one page websites, reset all variables...
if ( onePage ) {
jQuery('.mean-nav ul > li > a:first-child').on( "click" , function () {
jQuery('.mean-nav ul:first').slideUp();
menuOn = false;
jQuery($navreveal).toggleClass("meanclose").html(meanMenuOpen);
});
}
} else {
meanOriginal();
}
};
// run main menuMenu function on load
showMeanMenu();
});
};
})(jQuery);