12345 |
- /*
- 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 e(e){return CKEDITOR.tools.capitalize(e,!0)}function a(a,t){function i(e){return function(a,t){var i=a.widgets.focused,n=CKEDITOR.TRISTATE_DISABLED;i&&"easyimage"===i.name&&(n=e&&e.call(this,i,a,t)?CKEDITOR.TRISTATE_ON:CKEDITOR.TRISTATE_OFF),this.setState(n)}}function n(e,a,t,n){return t.type="widget",t.widget="easyimage",t.group=t.group||"easyimage",t.element="figure",a=new CKEDITOR.style(t),e.filter.allow(a),a=new CKEDITOR.styleCommand(a),a.contextSensitive=!0,a.refresh=i(function(e,a,t){return this.style.checkActive(t,a)}),e.addCommand(n,a),a=e.getCommand(n),a.enable=function(){},a.refresh(e,e.elementPath()),a}a.addCommand("easyimageAlt",new CKEDITOR.dialogCommand("easyimageAlt",{startDisabled:!0,contextSensitive:!0,refresh:i()})),function(t){function i(e,a){var t=e.match(/^easyimage(.+)$/);if(t){var i=(t[1][0]||"").toLowerCase()+t[1].substr(1);if(t[1]in a)return t[1];if(i in a)return i}return null}a.on("afterCommandExec",function(e){i(e.data.name,t)&&(a.forceNextSelectionCheck(),a.selectionChange(!0))}),a.on("beforeCommandExec",function(e){i(e.data.name,t)&&e.data.command.style.checkActive(e.editor.elementPath(),a)&&(e.cancel(),a.focus())});for(var s in t)n(a,s,t[s],"easyimage"+e(s))}(t)}function t(e){var a=e.config.easyimage_toolbar;e.plugins.contextmenu&&(a.split&&(a=a.split(",")),e.addMenuGroup("easyimage"),CKEDITOR.tools.array.forEach(a,function(a){a=e.ui.items[a],e.addMenuItem(a.name,{label:a.label,command:a.command,group:"easyimage"})}))}function i(e){var a=e.sender.editor,t=a.config.easyimage_toolbar;t.split&&(t=t.split(",")),CKEDITOR.tools.array.forEach(t,function(t){t=a.ui.items[t],e.data[t.name]=a.getCommand(t.command).state})}function n(a,t){var n=a.config,s=n.easyimage_class,n={name:"easyimage",allowedContent:{figure:{classes:n.easyimage_sideClass},img:{attributes:"!src,srcset,alt,width,sizes"}},requiredContent:"figure; img[!src]",styleableElements:"figure",supportedTypes:new RegExp("image/("+r.join("|")+")","i"),loaderType:CKEDITOR.plugins.cloudservices.cloudServicesLoader,progressReporterType:CKEDITOR.plugins.imagebase.progressBar,upcasts:{figure:function(e){return s&&!e.hasClass(s)||1!==e.find("img",!0).length?void 0:e}},init:function(){function e(a,t){var i=a.$;return i.complete&&i.naturalWidth?t(i.naturalWidth):void a.once("load",function(){return i.naturalWidth?void t(i.naturalWidth):(i.src=i.src,e(a,t))})}var t=this.parts.image,n=t&&t.$.complete&&!t.$.naturalWidth;(t&&!t.$.complete||n)&&(n&&(t.$.src=t.$.src),e(t,function(){a._.easyImageToolbarContext.toolbar.reposition()})),t=this.element.data("cke-upload-id"),"undefined"!=typeof t&&(this.setData("uploadId",t),this.element.data("cke-upload-id",!1)),this.on("contextMenu",i),a.config.easyimage_class&&this.addClass(a.config.easyimage_class),this.on("uploadStarted",function(){var a=this;e(a.parts.image,function(e){a.parts.image.hasAttribute("width")||(a.editor.fire("lockSnapshot"),a.parts.image.setAttribute("width",e),a.editor.fire("unlockSnapshot"))})}),this.on("uploadDone",function(e){e=e.data.loader.responseData.response;var a=CKEDITOR.plugins.easyimage._parseSrcSet(e);this.parts.image.setAttributes({"data-cke-saved-src":e["default"],src:e["default"],srcset:a,sizes:"100vw"})}),this.on("uploadFailed",function(){alert(this.editor.lang.easyimage.uploadFailed)}),this._loadDefaultStyle()},_loadDefaultStyle:function(){var i,n=!1,s=a.config.easyimage_defaultStyle;for(i in t){var o=a.getCommand("easyimage"+e(i));!n&&o&&o.style&&-1!==CKEDITOR.tools.array.indexOf(o.style.group,"easyimage")&&this.checkStyleActive(o.style)&&(n=!0)}!n&&s&&a.getCommand("easyimage"+e(s))&&this.applyStyle(a.getCommand("easyimage"+e(s)).style)}};s&&(n.requiredContent+="(!"+s+")",n.allowedContent.figure.classes="!"+s+","+n.allowedContent.figure.classes),a.plugins.link&&(n=CKEDITOR.plugins.imagebase.addFeature(a,"link",n)),n=CKEDITOR.plugins.imagebase.addFeature(a,"upload",n),n=CKEDITOR.plugins.imagebase.addFeature(a,"caption",n),CKEDITOR.plugins.imagebase.addImageWidget(a,"easyimage",n)}function s(e){var a=new RegExp("<img[^>]*\\ssrc=[\\'\\\"]?data:image/("+r.join("|")+");base64,","i");e.on("paste",function(t){if(!e.isReadOnly&&a.test(t.data.dataValue)){t=t.data;var i,n,s,o,l=document.implementation.createHTMLDocument(""),l=new CKEDITOR.dom.element(l.body),r=e.widgets.registered.easyimage,g=0;for(l.data("cke-editable",1),l.appendHtml(t.dataValue),n=l.find("img"),o=0;o<n.count();o++){s=n.getItem(o);var d=(i=s.getAttribute("src"))&&"data:"==i.substring(0,5),m=null===s.data("cke-realelement");d&&m&&!s.isReadOnly(1)&&(g++,g>1&&(d=e.getSelection().getRanges(),d[0].enlarge(CKEDITOR.ENLARGE_ELEMENT),d[0].collapse(!1)),i.match(/image\/([a-z]+?);/i),d=r._spawnLoader(e,i,r),i=r._insertWidget(e,r,i,!1,{uploadId:d.id}),i.data("cke-upload-id",d.id),i.replace(s))}t.dataValue=l.getHtml()}})}function o(e){e.ui.addButton("EasyImageUpload",{label:e.lang.easyimage.commands.upload,command:"easyimageUpload",toolbar:"insert,1"}),e.addCommand("easyimageUpload",{exec:function(){var a=CKEDITOR.dom.element.createFromHtml('<input type="file" accept="image/*" multiple="multiple">');a.once("change",function(a){a=a.data.getTarget(),a.$.files.length&&e.fire("paste",{method:"paste",dataValue:"",dataTransfer:new CKEDITOR.plugins.clipboard.dataTransfer({files:a.$.files})})}),a.$.click()}})}var l=!1,r=["jpeg","png","gif","bmp"];CKEDITOR.plugins.easyimage={_parseSrcSet:function(e){var a,t=[];for(a in e)"default"!==a&&t.push(e[a]+" "+a+"w");return t.join(", ")}},CKEDITOR.plugins.add("easyimage",{requires:"imagebase,balloontoolbar,button,dialog,cloudservices",lang:"ar,az,bg,cs,da,de,de-ch,en,en-au,et,fa,fr,gl,hr,hu,it,ku,lv,nb,nl,no,pl,pt,pt-br,ro,ru,sk,sq,sr,sr-latn,sv,tr,tt,uk,zh,zh-cn",icons:"easyimagefull,easyimageside,easyimagealt,easyimagealignleft,easyimagealigncenter,easyimagealignright,easyimageupload",hidpi:!0,onLoad:function(){CKEDITOR.dialog.add("easyimageAlt",this.path+"dialogs/easyimagealt.js")},isSupportedEnvironment:function(){return!CKEDITOR.env.ie||11<=CKEDITOR.env.version},init:function(e){this.isSupportedEnvironment()&&(l||(CKEDITOR.document.appendStyleSheet(this.path+"styles/easyimage.css"),l=!0),e.addContentsCss&&e.addContentsCss(this.path+"styles/easyimage.css"))},afterInit:function(i){if(this.isSupportedEnvironment()){var l;l=CKEDITOR.tools.object.merge({full:{attributes:{"class":"easyimage-full"},label:i.lang.easyimage.commands.fullImage},side:{attributes:{"class":"easyimage-side"},label:i.lang.easyimage.commands.sideImage},alignLeft:{attributes:{"class":"easyimage-align-left"},label:i.lang.common.alignLeft},alignCenter:{attributes:{"class":"easyimage-align-center"},label:i.lang.common.alignCenter},alignRight:{attributes:{"class":"easyimage-align-right"},label:i.lang.common.alignRight}},i.config.easyimage_styles),n(i,l),s(i),a(i,l),i.ui.addButton("EasyImageAlt",{label:i.lang.easyimage.commands.altText,command:"easyimageAlt",toolbar:"easyimage,3"});for(var r in l)i.ui.addButton("EasyImage"+e(r),{label:l[r].label,command:"easyimage"+e(r),toolbar:"easyimage,99",icon:l[r].icon,iconHiDpi:l[r].iconHiDpi});t(i),l=i.config.easyimage_toolbar,i._.easyImageToolbarContext=i.balloonToolbars.create({buttons:l.join?l.join(","):l,widgets:["easyimage"]}),o(i)}}}),CKEDITOR.config.easyimage_class="easyimage",CKEDITOR.config.easyimage_styles={},CKEDITOR.config.easyimage_defaultStyle="full",CKEDITOR.config.easyimage_toolbar=["EasyImageFull","EasyImageSide","EasyImageAlt"]}();
|