Your IP : 18.118.9.105


Current Path : /home/bitrix/ext_www/klimatlend.ua/bitrix/js/ui/dropdown/
Upload File :
Current File : /home/bitrix/ext_www/klimatlend.ua/bitrix/js/ui/dropdown/dropdown.min.js

(function(){"use strict";BX.namespace("BX.UI");BX.UI.Dropdown=function(t){this.popupWindow=null;this.items=[];this.defaultItems=[];this.itemsContainer=null;this.popupConatiner=null;this.footerItems=null;this.targetElement=t.targetElement;this.CurrentItem=null;this.searchAction=BX.prop.getString(t,"searchAction","");this.searchOptions=BX.prop.getObject(t,"searchOptions",{});this.messages=BX.prop.getObject(t,"messages",{});this.isChanged=false;this.enableCreation=BX.prop.getBoolean(t,"enableCreation",false);this.documentClickHandler=BX.delegate(this.onDocumentClick,this);this.emptyValueEventHandle=0;this.events=t.events||{};this.updateItemsList(t.items);this.setDefaultItems(t.items);this.setFooterItems(t.footerItems);if(this.targetElement!=="undefined"){this.init()}};BX.UI.Dropdown.prototype={init:function(){BX.bind(this.targetElement,"input",function(){if(this.targetElement.value.length===0){this.enableTargetElement()}this.getPopupWindow().show()}.bind(this));this.targetElement.addEventListener("click",function(){if(this.CurrentItem&&this.CurrentItem.title.length===this.targetElement.value.length){this.disableTargetElement()}else if(this.targetElement.value.length>0){this.disableTargetElement()}if(this.popupWindow){BX.PreventDefault()}this.getPopupWindow().show()}.bind(this),true);this.targetElement.addEventListener("focus",function(){this.getPopupWindow().show();if(!this.popupAlertContainer){return}}.bind(this),true);BX.bind(this.targetElement,"keyup",BX.throttle(function(t){if(this.targetElement.value===""){return}if(t.key==="Escape"){if(this.targetElement.value!==""&&!this.popupWindow){this.getPopupWindow().show()}else{BX.PreventDefault()}}}.bind(this),1e3));this.targetElement.addEventListener("keyup",function(t){if(t.keyCode===40){this.handleDownArrow()}else if(t.keyCode===38){this.handleUpArrow()}else if(t.keyCode===13){if(this.highlightedItem){this.handleItemClick(this.highlightedItem);this.getPopupWindow().close()}}else{this.handleTypeInField()}if(this.targetElement.value!==""&&!this.popupWindow){this.getPopupWindow().show();return}if(t.keyCode===9&&!this.popupWindow){this.getPopupWindow().show();return}if(t.keyCode===9&&this.targetElement.value===""&&!this.popupWindow){this.getPopupWindow().show()}if(!this.enableCreation){this.targetElement.addEventListener("keyup",function(t){if(t.key==="Escape"){this.resetInputValue()}}.bind(this));BX.bind(document,"click",this.documentClickHandler)}}.bind(this));this.targetElement.addEventListener("keydown",function(t){if(t.keyCode===9&&this.CurrentItem&&this.CurrentItem.title.length!==this.targetElement.value.length||t.keyCode===9&&!this.CurrentItem&&this.targetElement.value.length>0){this.onEmptyValueEvent();return}if(t.keyCode===9&&!this.popupWindow){this.getPopupWindow().show();return}if(t.keyCode===9&&this.targetElement.value===""&&!this.popupWindow){this.getPopupWindow().show();return}if(t.keyCode===9&&this.popupWindow){this.destroyPopupWindow()}}.bind(this));if(this.events){for(var t in this.events){if(BX.type.isFunction(this.events[t])){BX.addCustomEvent(this,"BX.UI.Dropdown:"+t,this.events[t])}}}},onDocumentClick:function(){if(this.CurrentItem&&this.CurrentItem.title.length!==this.targetElement.value.length||!this.CurrentItem&&this.targetElement.value.length>0){this.onEmptyValueEvent()}},getDefaultItems:function(){return this.defaultItems},setDefaultItems:function(t){this.defaultItems=t},getItems:function(){return this.items},updateItemsList:function(t){this.setDefaultItems(t);this.setItems(t);for(var e=0;e<t.length;e++){t[e].searchField=t[e].title+t[e].subtitle+t[e].phone+t[e].email;t[e].searchField=t[e].searchField.toLowerCase()}},setItems:function(t){this.items=t;if(this.popupWindow){this.renderItemsToInnerContainer()}},handleTypeInField:function(){if(!this.isChanged){this.isChanged=true}var t=this.getItemsListContainer();if(!this.targetElement.value){this.setItems(this.getDefaultItems());t.classList.remove("ui-dropdown-loader-active");BX.cleanNode(this.popupAlertContainer);this.alertEmptyContainer=null;BX.onCustomEvent(this,"BX.UI.Dropdown:onReset",[this])}else if(this.targetElement.value.length>=2){this.searchItemsByStr(this.targetElement.value).then(function(e){if(!this.alertEmptyContainer){this.popupAlertContainer.appendChild(this.getAlertEmptyContainer(e));BX.bind(document,"click",this.documentClickHandler)}this.setItems(e);t.classList.remove("ui-dropdown-loader-active")}.bind(this));t.classList.add("ui-dropdown-loader-active")}},searchItemsByStr:function(t){return BX.ajax.runAction(this.searchAction,{data:{search:t,options:this.searchOptions}}).then(this.onSearchRequestSuccess.bind(this))},onSearchRequestSuccess:function(t){return BX.prop.getArray(t,"data",[])},getFooterItems:function(){return this.footerItems},setFooterItems:function(t){if(Array.isArray(t)){this.footerItems=t}},getPopupWindow:function(){if(!this.popupWindow){this.popupWindow=new BX.PopupWindow("dropdown",this.targetElement,{autoHide:true,content:this.popupConatiner?this.popupContainer:this.getPopupContainer(),contentColor:"white",closeByEsc:true,className:"ui-dropdown-window",events:{onPopupClose:function(){this.popupWindow.destroy();this.popupWindow=null;this.itemListContainer=null;this.itemListInnerContainer=null;this.alertEmptyContainer=null;this.popupAlertContainer=null}.bind(this)}})}this.setWidthPopup();BX.bind(window,"resize",this.setWidthPopup.bind(this));return this.popupWindow},setWidthPopup:function(){if(this.popupWindow&&this.targetElement){this.popupWindow.popupContainer.style.width=this.targetElement.offsetWidth+"px"}},onEmptyValueEvent:function(){this.emptyValueEventHandle=window.setTimeout(function(){this.emptyValueEventHandle=0;if(this.enableCreation){BX.onCustomEvent(this,"BX.UI.Dropdown:onAdd",[this,{title:this.targetElement.value}]);this.setItems(this.getDefaultItems());BX.cleanNode(this.popupAlertContainer);this.alertEmptyContainer=null}else{this.resetInputValue()}}.bind(this),0)},resetInputValue:function(){this.targetElement.value="";BX.onCustomEvent(this,"BX.UI.Dropdown:onReset",[this])},destroyPopupWindow:function(){BX.unbind(document,"click",this.documentClickHandler);if(!this.popupWindow){return}this.popupWindow.close()},getPopupContainer:function(){this.popupContainer=this.getItemsListContainer();this.popupContainer.appendChild(this.getItemsListInnerContainer());this.popupContainer.appendChild(this.getPopupAlertContainer());this.renderItemsToInnerContainer();if(this.footerItems){this.popupContainer.appendChild(this.getLoaderContainer());this.popupContainer.appendChild(this.getFooterContent())}return this.popupContainer},getPopupAlertContainer:function(){if(!this.popupAlertContainer){this.popupAlertContainer=BX.create("div",{attrs:{className:"ui-dropdown-alert-container"}})}return this.popupAlertContainer},getAlertEmptyContainer:function(t){if(!this.alertEmptyContainer){this.alertEmptyContainer=BX.create("div",{props:{className:"ui-dropdown-alert-new"},events:{click:this.onEmptyValueEvent.bind(this)},children:[this.alertEmptyContainerValue=BX.create("div",{attrs:{className:"ui-dropdown-alert-new-name"},text:this.targetElement.value}),BX.create("div",{attrs:{className:"ui-dropdown-alert-new-text"},text:BX.prop.getString(this.messages,this.enableCreation?"creationLegend":"notFound","")})]});this.targetElement.addEventListener("input",function(){this.alertEmptyContainerValue.innerHTML=this.targetElement.value}.bind(this));if(!this.enableCreation){this.targetElement.addEventListener("input",function(){this.alertEmptyContainerValue.style.display="none"}.bind(this))}}if(t.length>0&&!this.enableCreation){this.alertEmptyContainer.style.display="none"}else{this.alertEmptyContainer.style.display=""}return this.alertEmptyContainer},getItemsListContainer:function(){if(!this.itemListContainer){this.itemListContainer=BX.create("div",{attrs:{className:"ui-dropdown-container"}})}return this.itemListContainer},getItemsListInnerContainer:function(){if(!this.itemListInnerContainer){this.itemListInnerContainer=BX.create("div",{attrs:{className:"ui-dropdown-inner"}})}return this.itemListInnerContainer},getItemNodeList:function(){var t=[];this.getItems().forEach(function(e){var i;var n;if(Array.isArray(e.email)){i=e.email[0].value}if(Array.isArray(e.phone)){n=e.phone[0].value}e.node=BX.create("div",{attrs:{className:"ui-dropdown-item"},events:{click:this.handleItemClick.bind(this,e)},children:[BX.create("div",{attrs:{className:"ui-dropdown-item-name"},text:e.title}),BX.create("div",{attrs:{className:"ui-dropdown-item-subname"},text:e.subtitle}),BX.create("div",{attrs:{className:"ui-dropdown-contact-info"},children:[e.phone?BX.create("div",{attrs:{className:"ui-dropdown-contact-info-item ui-dropdown-item-phone"},text:n?n:e.phone}):null,e.email?BX.create("div",{attrs:{className:"ui-dropdown-contact-info-item ui-dropdown-item-email"},text:i?i:e.email}):null]})]});t.push(e.node)},this);return t},renderItemsToInnerContainer:function(){var t=this.getItemsListInnerContainer();BX.cleanNode(t);var e=this.getItemNodeList();for(var i=0;i<e.length;i++){t.appendChild(e[i])}return t},getLoaderContainer:function(){return BX.create("div",{props:{className:"ui-dropdown-loader-container"},html:'<svg class="ui-dropdown-loader" viewBox="25 25 50 50"><circle class="ui-dropdown-loader-path" cx="50" cy="50" r="20" fill="none" stroke-miterlimit="10"></circle><circle class="ui-dropdown-loader-inner-path" cx="50" cy="50" r="20" fill="none" stroke-miterlimit="10"></circle></svg>'})},getFooterContent:function(){var t=BX.create("div",{});this.getFooterItems().forEach(function(e){var i=BX.create("div",{attrs:{className:"ui-dropdown-footer"},children:[BX.create("div",{attrs:{className:"ui-dropdown-caption-box"},children:[BX.create("div",{attrs:{className:"ui-dropdown-caption"},text:e.caption})]})]});e.buttons.forEach(function(t){i.appendChild(BX.create("div",{attrs:{className:"ui-dropdown-button-add"},text:t.caption,events:t.events}))});t.appendChild(i)});return t},handleUpArrow:function(){if(this.alertEmptyContainer&&this.popupAlertContainer.classList.contains("ui-dropdown-item-highlight")){if(this.items&&this.items.length>0){e=this.getItemByIndex(this.items.length-1);this.popupAlertContainer.classList.remove("ui-dropdown-item-highlight");this.cleanHighlightingItem();this.highlightItem(e)}return}if(!this.items){return}var t=this.getHighlightItemIndex();var e=null;if(t===null){e=this.getLastItem()}else{if(this.items.length>=t+1){e=this.getItemByIndex(t-1)}}if(e){this.cleanHighlightingItem();this.highlightItem(e)}},handleDownArrow:function(){var t=this.getHighlightItemIndex();if(this.alertEmptyContainer&&this.popupAlertContainer.classList.contains("ui-dropdown-item-highlight")){return}if(!this.items||this.items.length===0){if(this.alertEmptyContainer&&!this.popupAlertContainer.classList.contains("ui-dropdown-item-highlight")){this.popupAlertContainer.classList.add("ui-dropdown-item-highlight")}return}if(t===this.items.length-1){if(this.alertEmptyContainer&&!this.popupAlertContainer.classList.contains("ui-dropdown-item-highlight")){this.cleanHighlightingItem();this.popupAlertContainer.classList.add("ui-dropdown-item-highlight")}return}var e=null;if(t===null){e=this.getFirstItem()}else{e=this.getItemByIndex(t+1)}if(e){this.cleanHighlightingItem();this.highlightItem(e)}},scrollToItem:function(){var t=this.getItemsListInnerContainer();var e=t.getBoundingClientRect();var i=this.highlightedItem.node.getBoundingClientRect();var n=e.bottom-i.bottom;var s=e.top-i.top;if(n<0){t.scrollTop=t.scrollTop+Math.abs(n)}else if(s>0){t.scrollTop=t.scrollTop-s}},highlightItem:function(t){t.node.classList.add("ui-dropdown-item-highlight");this.highlightedItem=t;this.scrollToItem()},cleanHighlightingItem:function(){if(this.highlightedItem){this.highlightedItem.node.classList.remove("ui-dropdown-item-highlight")}this.highlightedItem=null},getHighlightItemIndex:function(){var t=null;var e=this.getItems();for(var i=0;i<e.length;i++){if(e[i].node.classList.contains("ui-dropdown-item-highlight")){return i}}return t},getItemIndex:function(t){var e=this.getItems();for(var i=0;i<e.length;i++){if(e[i]===t){return i}}return false},getFirstItem:function(){if(!this.items||this.items.length===0){return null}return this.items[0]},getLastItem:function(){var t=this.getItems();if(!t){return}return t[t.length-1]},getItemByIndex:function(t){var e=this.getItems();if(e[t]){return e[t]}return null},setNewItemsForTest:function(){var t=[{title:"Pasha",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"},{title:"Lesha",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"},{title:"Kolya",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"},{title:"UserName",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"},{title:"UserName",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"},{title:"UserName",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"},{title:"UserName",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"},{title:"UserName",subtitle:"developer",phone:"+7 965 954-64-24,",email:"rosros@mail.ru"}];this.updateItemsList(t);return this.getItems()},handleItemClick:function(t,e){if(this.emptyValueEventHandle>0){window.clearTimeout(this.emptyValueEventHandle);this.emptyValueEventHandle=0}this.CurrentItem=t;BX.onCustomEvent(this,"BX.UI.Dropdown:onSelect",[this,t])},selectTargetElementValue:function(){this.targetElement.select();this.targetElement.focus()},disableTargetElement:function(){this.targetElement.select();this.targetElement.focus();this.targetElement.addEventListener("keyup",function(t){var e=t.charCode||t.keyCode;if(this.targetElement===document.activeElement){if(e===8){return true}else if(e===37||e===39){if(this.targetElement.value.length>0&&this.targetElement===document.activeElement){this.selectTargetElementValue()}}else if(this.targetElement.value.length>0&&this.targetElement===document.activeElement){return true}else{BX.PreventDefault()}}}.bind(this))},enableTargetElement:function(){this.targetElement.addEventListener("keyup",function(){return true}.bind(this))}};BX.UI.DropdownUser=function(t){BX.UI.Dropdown.call(this,t)};BX.UI.DropdownUser.prototype={__proto__:BX.UI.Dropdown.prototype,renderItem:function(t){itemsContainer.appendChild(BX.create("div",{attrs:{className:"ui-dropdown-item ui-dropdown-item-user"},children:[BX.create("div",{attrs:{className:"ui-dropdown-item-icon"},text:t.user}),BX.create("div",{attrs:{className:"ui-dropdown-info-box"},children:[BX.create("div",{attrs:{className:"ui-dropdown-item-name"},text:t.title}),BX.create("div",{attrs:{className:"ui-dropdown-item-subname"},text:t.subtitle}),BX.create("div",{attrs:{className:"ui-dropdown-item-value"},text:t.value})]})]}))}}})();