Current Path : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/landing/ui/panel/ |
Current File : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/landing/ui/panel/editor_panel.min.js |
(function(){"use strict";BX.namespace("BX.Landing.UI.Panel");var t=BX.Landing.Utils.proxy;var n=BX.Landing.Utils.getSelectedElement;BX.Landing.UI.Panel.EditorPanel=function(){BX.Landing.UI.Panel.BaseButtonPanel.apply(this,arguments);this.layout.classList.add("landing-ui-panel-editor");this.position="absolute";this.currentElement=null;this.outOfFrame=true;this.onKeydown=this.onKeydown.bind(this);this.onTabDown=this.onTabDown.bind(this);this.onScroll=this.onScroll.bind(this)};BX.Landing.UI.Panel.EditorPanel.instance=null;BX.Landing.UI.Panel.EditorPanel.getInstance=function(){if(!BX.Landing.UI.Panel.EditorPanel.instance){BX.Landing.UI.Panel.EditorPanel.instance=new BX.Landing.UI.Panel.EditorPanel;BX.Landing.UI.Panel.EditorPanel.instance.init()}return BX.Landing.UI.Panel.EditorPanel.instance};var e=null;var i=null;function o(t){var n=new BX.Landing.UI.Button.EditorAction("drag",{html:'<strong class="landing-ui-drag"> </strong>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DRAG")}});n.layout.onbxdrag=s.bind(this);n.layout.onbxdragstop=d.bind(this);jsDD.registerObject(n.layout);t.prependButton(n);var e;var i;var o;var a;function s(n,s){if(!e){var d=BX.pos(jsDD.current_node);i=Math.max(Math.abs(n-d.left),0);o=Math.max(Math.abs(s-d.top),0);e=true}BX.DOM.write(function(){t.layout.classList.remove("landing-ui-transition");if(BX.Landing.PageObject.getEditorWindow().scrollY>0){a=s-o}else{a=s+o}t.layout.style.top=a+"px";t.layout.style.left=n-i+"px"}.bind(this))}function d(){e=false;t.layout.classList.add("landing-ui-transition")}}function a(n){n.addButton(new BX.Landing.UI.Button.EditorAction("bold",{html:'<span class="landing-ui-icon-editor-bold"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_BOLD")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("italic",{html:'<span class="landing-ui-icon-editor-italic"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ITALIC")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("underline",{html:'<span class="landing-ui-icon-editor-underline"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_UNDERLINE")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("strikeThrough",{html:'<span class="landing-ui-icon-editor-strike"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_STRIKE")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("justifyLeft",{html:'<span class="landing-ui-icon-editor-left"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_LEFT")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("justifyCenter",{html:'<span class="landing-ui-icon-editor-center"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_CENTER")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("justifyRight",{html:'<span class="landing-ui-icon-editor-right"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_RIGHT")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("justifyFull",{html:'<span class="landing-ui-icon-editor-justify"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_JUSTIFY")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.CreateLink("createLink",{html:'<span class="landing-ui-icon-editor-link"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_CREATE_LINK")},onClick:t(n.adjustButtonsState,n)}));var e=BX.Landing.Env.getInstance().getOptions().rights;if(e&&e.includes("edit")){n.addButton(new BX.Landing.UI.Button.CreatePage("createPage",{html:'<span class="landing-ui-icon-editor-new-page"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_CREATE_PAGE")},onClick:t(n.adjustButtonsState,n)}))}n.addButton(new BX.Landing.UI.Button.EditorAction("unlink",{html:'<span class="landing-ui-icon-editor-unlink"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_UNLINK")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("insertUnorderedList",{html:'<span class="fa fa-list-ul"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_UL")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("insertOrderedList",{html:'<span class="fa fa-list-ol"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_OL")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.EditorAction("removeFormat",{html:'<span class="landing-ui-icon-editor-eraser"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_CLEAR")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.ColorAction("foreColor",{text:BX.Landing.Loc.getMessage("EDITOR_ACTION_SET_FORE_COLOR"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_COLOR")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.TextBackgroundAction("hiliteColor",{html:'<span class="landing-ui-icon-editor-text-background"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TEXT_BACKGROUND")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.CreateTable("createTable",{html:'<span class="landing-ui-icon-editor-table"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_CREATE_TABLE")},onClick:t(n.adjustButtonsState,n)}));n.addButton(new BX.Landing.UI.Button.PasteTable("pasteTable",{html:'<span class="landing-ui-icon-editor-copy"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_PASTE_TABLE")},onClick:t(n.adjustButtonsState,n)}));if(BX.Landing.Main.getInstance()["options"]["copilot_available"]){n.addButton(new BX.Landing.UI.Button.AiCopilot.getInstance("ai_copilot",{html:"CoPilot",editor:n,onReplace(t){const e=n.currentElement.querySelector(".landing-ui-field-input");if(e){e.innerHTML=`<div>${t}</div>`}else if(n.currentElement){n.currentElement.innerHTML=`<div>${t}</div>`}},onReplaceContext(t){const n=window.getSelection().getRangeAt(0);n.deleteContents();n.insertNode(document.createTextNode(t))},onAddBelow(t){const e=n.currentElement.querySelector(".landing-ui-field-input");if(e){e.innerHTML=`${e.innerHTML}<div>${t}</div>`}else if(n.currentElement){n.currentElement.innerHTML=`${n.currentElement.innerHTML}<div>${t}</div>`}}}))}}var s={top:0,left:0};function d(t,n,e){var i=n.getBoundingClientRect();var o=i.left+i.width/2-t.rect.width/2;var a=i.top-t.rect.height-4;var d="absolute";var l=t.outOfFrame?window.parent:window;var r=n.closest(".landing-ui-panel-content-body-content");if(r){if(n.classList.contains("landing-ui-field")){a+=l.pageYOffset}else{a=r.getBoundingClientRect().top+5;d="fixed"}}else if(BX.Landing.Main.getInstance().isControlsExternal()){a+=71}else{if(a<=5&&(i.bottom>l.innerHeight||i.height>l.innerHeight/1.5)){a=5;d="fixed"}else{if(a>5){a+=l.pageYOffset+66}else{a=i.bottom+4+l.pageYOffset}}}if(t.outOfFrame&&t.contextDocument!==a.document&&t.contextDocument.defaultView.frameElement){o+=t.contextDocument.defaultView.frameElement.getBoundingClientRect().left}if(o+t.rect.width>l.innerWidth-20){o-=o+t.rect.width-(l.innerWidth-20)}o=Math.max(20,o);if(s.top!==a||s.left!==o||e){BX.DOM.write((function(){t.layout.style.position=d;t.layout.style.top=a+"px";t.layout.style.left=o+"px"}));s.top=a;s.left=o;B(t)}}function l(t){if(t.outOfFrame){window.parent.document.body.appendChild(t.layout)}else{window.document.body.appendChild(t.layout)}}var r=null;function u(t){r=t.target}var c=false;function g(t){c=r!==t.target}function h(t){if(c){t.preventDefault();t.stopPropagation()}}function f(t){if(t.popup){t.popup.close()}if(t.menu){t.menu.close()}}function B(t){t.buttons.forEach(f);if(t.additionalButtons){t.additionalButtons.forEach(f)}BX.Landing.UI.Tool.ColorPicker.hideAll()}BX.Landing.UI.Panel.EditorPanel.prototype={constructor:BX.Landing.UI.Panel.EditorPanel,__proto__:BX.Landing.UI.Panel.BaseButtonPanel.prototype,init:function(){o(this);a(this);l(this);this.rect=this.layout.getBoundingClientRect()},show:function(n,e,i,o,a){if(!o){this.showBaseButtons()}else{if(a){if(a.length>0){this.showBaseButtons();this.hideBaseButtons(a)}else{this.hideAllBaseButtons()}}else{this.hideAllBaseButtons()}}this.currentElement=n;this.setContextDocument(this.currentElement?this.currentElement.ownerDocument:document);if(this.additionalButtons){this.additionalButtons.forEach((function(t){this.buttons.remove(t);f(t);BX.remove(t.layout)}),this);this.additionalButtons=null}if(i){this.additionalButtons=i;this.additionalButtons.forEach((function(t){if(t.insertAfter){var n=this.layout.querySelector('[data-id="'+t.insertAfter+'"]');if(n){BX.insertAfter(t.layout,n);this.buttons.add(t)}}else{this.addButton(t)}if(t.insertBefore){const n=this.layout.querySelector(`[data-id="${t.insertBefore}"]`);if(n){BX.insertBefore(t.layout,n);this.buttons.add(t)}else{this.addButton(t)}}}),this)}if(!this.isShown()){BX.onCustomEvent("BX.Landing.Editor:enable",[n]);this.contextDocument.addEventListener("mousedown",u,true);this.contextDocument.addEventListener("mouseup",g,true);this.contextDocument.addEventListener("click",h,true);this.currentElement.addEventListener("click",t(this.adjustButtonsState,this),true);setTimeout(function(){this.layout.classList.add("landing-ui-transition")}.bind(this),100)}BX.Landing.UI.Panel.BaseButtonPanel.prototype.show.call(this,arguments);BX.DOM.write(function(){this.rect=this.layout.getBoundingClientRect();this.adjustPosition(n,e,true)}.bind(this));this.onShow(n);this.adjustButtonsState();this.adjustButtonsContextDocument()},onShow:function(t){i=t;e=e||this.onScroll.bind(null,t);this.contextDocument.addEventListener("keydown",this.onKeydown);this.contextWindow.addEventListener("resize",e);try{this.contextDocument.addEventListener("scroll",e,{passive:true})}catch(t){this.contextDocument.addEventListener("scroll",e)}},hide:function(){if(this.isShown()){BX.onCustomEvent("BX.Landing.Editor:disable",[null]);this.contextDocument.removeEventListener("mousedown",u,true);this.contextDocument.removeEventListener("mouseup",g,true);this.contextDocument.removeEventListener("click",h,true);this.currentElement.removeEventListener("click",t(this.adjustButtonsState,this),true);setTimeout(function(){this.rect=this.layout.getBoundingClientRect();this.layout.classList.remove("landing-ui-transition")}.bind(this),100)}BX.Landing.UI.Panel.BaseButtonPanel.prototype.hide.call(this,arguments);this.onHide()},onHide:function(){this.contextDocument.removeEventListener("keydown",this.onKeydown);this.contextWindow.removeEventListener("resize",e);try{this.contextDocument.removeEventListener("scroll",e,{passive:true})}catch(t){this.contextDocument.removeEventListener("scroll",e)}},onKeydown:function(t){if(t.key==="Tab"&&t.target.nodeName!=="LI"){t.preventDefault();if(!t.shiftKey){if(t.code==="Tab"){this.onTabDown()}else{this.contextDocument.execCommand("indent")}}else{this.contextDocument.execCommand("outdent")}}if(t.key==="Enter"&&t.target.nodeName!=="LI"&&t.target.nodeName!=="UL"&&t.metaKey===true){t.preventDefault();const n=this.contextWindow.getSelection().getRangeAt(0);const e=BX.create("br");n.deleteContents();n.insertNode(e);const i=this.contextDocument.createRange();i.setStartAfter(e);i.collapse(true);const o=this.contextWindow.getSelection();o.removeAllRanges();o.addRange(i)}setTimeout((function(){BX.Landing.UI.Panel.EditorPanel.getInstance().adjustPosition(i)}),10)},onTabDown:function(){var t=10;var n=true;var e=this.contextWindow.getSelection().focusNode.parentNode.parentNode;while(e.tagName==="DIV"){e=e.parentNode}var i=0;var o=[];var a=["UL","LI","BLOCKQUOTE","DIV"];while(a.indexOf(e.tagName)!==-1){if(e.tagName!=="DIV"){i++;o.push(e)}e=e.parentNode}if(i>t){if(o[o.length-1].tagName==="BLOCKQUOTE"){var s=o[o.length-1].previousSibling;while(s!==null&&s.nodeType!==1){s=s.previousSibling}var d=0;while(s&&s.tagName==="BLOCKQUOTE"){s=s.firstChild;d++}if(i-d>0){n=false}}else{for(var l=1;l<o.length;l++){if(o[l].childNodes.length<2){n=false;break}}if(o[0].firstChild.nextSibling===null){n=false}}}if(n){this.contextDocument.execCommand("indent")}},onScroll:function(){BX.Landing.UI.Panel.EditorPanel.getInstance().adjustPosition(i)},adjustButtonsState:function(){var t=function(t){return(!t?"de":"")+"activate"};var n=function(t){return this.buttons.get(t)}.bind(this);requestAnimationFrame(function(){var e=this.getFormat();void(n("bold")&&n("bold")[t(e.bold)]());void(n("italic")&&n("italic")[t(e.italic)]());void(n("underline")&&n("underline")[t(e.underline)]());void(n("strikeThrough")&&n("strikeThrough")[t(e.strike)]());void(n("justifyLeft")&&n("justifyLeft")[t(e.align==="left")]());void(n("justifyCenter")&&n("justifyCenter")[t(e.align==="center")]());void(n("justifyRight")&&n("justifyRight")[t(e.align==="right")]());void(n("justifyFull")&&n("justifyFull")[t(e.align==="justify")]())}.bind(this))},adjustButtonsContextDocument:function(){this.buttons.forEach((t=>{if("setContextDocument"in t){t.setContextDocument(this.contextDocument)}}))},getFormat:function(){var t=n(this.contextDocument);var e={};if(t){var i=getComputedStyle(t);switch(i.getPropertyValue("font-weight")){case"bold":case"bolder":case"500":case"600":case"700":case"800":case"900":e["bold"]=true;break}if(t.tagName==="B"){e["bold"]=true}if(i.getPropertyValue("font-style")==="italic"){e["italic"]=true}if(i.getPropertyValue("text-decoration").includes("underline")||i.getPropertyValue("text-decoration-line").includes("underline")){e["underline"]=true}if(i.getPropertyValue("text-decoration").includes("line-through")||i.getPropertyValue("text-decoration-line").includes("line-through")){e["strike"]=true}var o=i.getPropertyValue("text-align")||"left";if(o.match(/[left|center|rigth|custiffy]/)){e["align"]=o}if(this.currentElement.nodeName==="A"||this.currentElement.closest("a")){e["link"]=true}}return e},adjustPosition:function(t,n,e){d(this,t,e)},isFixed:function(){return this.position==="fixed-top"||this.position==="fixed-right"},hideAllBaseButtons:function(){this.layout.childNodes.forEach((function(t){if(t.dataset.id!=="drag"){t.hidden=true}}))},hideBaseButtons:function(t){this.layout.childNodes.forEach((function(n){if(t.indexOf(n.dataset.id)!==-1){n.hidden=true}}))},showBaseButtons:function(){this.layout.childNodes.forEach((t=>{if(t.dataset.id==="pasteTable"){if(top.window.copiedTable){t.hidden=false}else{t.hidden=true}}else{t.hidden=false}}))},isOutOfFrame:function(){return this.outOfFrame}}})(); //# sourceMappingURL=editor_panel.map.js