Skip to content

Commit

Permalink
add dom node init and check for existence before binding events for t…
Browse files Browse the repository at this point in the history
…hird nav responsive behavior
  • Loading branch information
nikolaswise committed Aug 25, 2015
1 parent 82c4d30 commit edaeeaa
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/js/calcite-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -596,28 +596,29 @@
// │ 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');
if (nav.scrollLeft > 0) calcite.addClass(leftBtn, 'is-active');
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();
}
};

// ┌────────────────────┐
Expand Down

0 comments on commit edaeeaa

Please sign in to comment.