Current Path : /var/www/www-root/data/www/monolith-realty.ru/bitrix/js/landing/ui/button/ |
Current File : /var/www/www-root/data/www/monolith-realty.ru/bitrix/js/landing/ui/button/ai_copilot_button.min.js |
(function(){"use strict";BX.namespace("BX.Landing.UI.Button");const t=980;const i=42;const n=4;const e=66;BX.Landing.UI.Button.AiCopilot=function(t,i){BX.Landing.UI.Button.EditorAction.apply(this,arguments);this.options=i;this.onReplace=i.onReplace;this.onReplaceContext=i.onReplaceContext;this.onAddBelow=i.onAddBelow;this.editor=i.editor;this.clientHeight=document.documentElement.clientHeight;this.clientWidth=document.documentElement.clientWidth};BX.Landing.UI.Button.AiCopilot.getInstance=function(t,i){if(!BX.Landing.UI.Button.AiCopilot.instance){BX.Landing.UI.Button.AiCopilot.instance=new BX.Landing.UI.Button.AiCopilot(t,i)}return BX.Landing.UI.Button.AiCopilot.instance};BX.Landing.UI.Button.AiCopilot.prototype={constructor:BX.Landing.UI.Button.AiCopilot,__proto__:BX.Landing.UI.Button.EditorAction.prototype,onClick(){if(!BX.Landing.Env.getInstance().getOptions()["ai_text_active"]&&BX.Landing.Main.getInstance()["options"]["ai_unactive_info_code"]){BX.UI.InfoHelper.show(BX.Landing.Main.getInstance()["options"]["ai_unactive_info_code"]);return}if(!this.isInit){BX.Dom.addClass(this.layout,"active");this.clickBeforeInit=true}this.context=" ";const i=window.getSelection().toString();if(i!==""){this.context=i;this.selectedContext=true}if(this.context===" "&&this.editor.currentElement){const t=this.editor.currentElement.querySelector(".landing-ui-field-input");if(t){this.context=t.innerHTML}else{this.context=this.editor.currentElement.innerHTML}}const n=this.editor.currentElement;if(this.copilot&&this.currentElement===this.editor.currentElement){this.hideEditorPanel(true);this.copilot.setSelectedText(this.context);this.copilot.show({currentElement:n,width:t});return}this.currentElement=this.editor.currentElement;if(this.isInit){this.hideEditorPanel(true);this.copilot.setSelectedText(this.context);this.copilot.show({currentElement:n,width:t})}},onMouseOver(){if(!this.copilot){const t=top.BX.AI?top.BX.AI.Copilot:BX.AI.Copilot;this.copilot=new t({moduleId:"landing",contextId:this.getContext(),category:"landing"});this.copilot.subscribe("finish-init",this.finishInitHandler.bind(this));this.copilot.subscribe("save",this.saveHandler.bind(this));this.copilot.subscribe("add_below",this.addBelowHandler.bind(this));BX.Event.EventEmitter.subscribe("BX.Landing.Node.Text:onMousedown",this.onClickHandler.bind(this));BX.Event.EventEmitter.subscribe("BX.Landing.Node.Img:onClick",this.onClickHandler.bind(this));BX.Event.EventEmitter.subscribe("BX.Landing.Node.Icon:onClick",this.onClickHandler.bind(this));BX.Event.EventEmitter.subscribe("BX.Landing.UI.Panel.ContentEdit:onClick",this.onClickHandler.bind(this));BX.Event.bind(document,"keydown",this.onWindowKeyDownHandler.bind(this));BX.Event.bind(document,"click",this.onClickHandler.bind(this));BX.Event.bind(document,"scroll",this.onScrollHandler.bind(this));this.copilot.init()}},finishInitHandler(){this.copilot.setSelectedText(this.context);this.copilotPositionTop=(this.clientHeight-i)/2;this.copilotPositionLeft=(this.clientWidth-t)/2;this.isInit=true;if(this.clickBeforeInit===true){this.hideEditorPanel(true);const i=this.editor.currentElement;this.copilot.show({currentElement:i,width:t});BX.Dom.removeClass(this.layout,"active")}},saveHandler(t){if(this.selectedContext===true){this.onReplaceContext(t.data.result)}else{this.onReplace(t.data.result)}if(this.copilot.isShown()){this.copilot.hide()}},addBelowHandler(t){this.onAddBelow(t.data.result);if(this.copilot.isShown()){this.copilot.hide()}},onWindowKeyDownHandler(t){if(t.key==="Escape"&&this.copilot.isShown()){this.copilot.hide()}},onClickHandler(){if(this.copilot.isShown()){this.copilot.hide()}},onScrollHandler(){const t=window.scrollY;if(!this.lastScrollY){this.lastScrollY=t}const o=t-this.lastScrollY;this.lastScrollY+=o;this.copilotPositionTop-=o;let s=this.copilotPositionTop;if(this.copilotPositionTop<e+n){s=e+n}const l=this.clientHeight+e-(i+n);if(this.copilotPositionTop>l){s=l}this.copilot.adjust({position:{top:s,left:this.copilotPositionLeft}})},getContext(){if(this.editor.currentElement){return"editor"}return"edit_block_slider"},hideEditorPanel(t){if(t){const t=this.editor.currentElement.querySelector(".landing-ui-field-input");if(!t){BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}else{BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}}})(); //# sourceMappingURL=ai_copilot_button.map.js