!function(){function t(t,o){this.editor=t,this.options=o,this.toolbar=new CKEDITOR.ui.balloonToolbar(t),this.options&&void 0===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=CKEDITOR.tools.array.filter(["matches","msMatchesSelector","webkitMatchesSelector","mozMatchesSelector","oMatchesSelector"],(function(t){return!!window.HTMLElement&&t in HTMLElement.prototype}))[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){n(t,(function(t){if(!s||s.options.priority>t.options.priority){var n=o(t,e);n instanceof CKEDITOR.dom.element&&(i=n,s=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,s,n=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<l.elements.length;r++){var a=l.elements[r];a.isReadOnly()||o(this._contexts,e,a)}this.hide(),s&&s.show(i)}},hide:function(){CKEDITOR.tools.array.forEach(this._contexts,(function(t){t.hide()}))},destroy:function(){CKEDITOR.tools.array.forEach(this._listeners,(function(t){t.removeListener()})),this._listeners.splice(0,this._listeners.length),this._clear()},_clear:function(){CKEDITOR.tools.array.forEach(this._contexts,(function(t){t.destroy()})),this._contexts.splice(0,this._contexts.length)},_refresh:function(){CKEDITOR.tools.array.forEach(this._contexts,(function(t){t.refresh()}))},_attachListeners:function(){this._listeners.push(this.editor.on("destroy",(function(){this.destroy()}),this),this.editor.on("selectionChange",(function(){this.check()}),this),this.editor.on("mode",(function(){this.hide()}),this,null,9999),this.editor.on("blur",(function(){this.hide()}),this,null,9999),this.editor.on("afterInsertHtml",(function(){this.check(),this._refresh()}),this,null,9999))}};var i=!1,s=!1;CKEDITOR.plugins.add("balloontoolbar",{requires:"balloonpanel",isSupportedEnvironment:function(){return!CKEDITOR.env.ie||8<CKEDITOR.env.version},beforeInit:function(t){s||(CKEDITOR.document.appendStyleSheet(this.path+"skins/default.css"),CKEDITOR.document.appendStyleSheet(this.path+"skins/"+CKEDITOR.skin.name+"/balloontoolbar.css"),s=!0),t.balloonToolbars=new CKEDITOR.plugins.balloontoolbar.contextManager(t)},init:function(t){t.balloonToolbars=new CKEDITOR.plugins.balloontoolbar.contextManager(t),i||(i=!0,CKEDITOR.ui.balloonToolbarView.prototype=CKEDITOR.tools.extend({},CKEDITOR.ui.balloonPanel.prototype),CKEDITOR.ui.balloonToolbarView.prototype.build=function(){CKEDITOR.ui.balloonPanel.prototype.build.call(this),this.parts.panel.addClass("cke_balloontoolbar"),this.parts.title.remove(),this.deregisterFocusable(this.parts.close),this.parts.close.remove()},CKEDITOR.ui.balloonToolbarView.prototype.show=function(){function t(){this.reposition()}if(!this.rect.visible){var o=this.editor.editable();this._detachListeners(),this._listeners.push(this.editor.on("change",t,this)),this._listeners.push(this.editor.on("resize",t,this)),this._listeners.push(CKEDITOR.document.getWindow().on("resize",t,this)),this._listeners.push(o.attachListener(o.getDocument(),"scroll",t,this)),CKEDITOR.ui.balloonPanel.prototype.show.call(this)}},CKEDITOR.ui.balloonToolbarView.prototype.reposition=function(){this.rect.visible&&this.attach(this._pointedElement,{focusElement:!1})},CKEDITOR.ui.balloonToolbarView.prototype.hide=function(){this._detachListeners(),CKEDITOR.ui.balloonPanel.prototype.hide.call(this)},CKEDITOR.ui.balloonToolbarView.prototype.blur=function(t){t&&this.editor.focus()},CKEDITOR.ui.balloonToolbarView.prototype._getAlignments=function(t,o,e){return{"bottom hcenter":(t=CKEDITOR.ui.balloonPanel.prototype._getAlignments.call(this,t,o,e))["bottom hcenter"],"top hcenter":t["top hcenter"]}},CKEDITOR.ui.balloonToolbarView.prototype._detachListeners=function(){this._listeners.length&&(CKEDITOR.tools.array.forEach(this._listeners,(function(t){t.removeListener()})),this._listeners=[])},CKEDITOR.ui.balloonToolbarView.prototype.destroy=function(){this._deregisterItemFocusables(),CKEDITOR.ui.balloonPanel.prototype.destroy.call(this),this._detachListeners()},CKEDITOR.ui.balloonToolbarView.prototype.renderItems=function(t){var o=[],e=CKEDITOR.tools.object.keys(t),i=!1;this._deregisterItemFocusables(),CKEDITOR.tools.array.forEach(e,(function(e){CKEDITOR.ui.richCombo&&t[e]instanceof CKEDITOR.ui.richCombo&&i?(i=!1,o.push("</span>")):CKEDITOR.ui.richCombo&&t[e]instanceof CKEDITOR.ui.richCombo||i||(i=!0,o.push('<span class="cke_toolgroup">')),t[e].render(this.editor,o)}),this),i&&o.push("</span>"),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}}}();