(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 _navigation = require('./navigation');

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

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Navigation = 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; }; }(); /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      * navigation.js
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      */

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

var _elementHelpers2 = _interopRequireDefault(_elementHelpers);

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"); } }

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

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

    this.element = element;
    this.menuIcon = _elementHelpers2.default.getElementByAttribute(this.attributes.menuIcon);
    this.modalMain = _elementHelpers2.default.getElementByAttributeWithinElement(this.element, this.attributes.modalMain);
    this.collapsibles = _elementHelpers2.default.getElementsByAttributeWithinElement(this.element, this.attributes.collapsible);
    this.modalHeader = _elementHelpers2.default.getElementByAttributeWithinElement(this.element, this.attributes.modalHeader);
    this.scrollPos = 0;
    this.addEventHandlers();
  }

  /**
   * Declare classes
   */


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


    /**
     * Add event handlers
     */
    value: function addEventHandlers() {
      var _this = this;

      this.menuIcon.addEventListener('click', function () {
        // close all menu items on mobile when menu is closed
        document.querySelector('html').classList.contains(_this.classes.modalOpen) && setTimeout(function () {
          return _this.closeCollapsible();
        }, 500);
        // add classes to HTML
        document.querySelector('html').classList.toggle('' + _this.classes.modalOpen);
        document.querySelector('html').classList.toggle('' + _this.classes.modalNavOpen);
        // add active classes to modal
        _this.element.classList.toggle('' + _this.classes.modalActive);

        // remove animated border classes on modal
        var modalHeaderDivider = _elementHelpers2.default.getElementByAttributeWithinElement(_this.element, _this.attributes.headerDivider);
        if (modalHeaderDivider !== null) {
          modalHeaderDivider.classList.remove('' + _this.classes.modalHeaderDividerIn);
          modalHeaderDivider.classList.remove('' + _this.classes.modalHeaderDividerOut);
        }
      });

      this.modalMain.addEventListener('scroll', function () {
        _this.checkPosition();
      }, { passive: true });
    }
  }, {
    key: 'closeCollapsible',
    value: function closeCollapsible() {
      var _this2 = this;

      this.collapsibles.forEach(function (element) {
        _this2.content = element.parentElement.querySelector('[' + _this2.attributes.collapsibleContent + ']');
        element.classList.remove(_this2.classes.collapsibleTriggerExpanded);
        element.setAttribute(_this2.attributes.ariaExpanded, 'false');
        element.removeAttribute(_this2.attributes.expanded);
        _this2.content.style.maxHeight = '0px';
        _this2.content.setAttribute(_this2.attributes.content, '');
        _this2.content.setAttribute(_this2.attributes.ariaHidden, 'true');
      });
    }

    /**
     * Check position
     */

  }, {
    key: 'checkPosition',
    value: function checkPosition() {
      var modalMainY = this.modalMain.scrollTop;
      if (modalMainY > this.scrollPos) {
        this.modalHeader.classList.add(this.classes.modalHeaderDivider);
        this.modalHeader.setAttribute(this.attributes.headerDivider, '');
        this.modalHeader.classList.add(this.classes.modalHeaderDividerIn);
        this.modalHeader.classList.remove(this.classes.modalHeaderDividerOut);
      }
      if (modalMainY === 0) {
        this.modalHeader.classList.add(this.classes.modalHeaderDividerOut);
        this.modalHeader.classList.remove(this.classes.modalHeaderDivider);
        this.modalHeader.removeAttribute(this.attributes.headerDivider);
        this.modalHeader.classList.remove(this.classes.modalHeaderDividerIn);
      }
    }

    /**
     * Get selector
     */

  }, {
    key: 'classes',
    get: function get() {
      return {
        hidden: 'hidden',
        modalOpen: 'modal-open',
        modalNavOpen: 'modal-nav-open',
        modalActive: 'modal--active',
        modalHeaderDivider: 'modal__header--divider',
        modalHeaderDividerIn: 'modal__header--divider-in',
        modalHeaderDividerOut: 'modal__header--divider-out',
        collapsibleTriggerExpanded: 'collapsible__trigger--expanded'
      };
    }

    /**
     * Declare attribute constants
     */

  }, {
    key: 'attributes',
    get: function get() {
      return {
        ariaExpanded: 'aria-expanded',
        ariaHidden: 'aria-hidden',
        collapsibleContent: 'data-rs-collapsible-content',
        collapsible: 'data-rs-collapsible',
        content: 'data-rs-collapsible-content',
        headerDivider: attributeBase + '-header-divider',
        menuIcon: attributeBase + '-menu-icon',
        modalMain: attributeBase + '-modal-main',
        modalHeader: attributeBase + '-modal-header'
      };
    }
  }], [{
    key: 'getSelector',
    value: function getSelector() {
      return '[' + attributeBase + ']';
    }
  }]);

  return Navigation;
}();
},{"../helpers/element-helpers":3}],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;
},{}]},{},[1]);
