/* Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license */ (function(){function e(a,b){this.editor=a;this.options=b;this.toolbar=new CKEDITOR.ui.balloonToolbar(a);this.options&&"undefined"===typeof this.options.priority&&(this.options.priority=CKEDITOR.plugins.balloontoolbar.PRIORITY.MEDIUM);this._loadButtons()}function g(a){this.editor=a;this._contexts=[];this._listeners=[];this._attachListeners()}var k=function(){return CKEDITOR.tools.array.filter(["matches","msMatchesSelector","webkitMatchesSelector","mozMatchesSelector","oMatchesSelector"],function(a){return window.HTMLElement? a in HTMLElement.prototype:!1})[0]}();CKEDITOR.ui.balloonToolbarView=function(a,b){b=CKEDITOR.tools.extend(b||{},{width:"auto",triangleWidth:7,triangleHeight:7});CKEDITOR.ui.balloonPanel.call(this,a,b);this._listeners=[]};CKEDITOR.ui.balloonToolbar=function(a,b){this._view=new CKEDITOR.ui.balloonToolbarView(a,b);this._items={}};CKEDITOR.ui.balloonToolbar.prototype.attach=function(a,b){this._view.renderItems(this._items);this._view.attach(a,{focusElement:!1,show:!b})};CKEDITOR.ui.balloonToolbar.prototype.show= function(){this._view.show()};CKEDITOR.ui.balloonToolbar.prototype.hide=function(){this._view.hide()};CKEDITOR.ui.balloonToolbar.prototype.addItem=function(a,b){this._items[a]=b};CKEDITOR.ui.balloonToolbar.prototype.addItems=function(a){for(var b in a)this.addItem(b,a[b])};CKEDITOR.ui.balloonToolbar.prototype.getItem=function(a){return this._items[a]};CKEDITOR.ui.balloonToolbar.prototype.deleteItem=function(a){this._items[a]&&delete this._items[a]};CKEDITOR.ui.balloonToolbar.prototype.destroy=function(){this._pointedElement= null;this._view.destroy()};e.prototype={destroy:function(){this.toolbar&&this.toolbar.destroy()},show:function(a){a&&this.toolbar.attach(a);this.toolbar.show()},hide:function(){this.toolbar.hide()},_matchRefresh:function(a,b){var c=null;this.options.refresh&&(c=this.options.refresh(this.editor,a,b)||null)&&!1===c instanceof CKEDITOR.dom.element&&(c=a&&a.lastElement||this.editor.editable());return c},_matchWidget:function(){var a=this.options.widgets,b=null;if(a){var c=this.editor.widgets&&this.editor.widgets.focused&& this.editor.widgets.focused.name;"string"===typeof a&&(a=a.split(","));-1!==CKEDITOR.tools.array.indexOf(a,c)&&(b=this.editor.widgets.focused.element)}return b},_matchElement:function(a){return this.options.cssSelector&&k&&a.$[k](this.options.cssSelector)?a:null},_loadButtons:function(){var a=this.options.buttons;a&&(a=a.split(","),CKEDITOR.tools.array.forEach(a,function(a){var c=this.editor.ui.create(a);c&&this.toolbar.addItem(a,c)},this))}};g.prototype={create:function(a){a=new CKEDITOR.plugins.balloontoolbar.context(this.editor, a);this.add(a);return a},add:function(a){this._contexts.push(a)},check:function(a){function b(a,b,c){n(a,function(a){if(!h||h.options.priority>a.options.priority){var d=b(a,c);d instanceof CKEDITOR.dom.element&&(e=d,h=a)}})}function c(a,b){return a._matchElement(b)}a||(a=this.editor.getSelection(),CKEDITOR.tools.array.forEach(a.getRanges(),function(a){a.shrink(CKEDITOR.SHRINK_ELEMENT,!0)}));if(a){var n=CKEDITOR.tools.array.forEach,d=a.getRanges()[0],f=d&&d.startPath(),e,h;b(this._contexts,function(b){return b._matchRefresh(f, a)});b(this._contexts,function(a){return a._matchWidget()});if(f)for(d=0;d