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

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

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

Object.defineProperty(exports, "__esModule", {
	value: true
});
exports.Toggable = 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 _target = require('./toggable/target');

var _target2 = _interopRequireDefault(_target);

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

/**
 * toggable.js
 * toggles class on click or keyup (spacebar)
 * 
 */

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

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

		this.element = element;
		var attributeState = this.element.dataset.rsToggable;
		this.state = Object.values(this.states).indexOf(attributeState) > -1 ? this.element.dataset.rsToggable : this.states.inactive;
		this.addEventHandlers();
		this.disableEvents = [];
		this.initialize();
	}

	/**
 * Declare classes
 */


	_createClass(Toggable, [{
		key: 'initialize',


		/**
   * Initialize toggable elements
   */
		value: function initialize() {
			this.setClass();
		}

		/**
   * Add event handlers
   */

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

			this.element.addEventListener('click', function (clickEvent) {
				clickEvent.preventDefault();
				_this.toggleState();
			});
		}

		/**
   * Toggle current state
   */

	}, {
		key: 'toggleState',
		value: function toggleState() {
			// toggle state
			this.state = this.state === this.states.active ? this.states.inactive : this.states.active;
			this.setClass();
			_target2.default.toggle(this.element, this.state === this.states.active);
		}

		/**
   * Set the class based on current state
   */

	}, {
		key: 'setClass',
		value: function setClass() {
			if (this.state === this.states.active) {
				this.element.classList.add(this.classes.iconTogglerActive);
			} else {
				this.element.classList.remove(this.classes.iconTogglerActive);
			}
		}

		/**
   * Get selector
   */

	}, {
		key: 'classes',
		get: function get() {
			return {
				iconTogglerActive: 'icon__toggler--active'
			};
		}

		/**
  * Declare state constants
  */

	}, {
		key: 'states',
		get: function get() {
			return {
				active: 'active',
				inactive: 'inactive'
			};
		}
	}], [{
		key: 'getSelector',
		value: function getSelector() {
			return '[' + attributeBase + ']';
		}
	}]);

	return Toggable;
}();
},{"./toggable/target":3}],3:[function(require,module,exports){
'use strict';

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

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 attributeBase = 'data-rs-toggable-target';

var Target = exports.Target = function () {
	function Target() {
		_classCallCheck(this, Target);
	}

	_createClass(Target, null, [{
		key: 'toggle',
		value: function toggle(element, enable) {
			if (typeof element === 'undefined' || !element) {
				return;
			}
			var targetSelector = element.getAttribute(attributeBase);
			if (typeof targetSelector !== 'undefined' && targetSelector) {
				var targetElements = document.querySelectorAll(targetSelector);
				targetElements.forEach(enable === true ? Target.enable : Target.disable);
			}
		}
	}, {
		key: 'enable',
		value: function enable(element) {
			element.removeAttribute('hidden');
		}
	}, {
		key: 'disable',
		value: function disable(element) {
			element.setAttribute('hidden', '');
		}
	}]);

	return Target;
}();

module.exports = Target;
},{}]},{},[1]);
