From edaeeaaeaecb2a3aa7ec4ab94df6980ecf917144 Mon Sep 17 00:00:00 2001 From: Nikolas Wise Date: Tue, 25 Aug 2015 07:35:37 -0700 Subject: [PATCH] add dom node init and check for existence before binding events for third nav responsive behavior --- lib/js/calcite-web.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/js/calcite-web.js b/lib/js/calcite-web.js index fe2bcd85d..000b30dc0 100644 --- a/lib/js/calcite-web.js +++ b/lib/js/calcite-web.js @@ -5,7 +5,7 @@ // └────────────┘ // define all public api methods (excluding patterns) var calcite = { - version: 'v0.11.5', + version: 'v0.11.6', click: click, addEvent: addEvent, removeEvent: removeEvent, @@ -596,18 +596,15 @@ // │ Third Nav │ // └───────────┘ // sticks things to the window - calcite.thirdNav = function () { - var nav = document.querySelector('.js-nav-overflow'); - var leftBtn = document.querySelector('.js-overflow-left'); - var rightBtn = document.querySelector('.js-overflow-right'); + calcite.thirdNav = function (domNode) { + var nav = findElements('.js-nav-overflow', domNode)[0]; + var leftBtn = findElements('.js-overflow-left', domNode)[0]; + var rightBtn = findElements('.js-overflow-right', domNode)[0]; function scroll (distance) { nav.scrollLeft += distance; } - calcite.addEvent(leftBtn, calcite.click(), scroll.bind(null, -40)); - calcite.addEvent(rightBtn, calcite.click(), scroll.bind(null, 40)); - function resize () { calcite.removeClass(leftBtn, 'is-active'); calcite.removeClass(rightBtn, 'is-active'); @@ -615,9 +612,13 @@ if (nav.scrollLeft + nav.clientWidth + 5 < nav.scrollWidth) calcite.addClass(rightBtn, 'is-active'); } - calcite.addEvent(nav, 'scroll', resize); - calcite.addEvent(window, 'resize', resize); - resize(); + if (nav) { + calcite.addEvent(leftBtn, calcite.click(), scroll.bind(null, -40)); + calcite.addEvent(rightBtn, calcite.click(), scroll.bind(null, 40)); + calcite.addEvent(nav, 'scroll', resize); + calcite.addEvent(window, 'resize', resize); + resize(); + } }; // ┌────────────────────┐