%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/bitrix/www/bitrix/js/landing/ui/field/
Upload File :
Create Path :
Current File : /home/bitrix/www/bitrix/js/landing/ui/field/link_url_field.min.js

(function(){"use strict";BX.namespace("BX.Landing.UI.Field");var e=BX.Landing.Utils.isBoolean;var t=BX.Landing.Utils.isArray;var i=BX.Landing.Utils.isString;var n=BX.Landing.Utils.isEmpty;var a=BX.Landing.Utils.isPlainObject;var s=BX.Landing.Utils.append;var l=BX.Landing.Utils.remove;var r=BX.Landing.Utils.data;var o=BX.Landing.Utils.attr;var h=BX.Landing.Utils.addClass;var u=BX.Landing.Utils.removeClass;var c=BX.Landing.Utils.proxy;var d=BX.Landing.Utils.htmlToElement;var p=BX.Landing.Utils.bind;var g=BX.Landing.Utils.unbind;var L=BX.Landing.Utils.join;var f=BX.Landing.Utils.fireEvent;var y=BX.Landing.Utils.hash;var v=BX.Landing.Utils.encodeDataValue;var T=BX.Landing.Utils.capitalize;var m=BX.Landing.Utils.style;var b=BX.Landing.UI.Button.BaseButton;var B=BX.Landing.UI.Field.Dropdown;var _=BX.Landing.UI.Tool.Menu;var E=BX.Landing.Cache;var I="block";var k="alias";var U="landing";var S="system";var C="catalog";var w="element";var P="section";var X="";var N="tel:";var R="skype:";var D="sms:";var H="mailto:";var A={catalog:new RegExp("^#catalog#(Element|Section)([0-9]+)"),catalogElement:new RegExp("^#catalogElement([0-9]+)"),catalogSection:new RegExp("^#catalogSection([0-9]+)"),block:new RegExp("^#block([0-9]+)"),page:new RegExp("^#landing([0-9]+)"),system:new RegExp("^#system_[a-z_-]+"),alias:new RegExp("^#.*")};BX.Landing.UI.Field.LinkURL=function(i){BX.Landing.UI.Field.Text.apply(this,arguments);h(this.layout,"landing-ui-field-link-url");this.requestOptions=i.options||{};this.allowedTypes=t(i.allowedTypes)?i.allowedTypes:[I,U];this.disableBlocks=e(i.disableBlocks)?i.disableBlocks:false;this.disableCustomURL=e(i.disableCustomURL)?i.disableCustomURL:false;this.disallowType=e(i.disallowType)?i.disallowType:false;this.iblocks=t(i.iblocks)?i.iblocks:null;this.allowedCatalogEntityTypes=t(i.allowedCatalogEntityTypes)?i.allowedCatalogEntityTypes:null;this.enableAreas=i.enableAreas;this.onListShow=this.onListShow.bind(this,this.requestOptions);this.onSelectButtonClick=this.onSelectButtonClick.bind(this);this.onTypeChange=this.onTypeChange.bind(this);this.onListItemClick=this.onListItemClick.bind(this);this.popup=null;this.dynamic=null;this.value=null;this.button=this.createButton();this.hrefTypeSwithcer=this.createTypeSwitcher();this.grid=this.createGridLayout();this.gridLeftCell=this.grid.querySelector('[class*="left"]');this.gridCenterCell=this.grid.querySelector('[class*="center"]');this.gridRightCell=this.grid.querySelector('[class*="right"]');l(this.hrefTypeSwithcer.header);s(this.hrefTypeSwithcer.layout,this.gridLeftCell);s(this.input,this.gridCenterCell);s(this.button.layout,this.gridRightCell);s(this.grid,this.layout);this.setHrefPlaceholderByType(this.getHrefStringType());this.setHrefTypeSwitcherValue(this.getHrefStringType());this.removeHrefTypeFromHrefString();this.makeDisplayedHrefValue();if(this.disallowType){void m(this.gridLeftCell,{display:"none"})}};BX.Landing.UI.Field.LinkURL.TYPE_BLOCK=I;BX.Landing.UI.Field.LinkURL.TYPE_PAGE=U;BX.Landing.UI.Field.LinkURL.TYPE_CATALOG=C;BX.Landing.UI.Field.LinkURL.TYPE_CATALOG_ELEMENT=w;BX.Landing.UI.Field.LinkURL.TYPE_CATALOG_SECTION=P;BX.Landing.UI.Field.LinkURL.matchers=A;BX.Landing.UI.Field.LinkURL.prototype={constructor:BX.Landing.UI.Field.LinkURL,__proto__:BX.Landing.UI.Field.Text.prototype,setIblocks:function(e){this.iblocks=t(e)?e:null},makeDisplayedHrefValue:function(){var e=this.getValue();var t=this.getPlaceholderType();var i;switch(t){case I:i=this.getBlockData(e);break;case U:i=this.getPageData(e);break;case w:i=this.getCatalogElementData(e);break;case P:i=this.getCatalogSectionData(e);break;case S:i=this.getSystemPage(e);break}if(i){i.then(c(this.createPlaceholder,this)).then(c(this.setValue,this)).catch(function(){});this.disableHrefTypeSwitcher();this.setHrefTypeSwitcherValue(X)}this.enableHrefTypeSwitcher()},getPlaceholderData:function(e){e=e||this.getValue();var t=this.getPlaceholderType(e);var i=Promise.resolve({});switch(t){case I:i=this.getBlockData(e);break;case U:i=this.getPageData(e);break;case w:i=this.getCatalogElementData(e);break;case P:i=this.getCatalogSectionData(e);break;case S:i=this.getSystemPage(e);break}return i},removeHrefTypeFromHrefString:function(){var e=this.getValue().replace(new RegExp(this.getHrefStringType(),"g"),"");this.setValue(e,true)},setHrefTypeSwitcherValue:function(e){this.hrefTypeSwithcer.setValue(e)},disableHrefTypeSwitcher:function(){this.hrefTypeSwithcer.disable()},enableHrefTypeSwitcher:function(){this.hrefTypeSwithcer.enable()},getSelectedHrefType:function(){return this.hrefTypeSwithcer.getValue()},getHrefStringType:function(){var e=this.getValue().split(":")[0];var t=X;switch(L(e,":")){case N:t=N;break;case D:t=D;break;case R:t=R;break;case H:t=H;break}return t},setHrefPlaceholderByType:function(e){var t=this.placeholder||BX.message("FIELD_LINK_HREF_PLACEHOLDER");switch(e){case X:if(this.disableBlocks&&this.disableCustomURL){t=BX.message("FIELD_LINK_HREF_PLACEHOLDER_PAGES_ONLY")}if(!this.disableBlocks&&this.disableCustomURL){t=BX.message("FIELD_LINK_HREF_PLACEHOLDER_WITHOUT_CUSTOM_URL")}if(this.allowedTypes.length===1&&this.allowedTypes[0]===C){t=BX.message("FIELD_LINK_HREF_PLACEHOLDER_CATALOG_ONLY")}break;case N:t=BX.message("LANDING_LINK_FIELD_URL_TYPE_PHONE_PLACEHOLDER");break;case R:t=BX.message("LANDING_LINK_FIELD_URL_TYPE_SKYPE_PLACEHOLDER");break;case D:t=BX.message("LANDING_LINK_FIELD_URL_TYPE_SMS_PLACEHOLDER");break;case H:t=BX.message("LANDING_LINK_FIELD_URL_TYPE_EMAIL_PLACEHOLDER");break}r(this.input,"data-placeholder",t)},getPlaceholderType:function(e){e=e||this.getValue();if(A.block.test(e)){return I}if(A.page.test(e)){return U}if(A.catalogElement.test(e)){return w}if(A.catalogSection.test(e)){return P}if(A.system.test(e)){return S}if(A.alias.test(e)){return k}return X},containsPlaceholder:function(){return this.input.innerHTML.indexOf("span")!==-1},createGridLayout:function(){return d('<div class="landing-ui-field-link-url-grid">'+'<div class="landing-ui-field-link-url-grid-left"></div>'+'<div class="landing-ui-field-link-url-grid-center"></div>'+'<div class="landing-ui-field-link-url-grid-right"></div>'+"</div>")},createTypeSwitcher:function(){return new B({items:[{name:BX.message("LANDING_LINK_FIELD_URL_TYPE_LINK"),value:X},{name:BX.message("LANDING_LINK_FIELD_URL_TYPE_PHONE"),value:N},{name:BX.message("LANDING_LINK_FIELD_URL_TYPE_SKYPE"),value:R},{name:BX.message("LANDING_LINK_FIELD_URL_TYPE_SMS"),value:D},{name:BX.message("LANDING_LINK_FIELD_URL_TYPE_EMAIL"),value:H}],onValueChange:this.onTypeChange})},createButton:function(){return new b("dropdown_button",{text:BX.message("LINK_URL_SUGGESTS_SELECT"),className:"landing-ui-button-select-link",onClick:this.onSelectButtonClick})},onTypeChange:function(e){var t=e.getValue();switch(t){case X:g(this.gridRightCell,"mouseover",c(this.onButtonMouseover,this));g(this.gridRightCell,"mouseout",c(this.onButtonMouseout,this));this.button.enable();break;case N:case D:case R:case H:p(this.gridRightCell,"mouseover",c(this.onButtonMouseover,this));p(this.gridRightCell,"mouseout",c(this.onButtonMouseout,this));this.button.disable();break}this.setHrefPlaceholderByType(t)},onButtonMouseover:function(){this.customTypeSuggestTimeout=setTimeout(function(){BX.Landing.UI.Tool.Suggest.getInstance().show(this.button.layout,{description:BX.message("LANDING_LINK_FIELD_URL_TYPE_CUSTOM_BUTTON_TITLE")});this.pulseTimeout=setTimeout(function(){h(this.hrefTypeSwithcer.input,"landing-ui-pulse")}.bind(this),1e3)}.bind(this),100)},onButtonMouseout:function(){clearTimeout(this.customTypeSuggestTimeout);BX.Landing.UI.Tool.Suggest.getInstance().hide();clearTimeout(this.pulseTimeout);u(this.hrefTypeSwithcer.input,"landing-ui-pulse")},getBlockData:function(e){return BX.Landing.UI.Panel.URLList.getInstance().getBlock(e.replace("#block","")).then(function(e){return e.type="block",e})},getPageData:function(e){if(E.has(y(e))){var t=E.get(y(e));if(t&&typeof t==="object"&&typeof t.then==="function"){return t}return Promise.resolve(t)}var i=parseInt(e.replace("#landing",""));var n=BX.Landing.UI.Panel.URLList.getInstance().getLanding(i,this.requestOptions).then(function(t){t=t[0];if(t){var i={type:"landing",id:t.ID,name:t.TITLE};E.set(y(e),i);return i}});E.set(y(e),n);return n},getSystemPage:function(e){if(E.has(y(e))){var t=E.get(y(e));if(t&&typeof t==="object"&&typeof t.then==="function"){return t}return Promise.resolve(t)}var i=this.content.replace("#system_","");var n=BX.Landing.Main.getInstance().options.syspages;if(i in n){var a={type:"system",id:"_"+i,name:n[i].name};E.set(y(e),a);return Promise.resolve(a)}return Promise.reject()},getCatalogElementData:function(e){if(E.has(y(e))){var t=E.get(y(e));if(t&&typeof t==="object"&&typeof t.then==="function"){return t}return Promise.resolve(t)}var i=e.match(A.catalogElement)[1];var n={elementId:i};return BX.Landing.Backend.getInstance().action("Utils::getCatalogElement",n).then(function(t){E.set(y(e),t);return t})},getCatalogSectionData:function(e){if(E.has(y(e))){var t=E.get(y(e));if(t&&typeof t==="object"&&typeof t.then==="function"){return t}return Promise.resolve(t)}var i=e.match(A.catalogSection)[1];var n={sectionId:i};return BX.Landing.Backend.getInstance().action("Utils::getCatalogSection",n).then(function(t){E.set(y(e),t);return t})},createPopup:function(){var e=[];if(this.allowedTypes.includes(I)){e.push({text:BX.message("LANDING_LINKS_BUTTON_BLOCKS"),onclick:this.onListShow.bind(this,I)})}if(this.allowedTypes.includes(U)){e.push({text:BX.message("LANDING_LINKS_BUTTON_LANDINGS"),onclick:this.onListShow.bind(this,U)})}if(this.allowedTypes.includes(C)){e.push({text:BX.message("LANDING_LINKS_BUTTON_CATALOG"),onclick:this.onListShow.bind(this,C)})}this.popup=new _({id:"link_list_"+ +new Date,bindElement:this.button.layout,items:e,autoHide:true,events:{onPopupClose:this.button.deactivate.bind(this.button)}});s(this.popup.popupWindow.popupContainer,this.button.layout.parentNode);return this.popup},onSelectButtonClick:function(){if(this.allowedTypes.length===1&&this.allowedTypes[0]===C){this.onListShow(C);return}this.popup=this.popup||this.createPopup();this.button.enable();this.popup.show();var e=BX.pos(this.button.layout,this.button.layout.parentNode);this.popup.popupWindow.popupContainer.style.top=e.bottom+"px";this.popup.popupWindow.popupContainer.style.left="auto";this.popup.popupWindow.popupContainer.style.right="0"},onListShow:function(e,i){if(this.popup){this.popup.close()}if(i===C){var n=this.iblocks;if(!t(n)){n=BX.Landing.Main.getInstance().options.iblocks}void BX.Landing.UI.Panel.Catalog.getInstance().show(n,this.allowedCatalogEntityTypes).then(this.onListItemClick);return}e.enableAreas=this.enableAreas;void BX.Landing.UI.Panel.URLList.getInstance().show(i,e).then(this.onListItemClick)},isEditPrevented:function(){if(!e(this.editPrevented)){this.editPrevented=this.disableCustomURL||this.containsPlaceholder()}return this.editPrevented},setEditPrevented:function(e){this.editPrevented=e},enableEdit:function(){if(!this.isEditPrevented()&&!this.disableCustomURL){BX.Landing.UI.Field.Text.prototype.enableEdit.apply(this)}},createPlaceholder:function(e){if(i(e)){return e}var t=d('<span class="landing-ui-field-url-placeholder">'+'<span class="landing-ui-field-url-placeholder-preview"></span>'+'<span class="landing-ui-field-url-placeholder-text">'+v(e.name)+"</span>"+'<span class="landing-ui-field-url-placeholder-delete"></span>'+"</span>");var a=t.querySelector('[class*="delete"]');p(a,"click",c(this.onPlaceholderRemoveClick,this));if(!n(e.image)&&i(e.image)){var s=t.querySelector('[class*="preview"]');o(s,{style:"background-image: url('"+e.image+"')"});if(e.subType===P){h(s,"section")}}if(e.type===C){e.chain.push(e.name);var l=L(e.name,"\n",e.chain.join(" / "));o(t,{"data-dynamic":{type:L(C,T(e.subType)),value:e.id},"data-placeholder":L("#",e.type,T(e.subType),e.id),"data-url":L("#",e.type,T(e.subType),e.id)});t.setAttribute("title",l);return t}o(t,{"data-placeholder":L("#",e.type,e.id),"data-url":L("#",e.type,e.id)});t.setAttribute("title",e.name);return t},onPlaceholderRemoveClick:function(e){this.setEditPrevented(false);this.enableEdit();l(e.target.parentNode);this.setValue("");f(this.layout,"input");this.onInputHandler(this.input.innerText)},onListItemClick:function(e){var t=Promise.resolve(e);if(e.type==="block"){t=this.getBlockData("#block"+e.id)}t.then(function(e){this.setValue(this.createPlaceholder(e));this.disableHrefTypeSwitcher();this.setHrefTypeSwitcherValue(X);f(this.layout,"input")}.bind(this))},setValue:function(e,t){if(typeof e==="object"){this.disableEdit();this.setEditPrevented(true);this.input.innerHTML="";s(e,this.input);this.value=e.dataset.placeholder;this.dynamic=e.dataset.dynamic;if(!t){this.onInputHandler(this.input.innerText)}}else{this.setEditPrevented(false);this.input.innerText=e.toString().trim();this.value=null;this.dynamic=null;this.enableHrefTypeSwitcher()}if(!t){this.onValueChangeHandler()}},getDynamic:function(){return this.dynamic},getValue:function(){return this.getSelectedHrefType()+(this.value?this.value:this.input.innerText)}}})();

Zerion Mini Shell 1.0