plugin.js 5.5 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(){function e(e,i){var s,o=e.config,l=i.lang,r=new CKEDITOR.style(i.styleDefinition),f=new a({entries:i.entries,styleVariable:i.styleVariable,styleDefinition:i.styleDefinition});e.addCommand(i.commandName,{exec:function(e,i){var a=i.newStyle,s=i.oldStyle,o=e.getSelection().getRanges()[0],l=void 0===a;(s||a)&&(s&&o.collapsed&&n({editor:e,range:o,style:s}),l?e.removeStyle(s):(s&&!t(s,a)&&e.removeStyle(s),e.applyStyle(a)))},refresh:function(e,t){r.checkApplicable(t,e,e.activeFilter)||this.setState(CKEDITOR.TRISTATE_DISABLED)}}),s=e.getCommand(i.commandName),e.ui.addRichCombo(i.comboName,{label:l.label,title:l.panelTitle,command:i.commandName,toolbar:"styles,"+i.order,defaultValue:"cke-default",allowedContent:r,requiredContent:r,contentTransformations:"span"===i.styleDefinition.element?[[{element:"font",check:"span",left:function(e){return!!e.attributes.size||!!e.attributes.align||!!e.attributes.face},right:function(e){var t=" x-small small medium large x-large xx-large 48px".split(" ");e.name="span",e.attributes.size&&(e.styles["font-size"]=t[e.attributes.size],delete e.attributes.size),e.attributes.align&&(e.styles["text-align"]=e.attributes.align,delete e.attributes.align),e.attributes.face&&(e.styles["font-family"]=e.attributes.face,delete e.attributes.face)}}]]:null,panel:{css:[CKEDITOR.skin.getPath("editor")].concat(o.contentsCss),multiSelect:!1,attributes:{"aria-label":l.panelTitle}},init:function(){var t="("+e.lang.common.optionDefault+")";this.startGroup(l.panelTitle),this.add(this.defaultValue,t,t),f.addToCombo(this)},onClick:function(t){var n=this.getValue();e.focus(),e.fire("saveSnapshot"),e.execCommand(i.commandName,{newStyle:f.getStyle(t),oldStyle:f.getStyle(n)}),e.fire("saveSnapshot")},onRender:function(){e.on("selectionChange",function(t){var n=this.getValue();(t=f.getMatchingValue(e,t.data.path))?t!=n&&this.setValue(t):this.setValue("",i.defaultLabel)},this),s.on("state",function(){this.setState(s.state)},this)},refresh:function(){this.setState(s.state)}})}function t(e,t){if(!(e instanceof CKEDITOR.style&&t instanceof CKEDITOR.style))return!1;var n=function(e,t){var n=e.getDefinition().attributes,i=t.getDefinition().attributes;return CKEDITOR.tools.objectCompare(n,i)}(e,t),i=function(e,t){return CKEDITOR.style.getStyleText(e.getDefinition())===CKEDITOR.style.getStyleText(t.getDefinition())}(e,t);return n&&i}function n(e){var t,n,a,s=e.editor,o=e.range,l=e.style;if(t=s.elementPath(),e=t.contains(function(e){return l.checkElementRemovable(e)})){if(n=o.checkBoundaryOfElement(e,CKEDITOR.START),a=o.checkBoundaryOfElement(e,CKEDITOR.END),n&&a){for(n=o.createBookmark();t=e.getFirst();)t.insertBefore(e);e.remove(),o.moveToBookmark(n)}else n||a?o.moveToPosition(e,n?CKEDITOR.POSITION_BEFORE_START:CKEDITOR.POSITION_AFTER_END):(o.splitElement(e),o.moveToPosition(e,CKEDITOR.POSITION_AFTER_END)),i(o,t.elements.slice(),e);s.getSelection().selectRanges([o])}}function i(e,t,n){var a=t.pop();if(a){if(n)return i(e,t,a.equals(n)?null:n);n=a.clone(),e.insertNode(n),e.moveToPosition(n,CKEDITOR.POSITION_AFTER_START),i(e,t)}}var a=CKEDITOR.tools.createClass({$:function(e){var t=e.entries.split(";");this._.data={},this._.names=[];for(var n=0;n<t.length;n++){var i,a,s=t[n];s?(s=s.split("/"),i=s[0],s=s[1],a={},a[e.styleVariable]=s||i,this._.data[i]=new CKEDITOR.style(e.styleDefinition,a),this._.data[i]._.definition.name=i,this._.names.push(i)):(t.splice(n,1),n--)}},proto:{getStyle:function(e){return this._.data[e]},addToCombo:function(e){for(var t=0;t<this._.names.length;t++){var n=this._.names[t];e.add(n,this.getStyle(n).buildPreview(),n)}},getMatchingValue:function(e,t){for(var n,i=t.elements,a=0;a<i.length;a++)if(n=i[a],n=this._.findMatchingStyleName(e,n))return n;return null}},_:{findMatchingStyleName:function(e,t){return CKEDITOR.tools.array.find(this._.names,function(n){return this.getStyle(n).checkElementMatch(t,!0,e)},this)}}});CKEDITOR.plugins.add("font",{requires:"richcombo",lang:"af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,es-mx,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,oc,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn",init:function(t){var n=t.config;e(t,{comboName:"Font",commandName:"font",styleVariable:"family",lang:t.lang.font,entries:n.font_names,defaultLabel:n.font_defaultLabel,styleDefinition:n.font_style,order:30}),e(t,{comboName:"FontSize",commandName:"fontSize",styleVariable:"size",lang:t.lang.font.fontSize,entries:n.fontSize_sizes,defaultLabel:n.fontSize_defaultLabel,styleDefinition:n.fontSize_style,order:40})}})}(),CKEDITOR.config.font_names="Arial/Arial, Helvetica, sans-serif;Comic Sans MS/Comic Sans MS, cursive;Courier New/Courier New, Courier, monospace;Georgia/Georgia, serif;Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;Tahoma/Tahoma, Geneva, sans-serif;Times New Roman/Times New Roman, Times, serif;Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;Verdana/Verdana, Geneva, sans-serif",CKEDITOR.config.font_defaultLabel="",CKEDITOR.config.font_style={element:"span",styles:{"font-family":"#(family)"},overrides:[{element:"font",attributes:{face:null}}]},CKEDITOR.config.fontSize_sizes="8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px",CKEDITOR.config.fontSize_defaultLabel="",CKEDITOR.config.fontSize_style={element:"span",styles:{"font-size":"#(size)"},overrides:[{element:"font",attributes:{size:null}}]};