(window["webpackJsonp_name_"] = window["webpackJsonp_name_"] || []).push([[43],{
/***/ 177:
/***/ (function(module, exports, __webpack_require__) {
"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 Multiselect = function () {
_createClass(Multiselect, null, [{
key: 'default',
get: function get() {
return {
el: null,
select: null,
config: null
};
}
}]);
function Multiselect(params) {
_classCallCheck(this, Multiselect);
this._params = Object.assign({}, Multiselect.default, params);
this._createSelect();
this._onClick();
}
_createClass(Multiselect, [{
key: '_createSelect',
value: function _createSelect() {
if (this.el.disabled) {
return;
}
this.selected = [];
if (this.el.classList.contains('cs-select_inited')) {
return false;
}
this.el.classList.add('cs-select_inited');
this.wrapper = document.createElement('DIV');
this.wrapper.className = 'cs-select ' + this.el.className;
this.title = document.createElement('SPAN');
this.title.classList.add('cs-placeholder');
this.title.classList.add('project-input');
this.title.classList.add('project-input_select');
this.options = document.createElement('DIV');
this.options.classList.add('cs-options');
this.list = document.createElement('UL');
var template = '';
for (var i = 0; i < this.el.options.length; i++) {
if (this.el.options[i].value) {
var className = '';
if (this.el.options[i].selected) {
this.selected.push(this.el.options[i].textContent);
className = 'cs-selected';
}
template += '
' + this.el.options[i].textContent + '';
}
}
this.arrow = document.createElement('span');
this.arrow.className = 'cs-placeholder-before project-input__icon';
var settings = window.formSettings['select'];
if (settings && !settings.use_defaults) {
this.arrow.className += ' has-svg';
this.arrow.innerHTML = '\n \n \n \n
';
} else {
this.arrow.className += ' ' + (document.body.getAttribute('data-form-icon-font') || 'font-awesome');
this.arrow.innerHTML = '';
}
this.title.innerHTML = '\n \n ' + (this.selected.length ? this.selected.join(', ') : 'Select') + '\n \n ';
this.title.appendChild(this.arrow);
this.list.innerHTML = template;
this.wrapper.appendChild(this.title);
this.wrapper.appendChild(this.options);
this.options.appendChild(this.list);
this.el.parentNode.insertBefore(this.wrapper, this.el);
this.wrapper.appendChild(this.el);
}
}, {
key: '_onClick',
value: function _onClick() {
var _this = this;
if (!this.wrapper) {
return false;
}
this.wrapper.addEventListener('click', function (event) {
var target = event.target;
_this.target = target;
if (target.tagName === "LI") {
_this._setActive(target);
}
if (target.tagName === "SPAN" && target.classList.contains('cs-placeholder')) {
_this._setOpen(target);
}
});
}
}, {
key: '_setActive',
value: function _setActive(target) {
var index = target.getAttribute('data-index');
if (this.el.options[index].selected) {
target.classList.remove('cs-selected');
this.el.options[index].selected = false;
var i = this.selected.indexOf(this.el.options[index].textContent);
i !== -1 ? this.selected.splice(i, 1) : [];
this.select.hasActive = false;
} else {
target.classList.add('cs-selected');
this.el.options[index].selected = true;
this.selected.push(this.el.options[index].textContent);
this.select.hasActive = true;
}
this.title.innerHTML = '\n \n ' + (this.selected.length ? this.selected.join(', ') : 'Select') + '\n \n ';
this.title.appendChild(this.arrow);
}
// TODO test this
}, {
key: '_setOpen',
value: function _setOpen(target) {
if (target.parentNode.classList.contains('cs-active')) {
target.classList.remove('project-input_focused');
target.parentNode.classList.remove('cs-active');
this.isOpened = false;
//document.removeEventListener('click', this.close.bind(this));
} else {
target.classList.add('project-input_focused');
target.parentNode.classList.add('cs-active');
this.isOpened = true;
//document.addEventListener('click', this.close.bind(this));
}
}
}, {
key: 'close',
value: function close() {
if (!this.wrapper || !this.title) {
return false;
}
this.title.classList.remove('project-input_focused');
this.wrapper.classList.remove('cs-active');
this.isOpened = false;
}
}, {
key: 'el',
get: function get() {
return this._params.el;
}
}, {
key: 'select',
get: function get() {
return this._params.select;
}
}]);
return Multiselect;
}();
exports.default = Multiselect;
/***/ })
}]);