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

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

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Collapsible = 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; }; }(); /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      * collapsible.js
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      * Script to expand and collapse elements
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      */

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-collapsible';

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

    this.element = element;
    this.content = this.element.parentElement.querySelector('[' + this.attributes.content + ']');
    this.triggerElement = this.element;
    this.initialExpanded = this.content.getAttribute(this.attributes.content) === this.states.expanded;

    this.addEventHandlers();
    if (this.initialExpanded) {
      this.handleExpandedElement();
    }
  }

  /**
   * Declare attribute constants
   */


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


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

      var initialHeight = this.content.offsetHeight;

      if (this.element.getAttribute(attributeBase) === this.attributes.navigation) {
        this.triggerElement = this.element.querySelector('[' + this.attributes.button + ']');
      }

      if (this.triggerElement != null) {
        this.triggerElement.addEventListener('click', function (clickEvent) {
          clickEvent.preventDefault();
          _this.toggle(initialHeight);
        });
      }
      if (this.initialExpanded) {
        window.addEventListener('load', function () {
          _this.handleExpandedElement();
        });
      }

      this.isOverflown(this.content, this.element);

      // on orientation change, recalculate content height
      window.addEventListener('orientationchange', function () {
        _this.recalculateContentHeight();
        _this.isOverflown(_this.content, _this.element);
      });

      window.addEventListener('resize', function () {
        _this.recalculateContentHeight();
        _this.isOverflown(_this.content, _this.element);
      });

      window.addEventListener('scroll', function () {
        _this.simulateClickOnScroll();
      });
    }
  }, {
    key: 'simulateClickOnScroll',


    /*
     * if the element is expanded and needs to be closed on scroll, simulate a click
     */
    value: function simulateClickOnScroll() {
      if (this.isExpanedElementToClose && this.element.hasAttribute(this.attributes.closeOnScroll)) {
        var elementPos = this.element.parentElement.offsetTop;
        var windowScrollPos = window.scrollY;

        if (windowScrollPos > elementPos) {
          this.element.click();
        }
      }
    }
  }, {
    key: 'toggle',
    value: function toggle(initialHeight) {
      if (this.isTriggerExpanded) {
        this.collapseTrigger();
        this.collapseContent(initialHeight);
      } else {
        var contentHeight = this.content.scrollHeight;
        this.expandTrigger();
        this.expandContent(contentHeight);
      }
    }
  }, {
    key: 'handleExpandedElement',
    value: function handleExpandedElement() {
      if (_elementHelpers2.default.isDesktop()) {
        var contentHeight = this.content.scrollHeight;
        if (this.content.style.maxHeight !== contentHeight + 'px') {
          this.expandContent(contentHeight);
          this.expandTrigger();
        }
        if (this.initialExpanded === false) {
          this.content.setAttribute(this.attributes.content, this.attributes.filter);
          this.element.setAttribute(this.attributes.expanded, this.states.expanded);
        }
      } else {
        // do not collapse on mobile devices if in filter
        this.collapseTrigger();
        this.collapseContent();
      }
    }
  }, {
    key: 'collapseTrigger',
    value: function collapseTrigger() {
      this.element.classList.remove(this.classes.collapsibleTriggerExpanded);
      this.element.setAttribute(this.attributes.ariaExpanded, 'false');
      this.element.removeAttribute(this.attributes.expanded);
    }
  }, {
    key: 'collapseContent',
    value: function collapseContent(initialHeight) {
      this.content.style.maxHeight = initialHeight + 'px';
      this.content.setAttribute(this.attributes.content, '');
      this.content.setAttribute(this.attributes.ariaHidden, 'true');
    }

    /**
     * Handles element on expand - add class and set aria expanded attribute
     */

  }, {
    key: 'expandTrigger',
    value: function expandTrigger() {
      this.element.classList.add(this.classes.collapsibleTriggerExpanded);
      this.element.setAttribute(this.attributes.ariaExpanded, 'true');
    }

    /**
     * Handles content on expand - set maxheight, expanded state en aria hidden attribute
     *
     * @param {number} contentHeight - height of content element
     */

  }, {
    key: 'expandContent',
    value: function expandContent(contentHeight) {
      this.content.style.maxHeight = contentHeight + 30 + 'px'; // add 30px to fit on IOS mobile (gives back different scrollHeight)
      this.content.setAttribute(this.attributes.content, this.states.expanded);
      this.content.setAttribute(this.attributes.ariaHidden, 'false');
    }

    /**
     * Recalculate content height and set max height
     */

  }, {
    key: 'recalculateContentHeight',
    value: function recalculateContentHeight() {
      this.content = this.element.parentElement.querySelector('[' + this.attributes.content + ']');
      this.contentHeight = this.content.scrollHeight;

      // set maxheight on expanded content
      if (this.content.getAttribute(this.attributes.content) === this.states.expanded) {
        this.content.style.maxHeight = this.contentHeight + 'px';
      }
    }

    /**
     * check if the content is not overflown
     */

  }, {
    key: 'isOverflown',
    value: function isOverflown(content, trigger) {
      if (trigger.getAttribute(attributeBase) === 'hide-trigger') {
        var isOverflown = content.scrollHeight > content.clientHeight || content.scrollWidth > content.clientWidth;

        if (!isOverflown) {
          trigger.classList.add('display-none');
        }

        if (isOverflown) {
          trigger.classList.remove('display-none');
        }
      }
    }

    /**
     * Get selector
     */

  }, {
    key: 'attributes',
    get: function get() {
      return {
        content: attributeBase + '-content',
        button: attributeBase + '-button',
        expanded: attributeBase + '-expanded',
        navigation: 'navigation',
        ariaExpanded: 'aria-expanded',
        ariaHidden: 'aria-hidden',
        filter: 'filter',
        closeOnOutsideClick: attributeBase + '-close-on-outside-click',
        closeOnScroll: attributeBase + '-close-on-scroll'
      };
    }

    /**
     * Declare classes
     */

  }, {
    key: 'classes',
    get: function get() {
      return {
        collapsibleTriggerExpanded: 'collapsible__trigger--expanded'
      };
    }

    /**
     * Declare state constants
     */

  }, {
    key: 'states',
    get: function get() {
      return {
        expanded: 'expanded'
      };
    }
  }, {
    key: 'isExpanedElementToClose',
    get: function get() {
      var elementsToClose = _elementHelpers2.default.getElementByAttribute(this.attributes.closeOnScroll);

      if (!elementsToClose) {
        return;
      }

      var elementsToCloseIsExpanded = elementsToClose.classList.contains(this.classes.collapsibleTriggerExpanded);

      return elementsToCloseIsExpanded;
    }
  }, {
    key: 'isTriggerExpanded',
    get: function get() {
      return this.element.classList.contains(this.classes.collapsibleTriggerExpanded);
    }
  }], [{
    key: 'getSelector',
    value: function getSelector() {
      return '[' + attributeBase + ']';
    }
  }]);

  return Collapsible;
}();
},{"../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]);
