/*
 Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.

 For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license

*/
(function(){CKEDITOR.plugins.add("stylescombo",{requires:"richcombo",lang:"en",init:function(c){var l=c.config,g=c.lang.stylescombo,f={},k=[],m=[];c.on("stylesSet",function(a){if(a=a.data.styles){for(var b,h,d,e=0,n=a.length;e<n;e++)(b=a[e],c.blockless&&b.element in CKEDITOR.dtd.$block||"string"==typeof b.type&&!CKEDITOR.style.customHandlers[b.type]||(h=b.name,b=new CKEDITOR.style(b),c.filter.customConfig&&!c.filter.check(b)))||(b._name=h,b._.enterMode=l.enterMode,b._.type=d=b.assignedTo||b.type,
b._.weight=e+1E3*(d==CKEDITOR.STYLE_OBJECT?1:d==CKEDITOR.STYLE_BLOCK?2:3),f[h]=b,k.push(b),m.push(b));k.sort(function(a,b){return a._.weight-b._.weight})}});c.ui.addRichCombo("Styles",{label:g.label,title:g.panelTitle,toolbar:"styles,10",allowedContent:m,panel:{css:[CKEDITOR.skin.getPath("editor")].concat(l.contentsCss),multiSelect:!0,attributes:{"aria-label":g.panelTitle}},init:function(){var a,b,c,d,e,f;e=0;for(f=k.length;e<f;e++)a=k[e],b=a._name,d=a._.type,d!=c&&(this.startGroup(g["panelTitle"+
String(d)]),c=d),this.add(b,a.type==CKEDITOR.STYLE_OBJECT?b:a.buildPreview(),b);this.commit()},onClick:function(a){c.focus();c.fire("saveSnapshot");a=f[a];var b=c.elementPath();if(a.group&&a.removeStylesFromSameGroup(c))c.applyStyle(a);else c[a.checkActive(b,c)?"removeStyle":"applyStyle"](a);c.fire("saveSnapshot")},onRender:function(){c.on("selectionChange",function(a){var b=this.getValue();a=a.data.path.elements;for(var h=0,d=a.length,e;h<d;h++){e=a[h];for(var g in f)if(f[g].checkElementRemovable(e,
!0,c)){g!=b&&this.setValue(g);return}}this.setValue("")},this)},onOpen:function(){var a=c.getSelection(),a=a.getSelectedElement()||a.getStartElement()||c.editable(),a=c.elementPath(a),b=[0,0,0,0];this.showAll();this.unmarkAll();for(var h in f){var d=f[h],e=d._.type;d.checkApplicable(a,c,c.activeFilter)?b[e]++:this.hideItem(h);d.checkActive(a,c)&&this.mark(h)}b[CKEDITOR.STYLE_BLOCK]||this.hideGroup(g["panelTitle"+String(CKEDITOR.STYLE_BLOCK)]);b[CKEDITOR.STYLE_INLINE]||this.hideGroup(g["panelTitle"+
String(CKEDITOR.STYLE_INLINE)]);b[CKEDITOR.STYLE_OBJECT]||this.hideGroup(g["panelTitle"+String(CKEDITOR.STYLE_OBJECT)])},refresh:function(){var a=c.elementPath();if(a){for(var b in f)if(f[b].checkApplicable(a,c,c.activeFilter))return;this.setState(CKEDITOR.TRISTATE_DISABLED)}},reset:function(){f={};k=[]}})}})})();