2015-07-04 16:23:34 +01:00

49 lines
1.7 KiB
JavaScript

/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Navbar scroll buttons
(function() {
'use strict';
var rightScroll = document.querySelector('.scrollindicator.scrollindicator--right');
var leftScroll = document.querySelector('.scrollindicator.scrollindicator--left');
var menuBar = document.querySelector('.docs-navigation');
var delta = 40;
function updateScrollIndicator() {
leftScroll.classList.remove('disabled');
rightScroll.classList.remove('disabled');
if (menuBar.scrollLeft <= 0) {
leftScroll.classList.add('disabled');
}
// 5px tolerance because browsers!
if (menuBar.scrollLeft + menuBar.clientWidth + 5 >= menuBar.scrollWidth) {
rightScroll.classList.add('disabled');
}
}
menuBar.addEventListener('scroll', updateScrollIndicator);
updateScrollIndicator();
function scrollMenuBar(delta) {
menuBar.scrollLeft += delta;
}
rightScroll.addEventListener('click', scrollMenuBar.bind(null, delta));
rightScroll.addEventListener('tap', scrollMenuBar.bind(null, delta));
leftScroll.addEventListener('click', scrollMenuBar.bind(null, -delta));
leftScroll.addEventListener('tap', scrollMenuBar.bind(null, -delta));
})();