vendor/assets/javascripts/responsive-nav.js in responsive-nav-rails-1.0.14 vs vendor/assets/javascripts/responsive-nav.js in responsive-nav-rails-1.0.15
- old
+ new
@@ -1,6 +1,6 @@
-/*! responsive-nav.js v1.0.14
+/*! responsive-nav.js v1.0.15
* https://github.com/viljamis/responsive-nav.js
* http://responsive-nav.com
*
* Copyright (c) 2013 @viljamis
* Available under the MIT license
@@ -35,12 +35,10 @@
}
var nav,
opts,
navToggle,
- docEl = document.documentElement,
- head = document.getElementsByTagName("head")[0],
styleElement = document.createElement("style"),
navOpen = false,
// fn arg can be an object or a function, thanks to handleEvent
// read more at: http://www.thecssninja.com/javascript/handleevent
@@ -94,17 +92,23 @@
el.detachEvent("on" + evt, fn);
}
}
},
- getFirstChild = function (e) {
- var firstChild = e.firstChild;
- // skip TextNodes
- while (firstChild !== null && firstChild.nodeType !== 1) {
- firstChild = firstChild.nextSibling;
+ getChildren = function (e) {
+ if (e.children.length < 1) {
+ throw new Error("The Nav container has no containing elements");
}
- return firstChild;
+ // Store all children in array
+ var children = [];
+ // Loop through children and store in array if child != TextNode
+ for (var i = 0; i < e.children.length; i++) {
+ if (e.children[i].nodeType === 1) {
+ children.push(e.children[i]);
+ }
+ }
+ return children;
},
setAttributes = function (el, attrs) {
for (var key in attrs) {
el.setAttribute(key, attrs[key]);
@@ -142,11 +146,11 @@
for (i in options) {
this.options[i] = options[i];
}
// Adds "js" class for <html>
- addClass(docEl, this.options.jsClass);
+ addClass(document.documentElement, this.options.jsClass);
// Wrapper
this.wrapperEl = el.replace("#", "");
if (document.getElementById(this.wrapperEl)) {
this.wrapper = document.getElementById(this.wrapperEl);
@@ -154,11 +158,11 @@
// If el doesn't exists, stop here.
throw new Error("The nav element you are trying to select doesn't exist");
}
// Inner wrapper
- this.wrapper.inner = getFirstChild(this.wrapper);
+ this.wrapper.inner = getChildren(this.wrapper);
// For minification
opts = this.options;
nav = this.wrapper;
@@ -262,11 +266,11 @@
addEvent(navToggle, "click", this, false);
},
_createStyles: function () {
if (!styleElement.parentNode) {
- head.appendChild(styleElement);
+ document.getElementsByTagName("head")[0].appendChild(styleElement);
}
},
_removeStyles: function () {
if (styleElement.parentNode) {
@@ -359,11 +363,15 @@
objStyle.transition = transition;
}
},
_calcHeight: function () {
- var savedHeight = nav.inner.offsetHeight,
- innerStyles = "#" + this.wrapperEl + ".opened{max-height:" + savedHeight + "px}";
+ var savedHeight = 0;
+ for (var i = 0; i < nav.inner.length; i++) {
+ savedHeight += nav.inner[i].offsetHeight;
+ }
+
+ var innerStyles = "#" + this.wrapperEl + ".opened{max-height:" + savedHeight + "px}";
// Hide from old IE
if (computed) {
styleElement.innerHTML = innerStyles;
innerStyles = "";
\ No newline at end of file