responsive-nav-rails 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06965135b6aeceb6f052ffa15e4861916174a613
|
4
|
+
data.tar.gz: f044ffa9fb2d0c8e33190df6943eb0456e703774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd15a62964756b5d36a44e06c5b16ce189e695a4fc022368ea54c6681ee8a0bf74deb04ae6308d183d361361ca508530ce0cbc410cd7855462316c7ed339e270
|
7
|
+
data.tar.gz: 993c82076846a0bf8e6779234ccb67746082cfd9de26c0c5e471cc1edd3206f961cea1b84b9cb86e69e210f8173488cc66b7d7542dbff311ba9abb146b2134d9
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! responsive-nav.js
|
1
|
+
/*! responsive-nav.js 1.0.23
|
2
2
|
* https://github.com/viljamis/responsive-nav.js
|
3
3
|
* http://responsive-nav.com
|
4
4
|
*
|
@@ -6,424 +6,438 @@
|
|
6
6
|
* Available under the MIT license
|
7
7
|
*/
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
prop
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
9
|
+
(function () {
|
10
|
+
|
11
|
+
"use strict";
|
12
|
+
|
13
|
+
/* exported responsiveNav */
|
14
|
+
var responsiveNav = function (el, options) {
|
15
|
+
|
16
|
+
var computed = !!window.getComputedStyle;
|
17
|
+
|
18
|
+
// getComputedStyle polyfill
|
19
|
+
if (!computed) {
|
20
|
+
window.getComputedStyle = function(el) {
|
21
|
+
this.el = el;
|
22
|
+
this.getPropertyValue = function(prop) {
|
23
|
+
var re = /(\-([a-z]){1})/g;
|
24
|
+
if (prop === "float") {
|
25
|
+
prop = "styleFloat";
|
26
|
+
}
|
27
|
+
if (re.test(prop)) {
|
28
|
+
prop = prop.replace(re, function () {
|
29
|
+
return arguments[2].toUpperCase();
|
30
|
+
});
|
31
|
+
}
|
32
|
+
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
|
33
|
+
};
|
34
|
+
return this;
|
32
35
|
};
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
var nav,
|
38
|
-
opts,
|
39
|
-
navToggle,
|
40
|
-
styleElement = document.createElement("style"),
|
41
|
-
hasAnimFinished,
|
42
|
-
navOpen,
|
43
|
-
|
36
|
+
}
|
37
|
+
/* exported addEvent, removeEvent, getChildren, setAttributes, addClass, removeClass */
|
44
38
|
// fn arg can be an object or a function, thanks to handleEvent
|
45
39
|
// read more at: http://www.thecssninja.com/javascript/handleevent
|
46
|
-
addEvent = function (el, evt, fn, bubble) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
40
|
+
var addEvent = function (el, evt, fn, bubble) {
|
41
|
+
if ("addEventListener" in el) {
|
42
|
+
// BBOS6 doesn't support handleEvent, catch and polyfill
|
43
|
+
try {
|
44
|
+
el.addEventListener(evt, fn, bubble);
|
45
|
+
} catch (e) {
|
46
|
+
if (typeof fn === "object" && fn.handleEvent) {
|
47
|
+
el.addEventListener(evt, function (e) {
|
48
|
+
// Bind fn as this and set first arg as event object
|
49
|
+
fn.handleEvent.call(fn, e);
|
50
|
+
}, bubble);
|
51
|
+
} else {
|
52
|
+
throw e;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
} else if ("attachEvent" in el) {
|
56
|
+
// check if the callback is an object and contains handleEvent
|
52
57
|
if (typeof fn === "object" && fn.handleEvent) {
|
53
|
-
el.
|
54
|
-
// Bind fn as this
|
55
|
-
fn.handleEvent.call(fn
|
56
|
-
}
|
58
|
+
el.attachEvent("on" + evt, function () {
|
59
|
+
// Bind fn as this
|
60
|
+
fn.handleEvent.call(fn);
|
61
|
+
});
|
57
62
|
} else {
|
58
|
-
|
63
|
+
el.attachEvent("on" + evt, fn);
|
59
64
|
}
|
60
65
|
}
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
})
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
el.removeEventListener(evt, fn, bubble);
|
78
|
-
} catch (e) {
|
66
|
+
},
|
67
|
+
|
68
|
+
removeEvent = function (el, evt, fn, bubble) {
|
69
|
+
if ("removeEventListener" in el) {
|
70
|
+
try {
|
71
|
+
el.removeEventListener(evt, fn, bubble);
|
72
|
+
} catch (e) {
|
73
|
+
if (typeof fn === "object" && fn.handleEvent) {
|
74
|
+
el.removeEventListener(evt, function (e) {
|
75
|
+
fn.handleEvent.call(fn, e);
|
76
|
+
}, bubble);
|
77
|
+
} else {
|
78
|
+
throw e;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
} else if ("detachEvent" in el) {
|
79
82
|
if (typeof fn === "object" && fn.handleEvent) {
|
80
|
-
el.
|
81
|
-
fn.handleEvent.call(fn
|
82
|
-
}
|
83
|
+
el.detachEvent("on" + evt, function () {
|
84
|
+
fn.handleEvent.call(fn);
|
85
|
+
});
|
83
86
|
} else {
|
84
|
-
|
87
|
+
el.detachEvent("on" + evt, fn);
|
85
88
|
}
|
86
89
|
}
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
} else {
|
93
|
-
el.detachEvent("on" + evt, fn);
|
90
|
+
},
|
91
|
+
|
92
|
+
getChildren = function (e) {
|
93
|
+
if (e.children.length < 1) {
|
94
|
+
throw new Error("The Nav container has no containing elements");
|
94
95
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
// Store all children in array
|
103
|
-
var children = [];
|
104
|
-
// Loop through children and store in array if child != TextNode
|
105
|
-
for (var i = 0; i < e.children.length; i++) {
|
106
|
-
if (e.children[i].nodeType === 1) {
|
107
|
-
children.push(e.children[i]);
|
96
|
+
// Store all children in array
|
97
|
+
var children = [];
|
98
|
+
// Loop through children and store in array if child != TextNode
|
99
|
+
for (var i = 0; i < e.children.length; i++) {
|
100
|
+
if (e.children[i].nodeType === 1) {
|
101
|
+
children.push(e.children[i]);
|
102
|
+
}
|
108
103
|
}
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
}
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
el.className = el.className.replace(reg, " ").replace(/(^\s*)|(\s*$)/g,"");
|
129
|
-
},
|
130
|
-
|
131
|
-
ResponsiveNav = function (el, options) {
|
132
|
-
var i;
|
133
|
-
|
134
|
-
// Default options
|
135
|
-
this.options = {
|
136
|
-
animate: true, // Boolean: Use CSS3 transitions, true or false
|
137
|
-
transition: 250, // Integer: Speed of the transition, in milliseconds
|
138
|
-
label: "Menu", // String: Label for the navigation toggle
|
139
|
-
insert: "after", // String: Insert the toggle before or after the navigation
|
140
|
-
customToggle: "", // Selector: Specify the ID of a custom toggle
|
141
|
-
openPos: "relative", // String: Position of the opened nav, relative or static
|
142
|
-
jsClass: "js", // String: 'JS enabled' class which is added to <html> el
|
143
|
-
init: function(){}, // Function: Init callback
|
144
|
-
open: function(){}, // Function: Open callback
|
145
|
-
close: function(){} // Function: Close callback
|
104
|
+
return children;
|
105
|
+
},
|
106
|
+
|
107
|
+
setAttributes = function (el, attrs) {
|
108
|
+
for (var key in attrs) {
|
109
|
+
el.setAttribute(key, attrs[key]);
|
110
|
+
}
|
111
|
+
},
|
112
|
+
|
113
|
+
addClass = function (el, cls) {
|
114
|
+
if (el.className.indexOf(cls) !== 0) {
|
115
|
+
el.className += " " + cls;
|
116
|
+
el.className = el.className.replace(/(^\s*)|(\s*$)/g,"");
|
117
|
+
}
|
118
|
+
},
|
119
|
+
|
120
|
+
removeClass = function (el, cls) {
|
121
|
+
var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
|
122
|
+
el.className = el.className.replace(reg, " ").replace(/(^\s*)|(\s*$)/g,"");
|
146
123
|
};
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
this.
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
nav.removeAttribute("aria-hidden");
|
187
|
-
nav = null;
|
188
|
-
|
189
|
-
removeEvent(window, "resize", this, false);
|
190
|
-
removeEvent(document.body, "touchmove", this, false);
|
191
|
-
removeEvent(navToggle, "touchstart", this, false);
|
192
|
-
removeEvent(navToggle, "touchend", this, false);
|
193
|
-
removeEvent(navToggle, "mouseup", this, false);
|
194
|
-
removeEvent(navToggle, "keyup", this, false);
|
195
|
-
removeEvent(navToggle, "click", this, false);
|
196
|
-
|
197
|
-
if (!opts.customToggle) {
|
198
|
-
navToggle.parentNode.removeChild(navToggle);
|
199
|
-
} else {
|
200
|
-
navToggle.removeAttribute("aria-hidden");
|
201
|
-
}
|
202
|
-
},
|
203
|
-
|
204
|
-
toggle: function () {
|
205
|
-
if (hasAnimFinished === true) {
|
206
|
-
if (!navOpen) {
|
207
|
-
removeClass(nav, "closed");
|
208
|
-
addClass(nav, "opened");
|
209
|
-
nav.style.position = opts.openPos;
|
210
|
-
setAttributes(nav, {"aria-hidden": "false"});
|
211
|
-
|
212
|
-
navOpen = true;
|
213
|
-
opts.open();
|
124
|
+
|
125
|
+
var nav,
|
126
|
+
opts,
|
127
|
+
navToggle,
|
128
|
+
styleElement = document.createElement("style"),
|
129
|
+
hasAnimFinished,
|
130
|
+
navOpen;
|
131
|
+
|
132
|
+
var ResponsiveNav = function (el, options) {
|
133
|
+
var i;
|
134
|
+
|
135
|
+
// Default options
|
136
|
+
this.options = {
|
137
|
+
animate: true, // Boolean: Use CSS3 transitions, true or false
|
138
|
+
transition: 250, // Integer: Speed of the transition, in milliseconds
|
139
|
+
label: "Menu", // String: Label for the navigation toggle
|
140
|
+
insert: "after", // String: Insert the toggle before or after the navigation
|
141
|
+
customToggle: "", // Selector: Specify the ID of a custom toggle
|
142
|
+
openPos: "relative", // String: Position of the opened nav, relative or static
|
143
|
+
jsClass: "js", // String: 'JS enabled' class which is added to <html> el
|
144
|
+
init: function(){}, // Function: Init callback
|
145
|
+
open: function(){}, // Function: Open callback
|
146
|
+
close: function(){} // Function: Close callback
|
147
|
+
};
|
148
|
+
|
149
|
+
// User defined options
|
150
|
+
for (i in options) {
|
151
|
+
this.options[i] = options[i];
|
152
|
+
}
|
153
|
+
|
154
|
+
// Adds "js" class for <html>
|
155
|
+
addClass(document.documentElement, this.options.jsClass);
|
156
|
+
|
157
|
+
// Wrapper
|
158
|
+
this.wrapperEl = el.replace("#", "");
|
159
|
+
if (document.getElementById(this.wrapperEl)) {
|
160
|
+
this.wrapper = document.getElementById(this.wrapperEl);
|
161
|
+
} else if (document.querySelector(this.wrapperEl)) {
|
162
|
+
this.wrapper = document.querySelector(this.wrapperEl);
|
214
163
|
} else {
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
164
|
+
// If el doesn't exists, stop here.
|
165
|
+
throw new Error("The nav element you are trying to select doesn't exist");
|
166
|
+
}
|
167
|
+
|
168
|
+
// Inner wrapper
|
169
|
+
this.wrapper.inner = getChildren(this.wrapper);
|
170
|
+
|
171
|
+
// For minification
|
172
|
+
opts = this.options;
|
173
|
+
nav = this.wrapper;
|
174
|
+
|
175
|
+
// Init
|
176
|
+
this._init(this);
|
177
|
+
};
|
178
|
+
|
179
|
+
ResponsiveNav.prototype = {
|
180
|
+
|
181
|
+
// Public methods
|
182
|
+
destroy: function () {
|
183
|
+
this._removeStyles();
|
184
|
+
removeClass(nav, "closed");
|
185
|
+
removeClass(nav, "opened");
|
186
|
+
removeClass(nav, "nav-collapse");
|
187
|
+
nav.removeAttribute("style");
|
188
|
+
nav.removeAttribute("aria-hidden");
|
189
|
+
nav = null;
|
190
|
+
|
191
|
+
removeEvent(window, "resize", this, false);
|
192
|
+
removeEvent(document.body, "touchmove", this, false);
|
193
|
+
removeEvent(navToggle, "touchstart", this, false);
|
194
|
+
removeEvent(navToggle, "touchend", this, false);
|
195
|
+
removeEvent(navToggle, "mouseup", this, false);
|
196
|
+
removeEvent(navToggle, "keyup", this, false);
|
197
|
+
removeEvent(navToggle, "click", this, false);
|
198
|
+
|
199
|
+
if (!opts.customToggle) {
|
200
|
+
navToggle.parentNode.removeChild(navToggle);
|
201
|
+
} else {
|
202
|
+
navToggle.removeAttribute("aria-hidden");
|
203
|
+
}
|
204
|
+
},
|
205
|
+
|
206
|
+
toggle: function () {
|
207
|
+
if (hasAnimFinished === true) {
|
208
|
+
if (!navOpen) {
|
209
|
+
removeClass(nav, "closed");
|
210
|
+
addClass(nav, "opened");
|
211
|
+
nav.style.position = opts.openPos;
|
212
|
+
setAttributes(nav, {"aria-hidden": "false"});
|
213
|
+
|
214
|
+
navOpen = true;
|
215
|
+
opts.open();
|
225
216
|
} else {
|
217
|
+
removeClass(nav, "opened");
|
218
|
+
addClass(nav, "closed");
|
219
|
+
setAttributes(nav, {"aria-hidden": "true"});
|
220
|
+
|
221
|
+
if (opts.animate) {
|
222
|
+
hasAnimFinished = false;
|
223
|
+
setTimeout(function () {
|
224
|
+
nav.style.position = "absolute";
|
225
|
+
hasAnimFinished = true;
|
226
|
+
}, opts.transition + 10);
|
227
|
+
} else {
|
228
|
+
nav.style.position = "absolute";
|
229
|
+
}
|
230
|
+
|
231
|
+
navOpen = false;
|
232
|
+
opts.close();
|
233
|
+
}
|
234
|
+
}
|
235
|
+
},
|
236
|
+
|
237
|
+
resize: function () {
|
238
|
+
if (window.getComputedStyle(navToggle, null).getPropertyValue("display") !== "none") {
|
239
|
+
setAttributes(navToggle, {"aria-hidden": "false"});
|
240
|
+
|
241
|
+
// If the navigation is hidden
|
242
|
+
if (nav.className.match(/(^|\s)closed(\s|$)/)) {
|
243
|
+
setAttributes(nav, {"aria-hidden": "true"});
|
226
244
|
nav.style.position = "absolute";
|
227
245
|
}
|
228
|
-
|
229
|
-
|
230
|
-
|
246
|
+
|
247
|
+
this._createStyles();
|
248
|
+
this._calcHeight();
|
249
|
+
} else {
|
250
|
+
setAttributes(navToggle, {"aria-hidden": "true"});
|
251
|
+
setAttributes(nav, {"aria-hidden": "false"});
|
252
|
+
nav.style.position = opts.openPos;
|
253
|
+
this._removeStyles();
|
231
254
|
}
|
232
|
-
}
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
255
|
+
},
|
256
|
+
|
257
|
+
handleEvent: function (e) {
|
258
|
+
var evt = e || window.event;
|
259
|
+
|
260
|
+
switch (evt.type) {
|
261
|
+
case "touchstart":
|
262
|
+
this._onTouchStart(evt);
|
263
|
+
break;
|
264
|
+
case "touchmove":
|
265
|
+
this._onTouchMove(evt);
|
266
|
+
break;
|
267
|
+
case "touchend":
|
268
|
+
case "mouseup":
|
269
|
+
this._onTouchEnd(evt);
|
270
|
+
break;
|
271
|
+
case "click":
|
272
|
+
this._preventDefault(evt);
|
273
|
+
break;
|
274
|
+
case "keyup":
|
275
|
+
this._onKeyUp(evt);
|
276
|
+
break;
|
277
|
+
case "resize":
|
278
|
+
this.resize(evt);
|
279
|
+
break;
|
243
280
|
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
this
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
this
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
_createStyles: function () {
|
305
|
-
if (!styleElement.parentNode) {
|
306
|
-
styleElement.type = "text/css";
|
307
|
-
document.getElementsByTagName("head")[0].appendChild(styleElement);
|
308
|
-
}
|
309
|
-
},
|
310
|
-
|
311
|
-
_removeStyles: function () {
|
312
|
-
if (styleElement.parentNode) {
|
313
|
-
styleElement.parentNode.removeChild(styleElement);
|
314
|
-
}
|
315
|
-
},
|
316
|
-
|
317
|
-
_createToggle: function () {
|
318
|
-
if (!opts.customToggle) {
|
319
|
-
var toggle = document.createElement("a");
|
320
|
-
toggle.innerHTML = opts.label;
|
321
|
-
setAttributes(toggle, {
|
322
|
-
"href": "#",
|
323
|
-
"class": "nav-toggle"
|
324
|
-
});
|
325
|
-
|
326
|
-
if (opts.insert === "after") {
|
327
|
-
nav.parentNode.insertBefore(toggle, nav.nextSibling);
|
281
|
+
},
|
282
|
+
|
283
|
+
// Private methods
|
284
|
+
_init: function () {
|
285
|
+
addClass(nav, "nav-collapse");
|
286
|
+
addClass(nav, "closed");
|
287
|
+
hasAnimFinished = true;
|
288
|
+
navOpen = false;
|
289
|
+
|
290
|
+
this._createToggle();
|
291
|
+
this._transitions();
|
292
|
+
this.resize();
|
293
|
+
|
294
|
+
// IE8 hack
|
295
|
+
var self = this;
|
296
|
+
setTimeout(function () {
|
297
|
+
self.resize();
|
298
|
+
}, 20);
|
299
|
+
|
300
|
+
addEvent(window, "resize", this, false);
|
301
|
+
addEvent(document.body, "touchmove", this, false);
|
302
|
+
addEvent(navToggle, "touchstart", this, false);
|
303
|
+
addEvent(navToggle, "touchend", this, false);
|
304
|
+
addEvent(navToggle, "mouseup", this, false);
|
305
|
+
addEvent(navToggle, "keyup", this, false);
|
306
|
+
addEvent(navToggle, "click", this, false);
|
307
|
+
|
308
|
+
// Init callback
|
309
|
+
opts.init();
|
310
|
+
},
|
311
|
+
|
312
|
+
_createStyles: function () {
|
313
|
+
if (!styleElement.parentNode) {
|
314
|
+
styleElement.type = "text/css";
|
315
|
+
document.getElementsByTagName("head")[0].appendChild(styleElement);
|
316
|
+
}
|
317
|
+
},
|
318
|
+
|
319
|
+
_removeStyles: function () {
|
320
|
+
if (styleElement.parentNode) {
|
321
|
+
styleElement.parentNode.removeChild(styleElement);
|
322
|
+
}
|
323
|
+
},
|
324
|
+
|
325
|
+
_createToggle: function () {
|
326
|
+
if (!opts.customToggle) {
|
327
|
+
var toggle = document.createElement("a");
|
328
|
+
toggle.innerHTML = opts.label;
|
329
|
+
setAttributes(toggle, {
|
330
|
+
"href": "#",
|
331
|
+
"class": "nav-toggle"
|
332
|
+
});
|
333
|
+
|
334
|
+
if (opts.insert === "after") {
|
335
|
+
nav.parentNode.insertBefore(toggle, nav.nextSibling);
|
336
|
+
} else {
|
337
|
+
nav.parentNode.insertBefore(toggle, nav);
|
338
|
+
}
|
339
|
+
|
340
|
+
navToggle = toggle;
|
328
341
|
} else {
|
329
|
-
|
342
|
+
var toggleEl = opts.customToggle.replace("#", "");
|
343
|
+
|
344
|
+
if (document.getElementById(toggleEl)) {
|
345
|
+
navToggle = document.getElementById(toggleEl);
|
346
|
+
} else if (document.querySelector(toggleEl)) {
|
347
|
+
navToggle = document.querySelector(toggleEl);
|
348
|
+
} else {
|
349
|
+
throw new Error("The custom nav toggle you are trying to select doesn't exist");
|
350
|
+
}
|
330
351
|
}
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
navToggle = document.getElementById(toggleEl);
|
338
|
-
} else if (document.querySelector(toggleEl)) {
|
339
|
-
navToggle = document.querySelector(toggleEl);
|
352
|
+
},
|
353
|
+
|
354
|
+
_preventDefault: function(e) {
|
355
|
+
if (e.preventDefault) {
|
356
|
+
e.preventDefault();
|
357
|
+
e.stopPropagation();
|
340
358
|
} else {
|
341
|
-
|
359
|
+
e.returnValue = false;
|
342
360
|
}
|
343
|
-
}
|
344
|
-
|
345
|
-
|
346
|
-
_preventDefault: function(e) {
|
347
|
-
if (e.preventDefault) {
|
348
|
-
e.preventDefault();
|
361
|
+
},
|
362
|
+
|
363
|
+
_onTouchStart: function (e) {
|
349
364
|
e.stopPropagation();
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
e
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
}
|
368
|
-
},
|
369
|
-
|
370
|
-
_onTouchEnd: function (e) {
|
371
|
-
this._preventDefault(e);
|
372
|
-
if (!this.touchHasMoved) {
|
373
|
-
if (e.type === "touchend") {
|
374
|
-
this.toggle(e);
|
375
|
-
// Prevent click on the underlying menu on Android 2.3
|
376
|
-
var that = this;
|
377
|
-
nav.addEventListener("click", that._preventDefault, true);
|
378
|
-
setTimeout(function () {
|
379
|
-
nav.removeEventListener("click", that._preventDefault, true);
|
380
|
-
}, opts.transition + 100);
|
381
|
-
return;
|
382
|
-
} else {
|
383
|
-
var evt = e || window.event;
|
384
|
-
// If it isn't a right click
|
385
|
-
if (!(evt.which === 3 || evt.button === 2)) {
|
365
|
+
this.startX = e.touches[0].clientX;
|
366
|
+
this.startY = e.touches[0].clientY;
|
367
|
+
this.touchHasMoved = false;
|
368
|
+
removeEvent(navToggle, "mouseup", this, false);
|
369
|
+
},
|
370
|
+
|
371
|
+
_onTouchMove: function (e) {
|
372
|
+
if (Math.abs(e.touches[0].clientX - this.startX) > 10 ||
|
373
|
+
Math.abs(e.touches[0].clientY - this.startY) > 10) {
|
374
|
+
this.touchHasMoved = true;
|
375
|
+
}
|
376
|
+
},
|
377
|
+
|
378
|
+
_onTouchEnd: function (e) {
|
379
|
+
this._preventDefault(e);
|
380
|
+
if (!this.touchHasMoved) {
|
381
|
+
if (e.type === "touchend") {
|
386
382
|
this.toggle(e);
|
383
|
+
// Prevent click on the underlying menu on Android 2.3
|
384
|
+
var that = this;
|
385
|
+
nav.addEventListener("click", that._preventDefault, true);
|
386
|
+
setTimeout(function () {
|
387
|
+
nav.removeEventListener("click", that._preventDefault, true);
|
388
|
+
}, opts.transition + 100);
|
389
|
+
return;
|
390
|
+
} else {
|
391
|
+
var evt = e || window.event;
|
392
|
+
// If it isn't a right click
|
393
|
+
if (!(evt.which === 3 || evt.button === 2)) {
|
394
|
+
this.toggle(e);
|
395
|
+
}
|
387
396
|
}
|
388
397
|
}
|
398
|
+
},
|
399
|
+
|
400
|
+
_onKeyUp: function (e) {
|
401
|
+
var evt = e || window.event;
|
402
|
+
if (evt.keyCode === 13) {
|
403
|
+
this.toggle(e);
|
404
|
+
}
|
405
|
+
},
|
406
|
+
|
407
|
+
_transitions: function () {
|
408
|
+
if (opts.animate) {
|
409
|
+
var objStyle = nav.style,
|
410
|
+
transition = "max-height " + opts.transition + "ms";
|
411
|
+
|
412
|
+
objStyle.WebkitTransition = transition;
|
413
|
+
objStyle.MozTransition = transition;
|
414
|
+
objStyle.OTransition = transition;
|
415
|
+
objStyle.transition = transition;
|
416
|
+
}
|
417
|
+
},
|
418
|
+
|
419
|
+
_calcHeight: function () {
|
420
|
+
var savedHeight = 0;
|
421
|
+
for (var i = 0; i < nav.inner.length; i++) {
|
422
|
+
savedHeight += nav.inner[i].offsetHeight;
|
423
|
+
}
|
424
|
+
var innerStyles = ".nav-collapse.opened{max-height:" + savedHeight + "px}";
|
425
|
+
|
426
|
+
if (styleElement.styleSheet) {
|
427
|
+
styleElement.styleSheet.cssText = innerStyles;
|
428
|
+
} else {
|
429
|
+
styleElement.innerHTML = innerStyles;
|
430
|
+
}
|
431
|
+
|
432
|
+
innerStyles = "";
|
389
433
|
}
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
}
|
397
|
-
},
|
398
|
-
|
399
|
-
_transitions: function () {
|
400
|
-
if (opts.animate) {
|
401
|
-
var objStyle = nav.style,
|
402
|
-
transition = "max-height " + opts.transition + "ms";
|
403
|
-
|
404
|
-
objStyle.WebkitTransition = transition;
|
405
|
-
objStyle.MozTransition = transition;
|
406
|
-
objStyle.OTransition = transition;
|
407
|
-
objStyle.transition = transition;
|
408
|
-
}
|
409
|
-
},
|
410
|
-
|
411
|
-
_calcHeight: function () {
|
412
|
-
var savedHeight = 0;
|
413
|
-
for (var i = 0; i < nav.inner.length; i++) {
|
414
|
-
savedHeight += nav.inner[i].offsetHeight;
|
415
|
-
}
|
416
|
-
var innerStyles = ".nav-collapse.opened{max-height:" + savedHeight + "px}";
|
417
|
-
|
418
|
-
if (styleElement.styleSheet) {
|
419
|
-
styleElement.styleSheet.cssText = innerStyles;
|
420
|
-
} else {
|
421
|
-
styleElement.innerHTML = innerStyles;
|
422
|
-
}
|
434
|
+
|
435
|
+
};
|
436
|
+
|
437
|
+
return new ResponsiveNav(el, options);
|
438
|
+
|
439
|
+
};
|
423
440
|
|
424
|
-
|
425
|
-
}
|
441
|
+
window.responsiveNav = responsiveNav;
|
426
442
|
|
427
|
-
|
428
|
-
return new ResponsiveNav(el, options);
|
429
|
-
};
|
443
|
+
}());
|
@@ -0,0 +1 @@
|
|
1
|
+
!function(){"use strict";var a=function(a,b){var c=!!window.getComputedStyle;c||(window.getComputedStyle=function(a){return this.el=a,this.getPropertyValue=function(b){var c=/(\-([a-z]){1})/g;return"float"===b&&(b="styleFloat"),c.test(b)&&(b=b.replace(c,function(){return arguments[2].toUpperCase()})),a.currentStyle[b]?a.currentStyle[b]:null},this});var d,e,f,g,h,i=function(a,b,c,d){if("addEventListener"in a)try{a.addEventListener(b,c,d)}catch(e){if("object"!=typeof c||!c.handleEvent)throw e;a.addEventListener(b,function(a){c.handleEvent.call(c,a)},d)}else"attachEvent"in a&&("object"==typeof c&&c.handleEvent?a.attachEvent("on"+b,function(){c.handleEvent.call(c)}):a.attachEvent("on"+b,c))},j=function(a,b,c,d){if("removeEventListener"in a)try{a.removeEventListener(b,c,d)}catch(e){if("object"!=typeof c||!c.handleEvent)throw e;a.removeEventListener(b,function(a){c.handleEvent.call(c,a)},d)}else"detachEvent"in a&&("object"==typeof c&&c.handleEvent?a.detachEvent("on"+b,function(){c.handleEvent.call(c)}):a.detachEvent("on"+b,c))},k=function(a){if(a.children.length<1)throw new Error("The Nav container has no containing elements");for(var b=[],c=0;c<a.children.length;c++)1===a.children[c].nodeType&&b.push(a.children[c]);return b},l=function(a,b){for(var c in b)a.setAttribute(c,b[c])},m=function(a,b){0!==a.className.indexOf(b)&&(a.className+=" "+b,a.className=a.className.replace(/(^\s*)|(\s*$)/g,""))},n=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)");a.className=a.className.replace(c," ").replace(/(^\s*)|(\s*$)/g,"")},o=document.createElement("style"),p=function(a,b){var c;this.options={animate:!0,transition:250,label:"Menu",insert:"after",customToggle:"",openPos:"relative",jsClass:"js",init:function(){},open:function(){},close:function(){}};for(c in b)this.options[c]=b[c];if(m(document.documentElement,this.options.jsClass),this.wrapperEl=a.replace("#",""),document.getElementById(this.wrapperEl))this.wrapper=document.getElementById(this.wrapperEl);else{if(!document.querySelector(this.wrapperEl))throw new Error("The nav element you are trying to select doesn't exist");this.wrapper=document.querySelector(this.wrapperEl)}this.wrapper.inner=k(this.wrapper),e=this.options,d=this.wrapper,this._init(this)};return p.prototype={destroy:function(){this._removeStyles(),n(d,"closed"),n(d,"opened"),n(d,"nav-collapse"),d.removeAttribute("style"),d.removeAttribute("aria-hidden"),d=null,j(window,"resize",this,!1),j(document.body,"touchmove",this,!1),j(f,"touchstart",this,!1),j(f,"touchend",this,!1),j(f,"mouseup",this,!1),j(f,"keyup",this,!1),j(f,"click",this,!1),e.customToggle?f.removeAttribute("aria-hidden"):f.parentNode.removeChild(f)},toggle:function(){g===!0&&(h?(n(d,"opened"),m(d,"closed"),l(d,{"aria-hidden":"true"}),e.animate?(g=!1,setTimeout(function(){d.style.position="absolute",g=!0},e.transition+10)):d.style.position="absolute",h=!1,e.close()):(n(d,"closed"),m(d,"opened"),d.style.position=e.openPos,l(d,{"aria-hidden":"false"}),h=!0,e.open()))},resize:function(){"none"!==window.getComputedStyle(f,null).getPropertyValue("display")?(l(f,{"aria-hidden":"false"}),d.className.match(/(^|\s)closed(\s|$)/)&&(l(d,{"aria-hidden":"true"}),d.style.position="absolute"),this._createStyles(),this._calcHeight()):(l(f,{"aria-hidden":"true"}),l(d,{"aria-hidden":"false"}),d.style.position=e.openPos,this._removeStyles())},handleEvent:function(a){var b=a||window.event;switch(b.type){case"touchstart":this._onTouchStart(b);break;case"touchmove":this._onTouchMove(b);break;case"touchend":case"mouseup":this._onTouchEnd(b);break;case"click":this._preventDefault(b);break;case"keyup":this._onKeyUp(b);break;case"resize":this.resize(b)}},_init:function(){m(d,"nav-collapse"),m(d,"closed"),g=!0,h=!1,this._createToggle(),this._transitions(),this.resize();var a=this;setTimeout(function(){a.resize()},20),i(window,"resize",this,!1),i(document.body,"touchmove",this,!1),i(f,"touchstart",this,!1),i(f,"touchend",this,!1),i(f,"mouseup",this,!1),i(f,"keyup",this,!1),i(f,"click",this,!1),e.init()},_createStyles:function(){o.parentNode||(o.type="text/css",document.getElementsByTagName("head")[0].appendChild(o))},_removeStyles:function(){o.parentNode&&o.parentNode.removeChild(o)},_createToggle:function(){if(e.customToggle){var a=e.customToggle.replace("#","");if(document.getElementById(a))f=document.getElementById(a);else{if(!document.querySelector(a))throw new Error("The custom nav toggle you are trying to select doesn't exist");f=document.querySelector(a)}}else{var b=document.createElement("a");b.innerHTML=e.label,l(b,{href:"#","class":"nav-toggle"}),"after"===e.insert?d.parentNode.insertBefore(b,d.nextSibling):d.parentNode.insertBefore(b,d),f=b}},_preventDefault:function(a){a.preventDefault?(a.preventDefault(),a.stopPropagation()):a.returnValue=!1},_onTouchStart:function(a){a.stopPropagation(),this.startX=a.touches[0].clientX,this.startY=a.touches[0].clientY,this.touchHasMoved=!1,j(f,"mouseup",this,!1)},_onTouchMove:function(a){(Math.abs(a.touches[0].clientX-this.startX)>10||Math.abs(a.touches[0].clientY-this.startY)>10)&&(this.touchHasMoved=!0)},_onTouchEnd:function(a){if(this._preventDefault(a),!this.touchHasMoved){if("touchend"===a.type){this.toggle(a);var b=this;return d.addEventListener("click",b._preventDefault,!0),setTimeout(function(){d.removeEventListener("click",b._preventDefault,!0)},e.transition+100),void 0}var c=a||window.event;3!==c.which&&2!==c.button&&this.toggle(a)}},_onKeyUp:function(a){var b=a||window.event;13===b.keyCode&&this.toggle(a)},_transitions:function(){if(e.animate){var a=d.style,b="max-height "+e.transition+"ms";a.WebkitTransition=b,a.MozTransition=b,a.OTransition=b,a.transition=b}},_calcHeight:function(){for(var a=0,b=0;b<d.inner.length;b++)a+=d.inner[b].offsetHeight;var c=".nav-collapse.opened{max-height:"+a+"px}";o.styleSheet?o.styleSheet.cssText=c:o.innerHTML=c,c=""}},new p(a,b)};window.responsiveNav=a}();
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responsive-nav-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas McNiven
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: responsive-nav.com for the rails asset pipeline
|
14
14
|
email:
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- responsive-nav-rails.gemspec
|
29
29
|
- vendor/assets/.DS_Store
|
30
30
|
- vendor/assets/javascripts/responsive-nav.js
|
31
|
+
- vendor/assets/javascripts/responsive-nav.min.js
|
31
32
|
- vendor/assets/stylesheets/responsive-nav.css
|
32
33
|
homepage: https://github.com/vevix/responsive-nav-rails
|
33
34
|
licenses:
|