Current Path : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/landing/ui/field/ |
Current File : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/landing/ui/field/font_field.min.js |
(function(){"use strict";BX.namespace("BX.Landing.UI.Field");BX.Runtime.loadExtension("landing.ui.component.link");var t=BX.Landing.Utils.isFunction;var e=BX.Landing.Utils.isPlainObject;var n=BX.Landing.Utils.bind;var i=BX.Landing.Utils.proxy;var a=BX.Landing.Utils.escapeHtml;var s=BX.Landing.Utils.addClass;var l=BX.Landing.Utils.clone;var o=/g-font-(?!size-|weight-)([a-z0-9-]+)/gi;var r=/[a-z0-9 ]*[a-z0-9]/i;var h=/['|"]/g;var c=/ /g;var u=["H1","H2","H3","H4","H5","H6","H7"];BX.Landing.UI.Field.Font=function(l){BX.Landing.UI.Field.BaseField.apply(this,arguments);s(this.layout,"landing-ui-field-font");this.value=l.value;this.headlessMode=l.headlessMode===true;this.frame=l.frame;this.items=[];this.defaultFontFamily=null;this.defaultFontLink=new BX.Landing.UI.Component.Link({text:BX.Landing.Loc.getMessage("LANDING_EDIT_BLOCK_DEFAULT_FONT")});s(this.defaultFontLink.getLayout(),"landing-ui-field-font-link");if(e(l.items)){var o=Object.keys(this.items);this.items=o.map((function(t){return{name:this.items[t],value:t}}),this)}this.onChangeHandler=t(l.onChange)?l.onChange:function(){};this.onValueChangeHandler=t(l.onValueChange)?l.onValueChange:function(){};if(this.value){this.content=a(this.value.family);this.input.innerHTML=this.value.family}else{this.content=a(this.content);this.input.innerHTML=this.content}if(this.frame){if(l.styleNode.currentTarget){this.element=l.styleNode.currentTarget}else{this.element=this.frame.document.querySelectorAll(this.selector)[0]}if(this.element){var r=BX.style(this.element,"font-family");if(r){r=r.replace(h,"");this.content=r.split(",")[0];this.input.innerHTML=this.content}this.createLinkContainer();this.setConditionLink()}}if(this.content.search(new RegExp("var\\(--[a-z-]*\\)"))!==-1){var c=window.getComputedStyle(document.body).getPropertyValue("font-family");this.input.innerHTML=c.replace(h,"").split(",")[0]}n(this.input,"click",i(this.onInputClick,this));this.defaultFontLink.subscribe("onClick",i(this.onDefaultFontLinkClick,this))};function d(t){return"g-font-"+t.toLowerCase().replace(c,"-")}BX.Landing.UI.Field.Font.prototype={constructor:BX.Landing.UI.Field.Font,__proto__:BX.Landing.UI.Field.BaseField.prototype,onInputClick:function(t){t.preventDefault();t.stopPropagation();BX.Landing.UI.Panel.GoogleFonts.getInstance().show().then(function(t){if(!this.response){this.response=l(BX.Landing.UI.Panel.GoogleFonts.getInstance().response);this.response.forEach((function(t){this.items.push({name:t.family,value:d(t.family)})}),this)}this.setValue(t)}.bind(this))},onDefaultFontLinkClick:function(){if(this.defaultFontFamily){const t=this.element.classList.value.match(o);if(t!==null){t.forEach((t=>{this.element.classList.remove(t)}))}this.content=this.defaultFontFamily.replace(h,"").split(",")[0];const e={family:this.content};this.setValue(e)}},createLinkContainer:function(){this.linkContainer=document.createElement("div");this.linkContainer.classList.add("landing-ui-component-link-container");this.layout.append(this.linkContainer)},setConditionLink:function(){if(this.element){if(u.includes(this.element.tagName)){const t=document.createElement("H2");document.body.appendChild(t);this.defaultFontFamily=getComputedStyle(t).fontFamily;t.remove()}else{this.defaultFontFamily=getComputedStyle(document.body).fontFamily}this.defaultFont=this.defaultFontFamily.match(r)[0];this.currentFont=getComputedStyle(this.element).fontFamily.match(r)[0];if(this.defaultFont!==this.currentFont){this.linkContainer.append(this.defaultFontLink.getLayout())}else if(this.linkContainer.hasChildNodes()){this.linkContainer.removeChild(this.linkContainer.firstChild)}}},setValue:function(t,n){if(e(t)){var i=d(t.family);var s=[100,200,300,400,500,600,700,800,900];var l=":wght@"+s.join(";");var o=t.family.replace(c,"+");var r=o+l;var h=BX.Landing.UI.Panel.GoogleFonts.getInstance().client.makeUrl({family:r});if(this.headlessMode){this.value={family:t.family,public:"https://fonts.google.com/specimen/"+o,uri:h};this.input.innerHTML=a(t.family);this.emit("onChange")}else{const e=BX.Landing.UI.Tool.FontManager.getInstance();e.addFont({className:i,family:o,href:h,category:t.category},window);this.input.innerHTML=a(t.family);this.onChangeHandler(i,this.items,this.postfix,this.property);this.onValueChangeHandler(this);e.removeUnusedFonts();if(!n){let t="";e.getUsedLoadedFonts().forEach((function(e){if(e.element){e.element.setAttribute("rel","stylesheet");e.element.removeAttribute("media");t+="<noscript>"+e.element.outerHTML+"</noscript>\n";e.element.setAttribute("rel","preload");e.element.setAttribute("onload","this.removeAttribute('onload');this.rel='stylesheet'");e.element.setAttribute("as","style");t+=e.element.outerHTML+"\n"}if(e.CSSDeclaration){t+=e.CSSDeclaration.outerHTML}}));t=t.replace("async@load","all").replace(/data-loadcss="true"/g,"");BX.Landing.Backend.getInstance().action("Landing::updateHead",{content:t})}}}this.setConditionLink()},getValue:function(){return this.value},onFrameLoad:function(){const t=Array.from(this.element.classList.value.matchAll(o));if(t&&t.length>0){const e=t[t.length-1][1].split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join(" ");this.content=e;this.setValue({family:e},true)}}}})(); //# sourceMappingURL=font_field.map.js