%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/js/landing/ui/field/ |
Current File : /home/bitrix/www/bitrix/js/landing/ui/field/multiselect_field.min.js |
(function(){"use strict";BX.namespace("BX.Landing.UI.Field");var t=BX.Landing.Utils.addClass;var i=BX.Landing.Utils.hasClass;var n=BX.Landing.Utils.removeClass;var e=BX.Landing.Utils.isArray;var a=BX.Landing.Utils.isFunction;var s=BX.Landing.Utils.create;var l=BX.Landing.Utils.random;var o=BX.Landing.Utils.escapeHtml;var u=BX.Landing.Utils.append;var p=BX.Landing.Utils.slice;var d=BX.Landing.Utils.encodeDataValue;var r=BX.Landing.Utils.remove;var h=BX.Landing.Utils.data;var c=BX.Landing.Utils.bind;var g=BX.Landing.Utils.style;var f=BX.Landing.Utils.clone;var v=BX.Landing.Utils.offsetLeft;var m=BX.Landing.Utils.offsetTop;var B=BX.Landing.Utils.findParent;var C=BX.Landing.Utils.decodeDataValue;var L=BX.Landing.Collection.BaseCollection;var X=BX.Landing.UI.Tool.Popup;function U(t,i,n){t.forEach(function(t){var a=new BX.Landing.UI.Field.Checkbox({id:t.value,items:[{name:t.name,value:t.value,checked:t.selected}],depth:n,compact:true,onChange:i.onCheckboxChange});i.fields.add(a);if(a.layout){u(a.layout,i.getPopup().contentContainer)}if(t.selected){i.addPlaceholder(t)}if(e(t.items)){n+=1;U(t.items,i,n);n-=1}})}BX.Landing.UI.Field.MultiSelect=function(i){BX.Landing.UI.Field.BaseField.apply(this,arguments);t(this.layout,"landing-ui-field-multiselect");this.onChangeHandler=a(i.onChange)?i.onChange:function(){};this.items=e(i.items)?i.items:[];this.value=e(i.value)?i.value:null;this.content=this.value;this.fields=new L;this.button=new BX.Landing.UI.Button.BaseButton("dropdown_button",{text:BX.message("LINK_URL_SUGGESTS_SELECT"),className:"landing-ui-button-select-link",onClick:this.onButtonClick.bind(this)});this.grid=s("div",{props:{className:"landing-ui-field-multiselect-grid"},children:[s("div",{props:{className:"landing-ui-field-multiselect-grid-left"},children:[this.input]}),s("div",{props:{className:"landing-ui-field-multiselect-grid-right"},children:[this.button.layout]})]});u(this.grid,this.layout);this.onInputClick=this.onInputClick.bind(this);this.onCheckboxChange=this.onCheckboxChange.bind(this);c(this.input,"click",this.onInputClick);c(top.document,"click",this.onDocumentClick.bind(this));requestAnimationFrame(function(){U(this.items,this,0);if(e(this.value)){this.value=this.value.map(function(t){return C(t)});this.setValue(this.value,true)}else{this.value=this.getValue();this.content=this.value}}.bind(this))};BX.Landing.UI.Field.MultiSelect.prototype={constructor:BX.Landing.UI.Field.MultiSelect,__proto__:BX.Landing.UI.Field.BaseField.prototype,addPlaceholder:function(t){var i=s("div",{props:{className:"landing-ui-field-multiselect-placeholder"},attrs:{"data-item":d(t),title:o(t.name)},children:[s("span",{props:{className:"landing-ui-field-multiselect-placeholder-text"},html:o(t.name)}),s("span",{props:{className:"landing-ui-field-multiselect-placeholder-remove"},events:{click:this.onPlaceholderRemoveClick.bind(this,t)}})]});u(i,this.input)},onPlaceholderRemoveClick:function(t,i,n){if(i){i.preventDefault();i.stopPropagation()}var e=this.getPlaceholderByItem(t);if(e){r(e);this.adjustPopupPosition();var a=this.fields.get(t.value);if(a){a.layout.querySelector("input").checked=false}}if(!n){this.onValueChangeHandler(this)}},onCheckboxChange:function(t){var i=t.getValue();if(i.length){this.addPlaceholder(t.items[0]);this.adjustPopupPosition()}else{this.onPlaceholderRemoveClick(t.items[0],null,true)}this.onValueChangeHandler(this)},getPlaceholderByItem:function(t){return p(this.input.children).find(function(i){return h(i,"data-item").value===t.value})},getPopup:function(){if(this.popup){return this.popup}this.popup=new X({id:this.selector+"_"+l(),bindElement:this.input,autoHide:true,events:{onPopupClose:function(){n(this.input,"landing-ui-active");if(i(this.layout.parentElement.parentElement,"landing-ui-form-style")){void g(this.layout.parentElement.parentElement,{"z-index":null,position:null})}}.bind(this)}});if(this.popup.popupContainer){t(this.popup.popupContainer,"landing-ui-field-multiselect-popup");var e=B(this.input,{className:"landing-ui-panel-content-body-content"},document.body);if(e){u(this.popup.popupContainer,e)}}return this.popup},showPopup:function(){this.getPopup().show();this.adjustPopupPosition();this.setValue(this.getValue(),true)},adjustPopupPosition:function(){if(this.popup){var t=B(this.input,{className:"landing-ui-panel-content-body-content"});var i=m(this.input,t);var n=v(this.input,t);var e=this.input.getBoundingClientRect();var a=2;requestAnimationFrame(function(){this.popup.popupContainer.style.top=i+e.height+a+"px";this.popup.popupContainer.style.left=n+"px";this.popup.popupContainer.style.width=e.width+"px"}.bind(this))}},onInputClick:function(i){if(i){i.stopPropagation()}var e=this.getPopup();if(e.isShown()){n(this.input,"landing-ui-active");return e.close()}t(this.input,"landing-ui-active");return this.showPopup()},onButtonClick:function(t){t.preventDefault();t.stopPropagation();this.onInputClick()},onDocumentClick:function(){this.getPopup().close()},getValue:function(){return p(this.input.children).map(function(t){return h(t,"data-item").value})},isChanged:function(){var t=f(this.content).sort();var i=this.getValue().sort();return JSON.stringify(t)!==JSON.stringify(i)},getItemByValue:function(t,i){var n=null;function e(t,i){return t.forEach(function(t){if(i==t.value){n=t;return}if(t.items){e(t.items,i)}},this)}e(t,i);return n},setValue:function(t,i){if(e(t)){this.input.innerHTML="";t.forEach(function(t){var i=this.getItemByValue(this.items,t);if(i){this.addPlaceholder(i)}},this)}if(!i){this.onValueChangeHandler(this)}}}})();