/* Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ !function(){function t(t,o){this.editor=t,this.options=o,this.toolbar=new CKEDITOR.ui.balloonToolbar(t),this.options&&"undefined"==typeof this.options.priority&&(this.options.priority=CKEDITOR.plugins.balloontoolbar.PRIORITY.MEDIUM),this._loadButtons()}function o(t){this.editor=t,this._contexts=[],this._listeners=[],this._attachListeners()}var e=function(){return CKEDITOR.tools.array.filter(["matches","msMatchesSelector","webkitMatchesSelector","mozMatchesSelector","oMatchesSelector"],function(t){return window.HTMLElement?t in HTMLElement.prototype:!1})[0]}();CKEDITOR.ui.balloonToolbarView=function(t,o){o=CKEDITOR.tools.extend(o||{},{width:"auto",triangleWidth:7,triangleHeight:7}),CKEDITOR.ui.balloonPanel.call(this,t,o),this._listeners=[]},CKEDITOR.ui.balloonToolbar=function(t,o){this._view=new CKEDITOR.ui.balloonToolbarView(t,o),this._items={}},CKEDITOR.ui.balloonToolbar.prototype.attach=function(t,o){this._view.renderItems(this._items),this._view.attach(t,{focusElement:!1,show:!o})},CKEDITOR.ui.balloonToolbar.prototype.show=function(){this._view.show()},CKEDITOR.ui.balloonToolbar.prototype.hide=function(){this._view.hide()},CKEDITOR.ui.balloonToolbar.prototype.reposition=function(){this._view.reposition()},CKEDITOR.ui.balloonToolbar.prototype.addItem=function(t,o){this._items[t]=o},CKEDITOR.ui.balloonToolbar.prototype.addItems=function(t){for(var o in t)this.addItem(o,t[o])},CKEDITOR.ui.balloonToolbar.prototype.getItem=function(t){return this._items[t]},CKEDITOR.ui.balloonToolbar.prototype.deleteItem=function(t){this._items[t]&&(delete this._items[t],this._view.renderItems(this._items))},CKEDITOR.ui.balloonToolbar.prototype.destroy=function(){for(var t in this._items)this._items[t].destroy&&this._items[t].destroy(),this.deleteItem(t);this._pointedElement=null,this._view.destroy()},CKEDITOR.ui.balloonToolbar.prototype.refresh=function(){for(var t in this._items){var o=this._view.editor.getCommand(this._items[t].command);o&&o.refresh(this._view.editor,this._view.editor.elementPath())}},t.prototype={destroy:function(){this.toolbar&&this.toolbar.destroy()},show:function(t){t&&this.toolbar.attach(t),this.toolbar.show()},hide:function(){this.toolbar.hide()},refresh:function(){this.toolbar.refresh()},_matchRefresh:function(t,o){var e=null;return this.options.refresh&&(e=this.options.refresh(this.editor,t,o)||null)&&!1==e instanceof CKEDITOR.dom.element&&(e=t&&t.lastElement||this.editor.editable()),e},_matchWidget:function(){var t=this.options.widgets,o=null;if(t){var e=this.editor.widgets&&this.editor.widgets.focused&&this.editor.widgets.focused.name;"string"==typeof t&&(t=t.split(",")),-1!==CKEDITOR.tools.array.indexOf(t,e)&&(o=this.editor.widgets.focused.element)}return o},_matchElement:function(t){return this.options.cssSelector&&e&&t.$[e](this.options.cssSelector)?t:null},_loadButtons:function(){var t=this.options.buttons;t&&(t=t.split(","),CKEDITOR.tools.array.forEach(t,function(t){var o=this.editor.ui.create(t);o&&this.toolbar.addItem(t,o)},this))}},o.prototype={create:function(t){return t=new CKEDITOR.plugins.balloontoolbar.context(this.editor,t),this.add(t),t},add:function(t){this._contexts.push(t)},check:function(t){function o(t,o,e){s(t,function(t){if(!n||n.options.priority>t.options.priority){var s=o(t,e);s instanceof CKEDITOR.dom.element&&(i=s,n=t)}})}function e(t,o){return t._matchElement(o)}if(t||(t=this.editor.getSelection(),CKEDITOR.tools.array.forEach(t.getRanges(),function(t){t.shrink(CKEDITOR.SHRINK_ELEMENT,!0)})),t){var i,n,s=CKEDITOR.tools.array.forEach,r=t.getRanges()[0],l=r&&r.startPath();if(o(this._contexts,function(o){return o._matchRefresh(l,t)}),o(this._contexts,function(t){return t._matchWidget()}),l)for((r=t.getSelectedElement())&&!r.isReadOnly()&&o(this._contexts,e,r),r=0;r")):CKEDITOR.ui.richCombo&&t[e]instanceof CKEDITOR.ui.richCombo||i||(i=!0,o.push('')),t[e].render(this.editor,o)},this),i&&o.push(""),this.parts.content.setHtml(o.join("")),this.parts.content.unselectable(),CKEDITOR.tools.array.forEach(this.parts.content.find("a").toArray(),function(t){t.setAttribute("draggable","false"),this.registerFocusable(t)},this)},CKEDITOR.ui.balloonToolbarView.prototype.attach=function(t,o){this._pointedElement=t,CKEDITOR.ui.balloonPanel.prototype.attach.call(this,t,o)},CKEDITOR.ui.balloonToolbarView.prototype._deregisterItemFocusables=function(){var t,o=this.focusables;for(t in o)this.parts.content.contains(o[t])&&this.deregisterFocusable(o[t])})}}),CKEDITOR.plugins.balloontoolbar={context:t,contextManager:o,PRIORITY:{LOW:999,MEDIUM:500,HIGH:10}}}();