(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _scroll = require('./scroll');

// initialize all elements
var componentsList = document.querySelectorAll(_scroll.Scroll.getSelector()); // Import all components

for (var i = 0; i < componentsList.length; i++) {
	new _scroll.Scroll(componentsList[i]);
}
},{"./scroll":2}],2:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Scroll = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _elementHelpers = require('../helpers/element-helpers');

var _elementHelpers2 = _interopRequireDefault(_elementHelpers);

var _scrollToElement = require('../helpers/scrollToElement');

var _scrollToElement2 = _interopRequireDefault(_scrollToElement);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
 * scroll.js
 * scroll script that adds a gradient and handles anchors
 */

/**
 * Declare constants
 */
var attributeBase = 'data-rs-scroll';

var Scroll = exports.Scroll = function () {
  function Scroll(element) {
    _classCallCheck(this, Scroll);

    this.element = element;
    this.list = _elementHelpers2.default.getElementByAttribute(this.attributes.list);
    this.link = _elementHelpers2.default.getElementsByAttribute(this.attributes.link);

    this.addEventHandlers();
  }

  /**
   * Declare attribute constants
   */


  _createClass(Scroll, [{
    key: 'addEventHandlers',


    /**
     * Add event handlers
     */
    value: function addEventHandlers() {
      this.addGradientToScrollingList();
      this.addAndRemoveGradientOnScroll();
      this.handleScrollOnClick();
      this.addAndRemoveDividerOnScroll();
      this.addDividerToScrollingList();
    }

    /**
     * Adds a gradient when it is possible to scroll, by comparing offset height with scroll height
     */

  }, {
    key: 'addGradientToScrollingList',
    value: function addGradientToScrollingList() {
      var _this2 = this;

      this.element.addEventListener('click', function () {
        var list = _this2.list;
        var offsetHeight = list.offsetHeight;
        var scrollHeight = list.scrollHeight;

        var isScrollable = scrollHeight > offsetHeight;

        if (isScrollable) {
          if (list.classList.contains('scroll-gradient')) {
            list.classList.remove('scroll-gradient');
          } else {
            list.classList.add('scroll-gradient');
          }
        }
      });
    }

    /**
     * removes gradient when scrolled all the way to the bottom
     * adds gradient when scrolled to the top
     */

  }, {
    key: 'addAndRemoveGradientOnScroll',
    value: function addAndRemoveGradientOnScroll() {
      var _this3 = this;

      this.list.addEventListener('scroll', function () {
        var list = _this3.list;
        var scrollTop = list.scrollTop;
        var scrollHeight = list.scrollHeight;
        var offsetHeight = list.offsetHeight;

        var isScrollable = scrollHeight > offsetHeight;

        var isScrolledToBottom = scrollHeight - offsetHeight - scrollTop < 1;

        if (isScrolledToBottom && isScrollable) {
          list.classList.remove('scroll-gradient');
        } else {
          list.classList.add('scroll-gradient');
        }
      });
    }

    /**
     * adds divider when scrolled more than 1px from top
     * removes the divider when scrolled to top
     */

  }, {
    key: 'addAndRemoveDividerOnScroll',
    value: function addAndRemoveDividerOnScroll() {
      var _this4 = this;

      this.list.addEventListener('scroll', function () {
        var list = _this4.list;
        var scrollTop = list.scrollTop;
        var scrollHeight = list.scrollHeight;
        var offsetHeight = list.offsetHeight;

        var isScrollable = scrollHeight > offsetHeight;

        if (isScrollable && scrollTop > 1) {
          _this4.element.classList.add('scroll-divider');
        } else {
          _this4.element.classList.remove('scroll-divider');
        }
      });
    }

    /**
     * Removes the divider when closing the element
     */

  }, {
    key: 'addDividerToScrollingList',
    value: function addDividerToScrollingList() {
      var _this5 = this;

      this.element.addEventListener('click', function () {
        if (_this5.element.classList.contains('scroll-divider')) {
          _this5.element.classList.remove('scroll-divider');
        }
      });
    }

    /**
     * scrolls the screen to the id of the content defined in the href
     * uses scrolltoelement helper
     * sets and removes 'is-active state'
     */

  }, {
    key: 'handleScrollOnClick',
    value: function handleScrollOnClick() {
      var _this6 = this;

      this.link.forEach(function (item) {
        var _this = _this6;
        item.addEventListener('click', function () {
          var link = this.querySelector('a');
          var href = link.getAttribute('href').substring(1);
          var elem = document.getElementById(href);
          var navHeight = _this.element.offsetHeight;

          var scrollExtraOffset = _elementHelpers2.default.isDesktop() ? null : -navHeight;

          var stickyClass = _this.element.parentElement.dataset.rsSticky;
          var parentContainsStickyClass = _this.element.parentElement.classList.contains(stickyClass);

          var parentHeight = _this.element.parentElement.offsetHeight;

          // If the parentcontainer is not sticky it needs to add an extra space to the scroll, because while scrolling down
          // the navigation becomes absolute and the height will be taken out of the DOM
          if (!parentContainsStickyClass) {
            scrollExtraOffset = -parentHeight;
          }

          (0, _scrollToElement2.default)(elem, 500, scrollExtraOffset);
          _this.link.forEach(function (item) {
            item.classList.remove('is-active');
          });

          this.classList.add('is-active');
        });
      });
    }

    /**
     * Get selector
     */

  }, {
    key: 'attributes',
    get: function get() {
      return {
        list: attributeBase + '-list',
        link: attributeBase + '-link'
      };
    }
  }], [{
    key: 'getSelector',
    value: function getSelector() {
      return '[' + attributeBase + ']';
    }
  }]);

  return Scroll;
}();
},{"../helpers/element-helpers":3,"../helpers/scrollToElement":4}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var ElementHelpers = function () {
	function ElementHelpers() {
		_classCallCheck(this, ElementHelpers);
	}

	_createClass(ElementHelpers, null, [{
		key: 'triggerEvent',


		/**
   * Trigger an event on a specified element
   * @param element {Node}
   * @param eventType
   */
		value: function triggerEvent(element, eventType) {
			var event = void 0;

			if (typeof Event === 'function') {
				event = new Event(eventType);
			} else {
				event = document.createEvent('Event');
				event.initEvent(eventType, true, true);
			}
			element.dispatchEvent(event);
		}

		/**
   * Get element by attribute and optional by attribute value
   * @param attributeName
   * @param attributeValue - optional
   */

	}, {
		key: 'getElementByAttribute',
		value: function getElementByAttribute(attributeName, attributeValue) {
			if (attributeValue) {
				return document.querySelector('[' + attributeName + '="' + attributeValue + '"]');
			} else {
				return document.querySelector('[' + attributeName + ']');
			}
		}

		/**
   * Get multiple elements by attribute and optional by attribute value
   * @param attributeName
   * @param attributeValue - optional
   */

	}, {
		key: 'getElementsByAttribute',
		value: function getElementsByAttribute(attributeName, attributeValue) {
			if (attributeValue) {
				return document.querySelectorAll('[' + attributeName + '="' + attributeValue + '"]');
			} else {
				return document.querySelectorAll('[' + attributeName + ']');
			}
		}

		/**
   * Get element by attribute and optional by attribute value, within an element
   * @param element
   * @param attributeName
   * @param attributeValue - optional
   */

	}, {
		key: 'getElementByAttributeWithinElement',
		value: function getElementByAttributeWithinElement(element, attributeName, attributeValue) {
			if (attributeValue) {
				return element.querySelector('[' + attributeName + '="' + attributeValue + '"]');
			} else {
				return element.querySelector('[' + attributeName + ']');
			}
		}

		/**
   * check if mouse pointer is on element
   * @param element
   */

	}, {
		key: 'isMouseOver',
		value: function isMouseOver(element) {
			return Array.prototype.slice.call(element.parentElement.querySelectorAll(':hover')).filter(function () {
				return element[0] == this;
			}).length > 0;
		}

		/**
   * Get multiple elements by attribute and optional by attribute value, within an element
   * @param element
   * @param attributeName
   * @param attributeValue - optional
   */

	}, {
		key: 'getElementsByAttributeWithinElement',
		value: function getElementsByAttributeWithinElement(element, attributeName, attributeValue) {
			if (attributeValue) {
				return element.querySelectorAll('[' + attributeName + '="' + attributeValue + '"]');
			} else {
				return element.querySelectorAll('[' + attributeName + ']');
			}
		}

		/**
   * Get element by class, within an element
   * @param element
   * @param className
   */

	}, {
		key: 'getElementByClassWithinElement',
		value: function getElementByClassWithinElement(element, className) {
			return element.querySelector('.' + className);
		}

		/**
   * get max width for mobile viewports 
   */

	}, {
		key: 'maxWidthMobileViewports',
		value: function maxWidthMobileViewports() {
			return 940;
		}

		/**
   * Create an event
   * @param eventType
   */

	}, {
		key: 'createEvent',
		value: function createEvent(eventType) {
			var event = void 0;
			if (typeof Event === 'function') {
				event = new Event(eventType);
			} else {
				event = document.createEvent('Event');
				event.initEvent(eventType, true, true);
			}
			return event;
		}

		/**
   * checks if viewport is desktop size
   */

	}, {
		key: 'isDesktop',
		value: function isDesktop() {
			return Math.max(document.documentElement.clientWidth, window.innerWidth || 0) > this.maxWidthMobileViewports();
		}
	}, {
		key: 'isIE11',
		value: function isIE11() {
			return navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > -1;
		}

		/**
   * Get keycode on keydown event, as fallback if event.code is not supported yet by the browser
   * @param event
   */

	}, {
		key: 'getKeyCodeOnKeyDownEvent',
		value: function getKeyCodeOnKeyDownEvent(event) {
			var keyCode = void 0;
			if (event != null) {
				if (typeof event.code === 'undefined') {
					switch (event.keyCode) {
						case 13:
							keyCode = 'Enter';
							break;
						case 38:
							keyCode = 'ArrowUp';
							break;
						case 40:
							keyCode = 'ArrowDown';
							break;
						case 9:
							keyCode = 'Tab';
							break;
						case 27:
							keyCode = 'Escape';
							break;
						case 33:
							keyCode = 'PageUp';
							break;
						case 34:
							keyCode = 'PageDown';
							break;
						default:
							keyCode = undefined;
							break;
					}
				} else {
					keyCode = event.code;
				}
			}
			return keyCode;
		}
	}]);

	return ElementHelpers;
}();

module.exports = ElementHelpers;
},{}],4:[function(require,module,exports){
'use strict';

function getElementY(query) {
  return window.pageYOffset + query.getBoundingClientRect().top;
}

module.exports = function scrollToElement(element) {
  var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
  var addspace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;

  if (!element) {
    return;
  }

  var startingY = window.pageYOffset;
  var elementY = element === 'top' ? getElementY(document.body) : getElementY(element);

  // If element is close to page's bottom then window will scroll only to some position above the element.
  var targetY = document.body.scrollHeight - elementY < window.innerHeight ? document.body.scrollHeight - window.innerHeight : elementY;
  var diff = targetY - startingY + addspace;
  // Easing function: easeInOutCubic
  // From: https://gist.github.com/gre/1650294
  var easing = function easing(t) {
    return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
  };
  var start = void 0;

  if (!diff) {
    return;
  }

  // Bootstrap our animation - it will get called right before next frame shall be rendered.
  window.requestAnimationFrame(function step(timestamp) {
    if (!start) {
      start = timestamp;
    }
    // Elapsed miliseconds since start of scrolling.
    var time = timestamp - start;
    // Get percent of completion in range [0, 1].
    var percent = Math.min(time / duration, 1);
    // Apply the easing.
    // It can cause bad-looking slow frames in browser performance tool, so be careful.
    percent = easing(percent);

    window.scrollTo(0, startingY + diff * percent);

    // Proceed with animation as long as we wanted it to.
    if (time < duration) {
      window.requestAnimationFrame(step);
    }
  });
};
},{}]},{},[1]);
