plugin.js 8.9 KB

12345
  1. /*
  2. Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
  3. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. !function(){var t=!1;CKEDITOR.plugins.add("balloonpanel",{init:function(){t||(CKEDITOR.document.appendStyleSheet(this.path+"skins/"+CKEDITOR.skin.name+"/balloonpanel.css"),t=!0)}}),CKEDITOR.ui.balloonPanel=function(t,e){this.editor=t,CKEDITOR.tools.extend(this,{width:360,height:"auto",triangleWidth:20,triangleHeight:20,triangleMinDistance:40},e,!0),this.templates={};for(var i in this.templateDefinitions)this.templates[i]=new CKEDITOR.template(this.templateDefinitions[i]);this.parts={},this.focusables={},this.showListeners={},this.activeShowListeners={},this.rect={visible:!1},this.build(),t.on("destroy",function(){this.destroy()},this)},CKEDITOR.ui.balloonPanel.prototype={templateDefinitions:{panel:'<div class="cke {id} cke_reset_all cke_chrome cke_balloon cke_editor_{name} cke_{langDir} '+CKEDITOR.env.cssClass+'" dir="{langDir}" title="'+(CKEDITOR.env.gecko?" ":"")+'" lang="{langCode}" role="dialog" style="{style}" tabindex="-1" aria-labelledby="cke_{name}_arialbl"></div>',content:'<div class="cke_balloon_content">{content}</div>',title:'<div class="cke_balloon_title" role="presentation">{title}</div>',close:'<a class="cke_balloon_close_button" href="javascript:void(0)" title="Close" role="button" tabindex="-1"><span class="cke_label">X</span></a>',triangleOuter:'<span class="cke_balloon_triangle cke_balloon_triangle_outer"></span>',triangleInner:'<span class="cke_balloon_triangle cke_balloon_triangle_inner">&#8203;</span>'},build:function(){var t=this.editor;this.parts={title:CKEDITOR.dom.element.createFromHtml(this.templates.title.output({title:this.title})),close:CKEDITOR.dom.element.createFromHtml(this.templates.close.output()),panel:CKEDITOR.dom.element.createFromHtml(this.templates.panel.output({id:t.id,langDir:t.lang.dir,langCode:t.langCode,name:t.name,style:"display:none;",voiceLabel:t.lang.editorPanel+", "+t.name})),content:CKEDITOR.dom.element.createFromHtml(this.templates.content.output({content:this.content||""})),triangleOuter:CKEDITOR.dom.element.createFromHtml(this.templates.triangleOuter.output()),triangleInner:CKEDITOR.dom.element.createFromHtml(this.templates.triangleInner.output())},this.parts.panel.append(this.parts.title,1),this.parts.panel.append(this.parts.close,1),this.parts.panel.append(this.parts.triangleOuter),this.parts.panel.append(this.parts.content),this.parts.triangleOuter.append(this.parts.triangleInner),this.registerFocusable(this.parts.panel),this.registerFocusable(this.parts.close),this.parts.title.unselectable(),this.parts.close.unselectable(),CKEDITOR.document.getBody().append(this.parts.panel),this.resize(this.width,this.height),this.on("show",this.activateShowListeners,this),this.on("hide",this.deactivateShowListeners,this),this.parts.close.on("click",function(t){this.hide(),t.data.preventDefault()},this)},show:function(){this.rect.visible||(this.rect.visible=!0,this.parts.panel.show(),this.fire("show"))},hide:function(){this.rect.visible&&(this.rect.visible=!1,this.parts.panel.hide(),this.blur(),this.fire("hide"))},blur:function(){this.editor.focus()},move:function(t,e){this.rect.left=e,this.rect.top=t,this.parts.panel.setStyles({left:CKEDITOR.tools.cssLength(e),top:CKEDITOR.tools.cssLength(t)})},attach:function(){function t(t,e){var i=Math.max(0,Math.min(t.right,e.right)-Math.max(t.left,e.left)),n=Math.max(0,Math.min(t.bottom,e.bottom)-Math.max(t.top,e.top));return i*n}function e(t,e,i,n){return t={top:t,left:e},t.right=t.left+i,t.bottom=t.top+n,t}function i(t,e){return t.right=e.right,t.width=t.right-t.left,e.y&&(t.y=e.y),t}function n(t){var e=s(t,!0);return t=s(t),e=i(e[0],e.pop()),t=i(t[0],t.pop()),e.bottom=t.bottom,e.height=e.bottom-e.top,t.y&&(e.y=t.y),t.top=e.top,t.height=e.height,[e,t]}function s(t,e){var i=e?t[0]:t[t.length-1],n=e?"top":"bottom";return CKEDITOR.tools.array.filter(t,function(t){return t[n]===i[n]?t:void 0})}var o,a,l,h,r={right:"left",top:"bottom",topLeft:"bottomLeft",topRight:"bottomRight",bottom:"top",bottomLeft:"topLeft",bottomRight:"topRight",left:"right"};return function(s,c){if(s instanceof CKEDITOR.dom.selection){var g,p=s.getRanges(),p=s.isFake&&s.isInTable()?CKEDITOR.tools.array.map(p,function(t){return t.getClientRects(!0)[0]}):p[p.length-1].getClientRects(!0),m=p[0],d=p[p.length-1];g=m===d?[m]:m.top===d.top?[i(m,d)]:n(p)}(c instanceof CKEDITOR.dom.element||!c)&&(c={focusElement:c}),c=CKEDITOR.tools.extend(c,{show:!0}),!0===c.show&&this.show(),this.fire("attach"),o=CKEDITOR.document.getWindow(),a=this.editor.window.getFrame(),l=this.editor.editable(),h=l.isInline(),!h&&CKEDITOR.env.safari&&(a=a.getParent());var u,f,b,p=this.getWidth(),m=this.getHeight(),d=p*m;u=s.getClientRect&&s.getClientRect(!0);var v=h?l.getClientRect(!0):a.getClientRect(!0),_=o.getViewPaneSize(),w=o.getScrollPosition(),C={top:Math.max(v.top,w.y),left:Math.max(v.left,w.x),right:Math.min(v.right,_.width+w.x),bottom:Math.min(v.bottom,_.height+w.y)};h&&this.editor.elementMode===CKEDITOR.ELEMENT_MODE_INLINE&&(C=this._getViewPaneRect(o),C.right+=this.triangleWidth,C.bottom+=this.triangleHeight),g?(CKEDITOR.tools.array.forEach(g,function(t){this._adjustElementRect(t,h?C:v)},this),u=this._getAlignments(g[0],p,m),1<g.length&&(u["bottom hcenter"]=this._getAlignments(g[1],p,m)["bottom hcenter"]),b={"top hcenter":!0,"bottom hcenter":!0}):(this._adjustElementRect(u,h?C:v),u=this._getAlignments(u,p,m));for(var R in b||u){if(b=e(u[R].top,u[R].left,p,m),b=u[R].areaDifference=d-t(b,C),0===b){f=R;break}f||(f=R),b<u[f].areaDifference&&(f=R)}R=(b=this.parts.panel.getAscendant(function(t){return t instanceof CKEDITOR.dom.document?!1:"static"!==t.getComputedStyle("position")}))?parseInt(b.getComputedStyle("margin-left"),10):0,b=b?parseInt(b.getComputedStyle("margin-top"),10):0,this.move(u[f].top-b,u[f].left-R),f=f.split(" "),this.setTriangle(r[f[0]],f[1]),!1!==c.focusElement&&(c.focusElement||this.parts.panel).focus()}}(),resize:function(t,e){this.rect.width=t,this.rect.height=e,this.parts.panel.setStyles({width:CKEDITOR.tools.cssLength(t),height:CKEDITOR.tools.cssLength(e)})},getWidth:function(){return"auto"===this.rect.width?this.parts.panel.getClientRect().width:this.rect.width},getHeight:function(){return"auto"===this.rect.height?this.parts.panel.getClientRect().height:this.rect.height},setTriangle:function(t,e){var i=this.parts.triangleOuter,n=this.parts.triangleInner;this.triangleSide&&(i.removeClass("cke_balloon_triangle_"+this.triangleSide),i.removeClass("cke_balloon_triangle_align_"+this.triangleAlign),n.removeClass("cke_balloon_triangle_"+this.triangleSide)),this.triangleSide=t,this.triangleAlign=e,i.addClass("cke_balloon_triangle_"+t),i.addClass("cke_balloon_triangle_align_"+e),n.addClass("cke_balloon_triangle_"+t)},registerFocusable:function(t){this.editor.focusManager.add(t),this.focusables[t.getUniqueId()]=t},deregisterFocusable:function(t){this.editor.focusManager.remove(t),delete this.focusables[t.getUniqueId()]},addShowListener:function(t){var e=CKEDITOR.tools.getNextNumber();this.showListeners[e]=t,this.rect.visible&&this.activateShowListener(e);var i=this;return{removeListener:function(){i.removeShowListener(e)}}},removeShowListener:function(t){this.deactivateShowListener(t),delete this.showListeners[t]},activateShowListener:function(t){this.activeShowListeners[t]=this.showListeners[t].call(this)},deactivateShowListener:function(t){this.activeShowListeners[t]&&this.activeShowListeners[t].removeListener(),delete this.activeShowListeners[t]},activateShowListeners:function(){for(var t in this.showListeners)this.activateShowListener(t)},deactivateShowListeners:function(){for(var t in this.activeShowListeners)this.deactivateShowListener(t)},destroy:function(){this.deactivateShowListeners(),this.parts.panel.remove()},setTitle:function(t){this.parts.title.setHtml(t)},_getAlignments:function(t,e,i){return{"right vcenter":{top:t.top+t.height/2-i/2,left:t.right+this.triangleWidth},"left vcenter":{top:t.top+t.height/2-i/2,left:t.left-e-this.triangleWidth},"top hcenter":{top:t.top-i-this.triangleHeight,left:t.left+t.width/2-e/2},"top left":{top:t.top-i-this.triangleHeight,left:t.left+t.width/2-this.triangleMinDistance},"top right":{top:t.top-i-this.triangleHeight,left:t.right-t.width/2-e+this.triangleMinDistance},"bottom hcenter":{top:t.bottom+this.triangleHeight,left:t.left+t.width/2-e/2},"bottom left":{top:t.bottom+this.triangleHeight,left:t.left+t.width/2-this.triangleMinDistance},"bottom right":{top:t.bottom+this.triangleHeight,left:t.right-t.width/2-e+this.triangleMinDistance}}},_adjustElementRect:function(t,e){t.left=Math.max(e.left,Math.min(e.right-1,t.left)),t.right=Math.max(e.left,Math.min(e.right,t.right)),t.top=Math.max(e.top,Math.min(e.bottom-1,t.top)),t.bottom=Math.max(e.top,Math.min(e.bottom,t.bottom))},_getViewPaneRect:function(t){var e=t.getScrollPosition();return t=t.getViewPaneSize(),{top:e.y,bottom:e.y+t.height,left:e.x,right:e.x+t.width}}},CKEDITOR.event.implementOn(CKEDITOR.ui.balloonPanel.prototype)}();