forked from invmatt/Droplet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdroplet.jquery.js
148 lines (108 loc) · 5.59 KB
/
droplet.jquery.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
/*
* Droplet.js / 1.2.3
* https://github.com/invmatt/Droplet
*/
(function($) {
$.droplet = function(selector, settings) {
var config = {
'buttonID': 'droplet-menu', // The default button ID
'mode': 'droplet-responsive', // Class added once the smaller breakpoint has been reached
'smallScreen': '768',
'largeScreen': '769',
'Modernizr': false, // Adds support for Modernizr Media Queries (recommended)
'subNav': false, // If you have sub-navigation set this to true
'subClass': '', // Class of the containing sub navigation UL
'panel': false, // Create a panel style menu
'panelPosition': '250',
'shortScreen': '', // Optionally set a height at which the screen size could be considered too small for a fixed-position nav. Adds class of 'droplet-short' if specified
'unit': 'px' // Choose the unit for the Modernizr media queries
};
if (settings) { $.extend(config, settings); }
// Set some basic vars
var obj = $(selector);
var child = obj.children('ul');
var childOfChild = obj.children('li > ul');
var menuSize = "";
var i = 0;
var navLocation = (obj).parent();
var animateSpeed = 500;
$("body").addClass("droplet-enabled");
$(function() { windowSize(); });
$(window).resize(windowSize);
function windowSize() {
if ((config.Modernizr == false && $(window).width() <= config.smallScreen) || (config.Modernizr == true && Modernizr.mq('only screen and (max-width : ' + config.smallScreen + config.unit + ')'))) {
if (menuSize != "small") {
menuSize = "small";
$(obj).addClass(config.mode);
// Panel Style
if (!config.panel) {
$(obj).prepend('<div id="' + config.buttonID + '">Main Menu</div>');
$("#" + config.buttonID + "").click(function() {
if ($(child).css('display') == 'none') {
$(child).slideDown("fast");
$("#" + config.buttonID + "").addClass("active");
}
else if ($(child).css('display') == 'block') {
$(child).slideUp("fast");
$("#" + config.buttonID + "").removeClass("active");
}
});
}
if ((config.shortScreen != '' && config.Modernizr == false && $(window).height() <= config.shortScreen) || (config.shortScreen != '' && config.Modernizr == true && Modernizr.mq('only screen and (max-height : ' + config.shortScreen + config.unit + ')'))) {
$(obj).addClass('droplet-short');
}
if (config.panel) {
$("body").prepend($(obj));
$("body").prepend('<div id="' + config.buttonID + '">Main Menu</div>');
$(obj).addClass("panel-closed");
$(obj).css({
width: '' + config.panelPosition + 'px',
left: '-' + config.panelPosition + 'px',
position: "fixed"
});
$("#" + config.buttonID + "").click(function() {
if ($(obj).hasClass('panel-open')) {
$(obj).removeClass('panel-open');
$(obj).addClass('panel-closed');
$(obj).animate({
left: '-' + config.panelPosition + 'px'
}, animateSpeed);
$("body").animate({
left: '0'
}, animateSpeed);
$(child).css("display", "none");
} else {
$(obj).removeClass('panel-closed');
$(obj).addClass('panel-open');
$(obj).animate({
left: '0px'
}, animateSpeed);
$("body").animate({
left: '' + config.panelPosition + 'px'
}, animateSpeed);
$(child).css("display", "block");
}
});
}
$(child).css('display', 'none');
if (config.subNav) {
// WIP
}
}
}
else if ((config.Modernizr == false && $(window).width() >= config.largeScreen) || (config.Modernizr == true && Modernizr.mq('only screen and (min-width : ' + config.largeScreen + config.unit + ')'))) {
if (menuSize != "large") {
menuSize = "large";
$(child).css('display', 'block');
$(obj).removeClass(config.mode);
$("#" + config.buttonID + "").remove();
if (config.panel) {
$(navLocation).append($(obj));
$(obj).removeAttr('style')
}
}
}
}
return this;
};
})(jQuery);