(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 _autoSuggest = require('./auto-suggest');

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

for (var i = 0; i < componentsList.length; i++) {
	new _autoSuggest.AutoSuggest(componentsList[i]);
}
},{"./auto-suggest":2}],2:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AutoSuggest = 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; }; }(); /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      * auto-suggest.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-auto-suggest';

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

    this.element = element;
    this.minimumLength = 1;
    this.container = this.element;
    this.timeout;
    this.numberOfListItems = 0;
    this.selectedIndex;
    this.selectedValue;
    this.previousInput = '';
    this.resultList;

    // attributes
    this.input = _elementHelpers2.default.getElementByAttributeWithinElement(this.element, this.attributes.input);
    this.list = _elementHelpers2.default.getElementByAttributeWithinElement(this.element, this.attributes.list);
    this.noResultMessage = this.input.getAttribute(this.attributes.noResultMessage);
    // option to disable the input events RBD-9338
    this.preventInputEvent = this.input.getAttribute(this.attributes.preventInputEvent);
    // ignore default Orbit filter and display all returned data RBR-452
    this.useExactValues = this.input.getAttribute(this.attributes.useExactValues);
    this.separator = this.list.getAttribute(this.attributes.separator);
    this.threshold = Number(this.input.getAttribute(this.attributes.threshold)) || 300;

    // nodes
    this.submit = element.parentNode.querySelector('[type="submit"]');

    // functions
    this.dataSource = this.getDataSource();
    this.disableNativeAutoComplete();
    this.addEventHandlers();
  }

  /**
   * Declare attributes
   */


  _createClass(AutoSuggest, [{
    key: 'disableNativeAutoComplete',


    /**
     * Disable native auto complete
     * Only Chrome does not support disabling native auto complete
     */
    value: function disableNativeAutoComplete() {
      this.input.setAttribute(this.attributes.autocomplete, 'off');
    }

    /**
     * Add event handlers
     */

  }, {
    key: 'addEventHandlers',
    value: function addEventHandlers() {
      var _this = this;

      var events = ['focus', 'keydown'];

      if (this.preventInputEvent === null) {
        events.push('input');
      }

      // on input and focus, create list if user input length > minimum length
      events.forEach(function (eventType) {
        _this.element.addEventListener(eventType, _this.onInput.bind(_this), {
          capture: true
        });
      });
      document.addEventListener('click', this.clickOutside.bind(this));
    }
  }, {
    key: 'onInput',
    value: function onInput(event) {
      if (event.target.hasAttribute(this.attributes.input)) {
        if (event.type === 'input' || event.type === 'focus') {
          this.numberOfListItems = 0;
          // only process if input is equal to or longer then minimum length
          if (this.input.value.length >= this.minimumLength) {
            // if previous input length is less then minimum length OR if previous input does not contain current input -> reset the data source
            if (this.previousInput.length < this.minimumLength || this.input.value.toLowerCase().indexOf(this.previousInput.toLowerCase()) === -1) {
              this.dataSource = this.getDataSource();
            }
            this.createList();
          } else {
            // Close the list if it contains the open class
            if (this.container.classList.contains(this.classes.autosuggestOpen)) {
              this.closeList();
            }
          }
          this.previousInput = this.input.value;
        } else if (event.type === 'keydown') {
          // if keydown is tab and item is preselected, select item and close list
          if (_elementHelpers2.default.getKeyCodeOnKeyDownEvent(event) == this.keyCodes.Tab) {
            if (this.selectedIndex > -1) {
              this.setSelectedValue(this.selectedIndex);
            }
            this.closeList();
          }
          // if keydown is escape, close list and do not select item
          if (_elementHelpers2.default.getKeyCodeOnKeyDownEvent(event) == this.keyCodes.Escape) {
            this.closeList();
          }
          this.handleButtonKeys(event);
        }
      }
    }
  }, {
    key: 'clickOutside',
    value: function clickOutside(event) {
      // if clicked outside input field or list, close the list and do not select item
      if (!this.list.contains(event.target) && !this.input.contains(event.target)) {
        if (this.container.classList.contains(this.classes.autosuggestOpen)) {
          this.closeList();
        }
      }
    }

    /**
     * Create list - get matched items from data source and put them in list with li elements
     */

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

      var list = '';
      var listItemIndex = 0;

      window.clearTimeout(this.timeout);

      // set result list equal to data source
      this.resultList = JSON.parse(JSON.stringify(this.dataSource));

      this.dataSource.forEach(function (listItem) {
        // check for each list item in the data source if it matches with input from user
        if (listItem.toLowerCase().indexOf(_this2.input.value.toLowerCase()) > -1 || _this2.useExactValues !== null) {
          // escape special symbols RBD-8705
          var regexSafeValue = _this2.input.value.replace(/[-\[\]/{}()*+?.\\^$|]/g, '\\$&');
          // if item matches, add mark to matched part to create highlighted text
          var regex = new RegExp(regexSafeValue, 'gi');
          var response = listItem.replace(regex, function (value) {
            return '<mark>' + value + '</mark>';
          });
          // create li element for matched item
          var li = '<li class="' + _this2.classes.autosuggestItem + '" ' + _this2.attributes.listValue + ' ' + _this2.attributes.index + '="' + listItemIndex + '" >' + response + '</li>';

          // add li elements to list variable
          list = list + li;
          _this2.numberOfListItems++;
          listItemIndex++;
        } else {
          // if list item does not match input from user -> remove list item from result list
          var index = _this2.resultList.indexOf(listItem);
          if (index > -1) {
            _this2.resultList.splice(index, 1);
          }
        }
      });
      // set data source equal to result list
      this.dataSource = JSON.parse(JSON.stringify(this.resultList));
      // if number of list items > 0, bind result list
      if (this.numberOfListItems > 0) {
        this.timeout = setTimeout(function () {
          return _this2.bindResultList(list);
        }, this.threshold);
      } else {
        var noResults = '<li class="' + this.classes.autosuggestNoResult + '">' + (this.noResultMessage || 'no results') + ' </li>';
        this.bindResultList(noResults);
      }
    }

    /**
     * bind result list - binds result to list, add eventlisteners for events 'click' and 'mouseenter' to list items
     *
     * @param {string} list - list with results
     */

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

      this.list.innerHTML = list;
      this.container.classList.add(this.classes.autosuggestOpen);

      this.list.querySelectorAll('[' + this.attributes.listValue + ']').forEach(function (element, index) {
        if (index === 0) {
          // set first item as pre selected
          element.classList.add(_this3.classes.autosuggestPreselect);
          element.setAttribute(_this3.attributes.preselect, '');

          _this3.selectedIndex = 0;
          _this3.updatePreselectedItem(_this3.selectedIndex, null, true);
        }

        element.addEventListener('click', function () {
          _this3.setSelectedValue(_this3.selectedIndex);
        });

        element.addEventListener('mouseenter', function (mouseEnterEvent) {
          _this3.updatePreselectedItem(element.getAttribute(_this3.attributes.index), mouseEnterEvent, false);
        });
      });
    }

    /**
     * Update preselected item, triggers setScrollbar
     *
     * @param {number} index - index of preselected element
     * @param {Event} event - event triggered
     * @param {boolean} executeScroll - boolean to trigger scroll
     */

  }, {
    key: 'updatePreselectedItem',
    value: function updatePreselectedItem(index, event, executeScroll) {
      // get former preselected item, remove class and attribute
      var formerPreselectedItem = _elementHelpers2.default.getElementByAttribute(this.attributes.preselect);
      if (formerPreselectedItem) {
        formerPreselectedItem.classList.remove(this.classes.autosuggestPreselect);
        formerPreselectedItem.removeAttribute(this.attributes.preselect);
      }
      // get preselected item, add class and attribute
      var preselectedItem = _elementHelpers2.default.getElementByAttribute(this.attributes.index, index);
      if (preselectedItem) {
        preselectedItem.classList.add(this.classes.autosuggestPreselect);
        preselectedItem.setAttribute(this.attributes.preselect, '');
      }

      this.selectedIndex = index;
      this.selectedValue = preselectedItem.innerText;

      // only set scrollbar if event is keydown
      if (typeof event !== 'undefined' && event !== null && event.type === 'keydown' || executeScroll === true) {
        this.setScrollbar(preselectedItem, event);
      }
    }

    /**
     * Set selected value
     *
     * @param {number} index - index of selected item
     */

  }, {
    key: 'setSelectedValue',
    value: function setSelectedValue(index) {
      // get preselected item with index, set value to input field and close the list
      var preSelectedItem = _elementHelpers2.default.getElementByAttribute(this.attributes.index, index);

      if (preSelectedItem != null) {
        this.input.value = preSelectedItem.innerText;
        this.closeList();
      }
    }

    /**
     * Handle button keys - handle key presses down, up, enter, page down and page up
     *
     * @param {Event} event - event triggered
     */

  }, {
    key: 'handleButtonKeys',
    value: function handleButtonKeys(event) {
      if (event != null && this.selectedIndex > -1) {
        switch (_elementHelpers2.default.getKeyCodeOnKeyDownEvent(event)) {
          case this.keyCodes.Down:
            event.preventDefault();
            // if preselected item is not last of the list, preselect next item
            if (this.selectedIndex < this.numberOfListItems - 1) {
              this.selectedIndex++;
              this.updatePreselectedItem(this.selectedIndex, event, false);
            }
            break;

          case this.keyCodes.Up:
            event.preventDefault();
            // if preselected item is not first of the list, preselect previous item
            if (this.selectedIndex > 0) {
              this.selectedIndex--;
              this.updatePreselectedItem(this.selectedIndex, event, false);
            }
            break;

          case this.keyCodes.PageDown:
            event.preventDefault();
            // if preselected item is not last of the list, preselect last item
            if (this.selectedIndex < this.numberOfListItems - 1) {
              this.updatePreselectedItem(Number(this.numberOfListItems) - 1, event, false);
            }
            break;

          case this.keyCodes.PageUp:
            event.preventDefault();
            // if preselected item is not first of the list, preselect first item
            if (this.selectedIndex > 0) {
              this.updatePreselectedItem(0, event, false);
            }
            break;

          case this.keyCodes.Enter:
            event.preventDefault();
            this.setSelectedValue(this.selectedIndex);
            this.closeList();
            this.input.blur();

            // If there is a submit button after enter focus on the submit button
            if (this.submit) {
              this.submit.focus();
            }
            break;
        }
      }
    }

    /**
     * Set scroll bar to correct position
     *
     * @param {HTMLElement} element - selected element from the list
     * @param {Event} event - event triggered
     */

  }, {
    key: 'setScrollbar',
    value: function setScrollbar(element, event) {
      var elementHeight = element.offsetHeight;
      var elementOffsetTop = element.offsetTop;
      var offsetTopFirstElement = this.list.children[0].offsetTop;

      // set scrollbar on moving down
      if (event != null && _elementHelpers2.default.getKeyCodeOnKeyDownEvent(event) == this.keyCodes.Down) {
        // if bottom of preselected element (elementHeight + elementOffsetTop) > bottom of visible list (this.list.offsetHeight + this.list.scrollTop),
        // set scrollTop to difference between bottom of preselected element and the height of the list
        if (elementHeight + elementOffsetTop > this.list.offsetHeight + this.list.scrollTop) {
          this.list.scrollTop = elementHeight + elementOffsetTop - this.list.offsetHeight;
        }
      }
      // set scrollbar on  moving up
      else {
          // if top of preselected element - margin top) < scroll position OR bottom of preselected element (elementHeight + elementOffsetTop) > bottom of visible list,
          // set scrollTop to top op preselected element - margin top
          if (elementOffsetTop - offsetTopFirstElement < this.list.scrollTop || elementOffsetTop + elementHeight > this.list.scrollTop + this.list.offsetHeight) {
            this.list.scrollTop = elementOffsetTop - offsetTopFirstElement;
          }
        }
    }

    /**
     * Close list - closes the list with suggestions and resets selected index and selected value
     */

  }, {
    key: 'closeList',
    value: function closeList() {
      // Add custom event to be able to add custom events on the autosuggest close dropdown
      var event = new CustomEvent('autoSuggestCloseDropdown');
      window.dispatchEvent(event);

      this.container.classList.remove(this.classes.autosuggestOpen);
      this.list.innerHTML = '';

      this.selectedValue = '';
      this.selectedIndex = -1;
    }

    /**
     * Get data source
     */

  }, {
    key: 'getDataSource',
    value: function getDataSource() {
      var autoSuggestValues = this.list.getAttribute(this.attributes.values);
      if (typeof autoSuggestValues !== 'undefined' && autoSuggestValues !== null) {
        return autoSuggestValues.split(this.separator);
      } else {
        return [];
      }
    }

    /**
     * Get selector
     */

  }, {
    key: 'attributes',
    get: function get() {
      return {
        autocomplete: 'autocomplete',
        container: attributeBase + '-container',
        index: attributeBase + '-index',
        input: attributeBase + '-input',
        list: attributeBase + '-list',
        listValue: attributeBase + '-list-value',
        noResultMessage: attributeBase + '-no-result-message',
        preselect: attributeBase + '-preselect',
        preventInputEvent: attributeBase + '-prevent-input-event',
        selected: attributeBase + '-selected',
        separator: attributeBase + '-separator',
        threshold: attributeBase + '-threshold',
        useExactValues: attributeBase + '-use-exact-values',
        values: attributeBase + '-values'
      };
    }

    /**
     * Declare classes
     */

  }, {
    key: 'classes',
    get: function get() {
      return {
        autosuggestOpen: 'select-menu--open',
        autosuggestItem: 'select-menu__item',
        autosuggestNoResult: 'select-menu__item select-menu__item--no-result',
        autosuggestPreselect: 'select-menu__item--preselect'
      };
    }

    /**
     * Declare key codes
     */

  }, {
    key: 'keyCodes',
    get: function get() {
      return {
        Enter: 'Enter',
        Up: 'ArrowUp',
        Down: 'ArrowDown',
        Tab: 'Tab',
        Escape: 'Escape',
        PageUp: 'PageUp',
        PageDown: 'PageDown'
      };
    }
  }], [{
    key: 'getSelector',
    value: function getSelector() {
      return '[' + attributeBase + ']';
    }
  }]);

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