CKEDITOR.plugins.add("ipspaste",{requires:"clipboard",init:function(a){function q(b){var c=a.getSelection().createBookmarks2();if(d.length&&b.data.dataTransfer.getFilesCount()&&-1==_.indexOf(g,b.data.dataTransfer.id))for(var e=0;e<b.data.dataTransfer.getFilesCount();e++)g.push(b.data.dataTransfer.id),d.trigger("injectFile",{file:b.data.dataTransfer.getFile(e),data:{insertPoint:c}})}function p(){var b=$("."+a.id).closest("[data-ipsEditor]").find('[data-role\x3d"imageMessage"]');b.slideDown({queue:!1});
b.find('[data-action\x3d"removeImageMessage"]').click(function(){b.slideUp()})}if(a.contextMenu)a.on("pluginsLoaded",function(){a.removeMenuItem("cut");a.removeMenuItem("copy")});a.addCommand("ipspasteplain",{canUndo:!1,async:!0,exec:function(b){b.getClipboardData({title:ips.getString("pasteAsPlaintext")},function(a){a&&b.fire("paste",{type:"text",dataValue:a.dataValue,method:"paste",dataTransfer:CKEDITOR.plugins.clipboard.initPasteDataTransfer(),force:!0});b.fire("afterCommandExec",{name:"pastetext",
command:"ipspasteplain",returnValue:!!a})})}});a.contextMenu&&(a.addMenuItem("ipspasteplain",{label:ips.getString("pasteAsPlaintext"),icon:this.path+"icons"+(CKEDITOR.env.hidpi?"/hidpi":"")+"/pastetext.png",command:"ipspasteplain",group:"clipboard",order:16}),a.contextMenu.addListener(function(a,c){inReadOnly=c.getRanges()[0].checkReadOnly();return{ipspasteplain:CKEDITOR.TRISTATE_OFF}}));CKEDITOR.plugins.clipboard.addFileMatcher(a,function(a){return!0});var h=function(b,c){var e=a.getSelection().createBookmarks(!0);
a.focus();if(c.data.insertPoint)a.getSelection().selectBookmarks(c.data.insertPoint),a.insertHtml(c.content);else if(c.data.placeholder){var d=a.document.find("img.pastedImagePlaceholder"+c.data.placeholder);d.count()&&a.getSelection().selectElement(d.getItem(0));a.insertHtml(c.content)}a.focus();a.getSelection().selectBookmarks(e)},d=$(a.element.$).closest("[data-ipsEditor]").find("[data-ipsUploader]");if(d.length)d.on("injectedFileReadyForInsert",h);else{var k=$(a.element.$).closest("[data-ipsEditor]");
k.on("uploaderReady",function(){d=k.find("[data-ipsUploader]");d.length&&!d.data("pasteReady")&&(d.on("injectedFileReadyForInsert",h),d.data("pasteReady",!0))})}var g=[];if("force"==a.config.ipsPasteBehaviour)a.on("paste",function(a){q(a);"paste"==a.data.method&&(a.data.type="text")},this,{},0);else a.on("paste",function(b){b.data.dataValue&&(CKEDITOR.env.gecko||CKEDITOR.env.edge||CKEDITOR.env.chrome&&!CKEDITOR.env.mac)&&"paste"==b.data.method||(q(b),b.data.dataTransfer.getFilesCount()&&(b.data.dataValue=
""));if(b.data.dataValue){if(CKEDITOR.env.safari){var c=b.data.dataValue.match(/<img src="webkit-fake-url:\/\//);c&&(b.data.dataValue=b.data.dataValue.replace(/<img src="webkit-fake-url:\/\/[^>]*>/,""),p());if(c=b.data.dataValue.match(/<img src="blob:(.+?)"/))b.data.dataValue=b.data.dataValue.replace(/<img src="blob:[^>]*>/,""),p()}if(!b.data.dataValue.match(/data-cke-widget-drag-handler/i)&&(c=b.data.dataValue.match(/<img[^>]*src=(["'])data:image\/(jpeg|png|gif|webp);base64,[A-Z0-9\/\+]*=*\1[^>]*>/gi)))if(d.length)for(var e=
0;e<c.length;e++){var g=Math.random().toString(36).substring(7);b.data.dataValue=b.data.dataValue.replace(c[e],'\x3cimg class\x3d"pastedImagePlaceholder'+g+'" content-editable\x3d"false"\x3e');for(var l=c[e].match(/src=(["'])data:(image\/(jpeg|png|gif|webp));base64,([A-Z0-9\/\+]*=*)\1/i),h=atob(l[4]),m=h.length,k=new Uint8Array(m);m--;)k[m]=h.charCodeAt(m);l=new File([k],"image."+l[3],{type:l[2]});d.trigger("injectFile",{file:l,data:{placeholder:g}})}else{for(e=0;e<c.length;e++)b.data.dataValue=b.data.dataValue.replace(c[e],
"");p()}if(-1!==b.data.dataValue.replace(/<((\/)?(p|a( href=["'].+?['"])?)|br(.+?)?)>/g,"").indexOf("\x3c")&&"force"!=a.config.ipsPasteBehaviour&&!b.data.force){var u=a.getSnapshot(),r=a.getSelection().createBookmarks2(!0),t=null;a.once("afterPaste",function(b){t=a.getSelection().createBookmarks2(!0);a.once("key",function(){n()});a.once("setData",function(){n()})});var f=$("."+a.id).closest("[data-ipsEditor]").find('[data-role\x3d"pasteMessage"]');f.slideDown({queue:!1});var n=function(){f.slideUp({queue:!1});
f.find('[data-action\x3d"keepPasteFormatting"]').off("click.ipsPaste");f.find('[data-action\x3d"removePasteFormatting"]').off("click.ipsPaste")};f.find('[data-action\x3d"keepPasteFormatting"]').on("click.ipsPaste",function(){a.focus();a.getSelection().selectBookmarks(t||r);n()});f.find('[data-action\x3d"removePasteFormatting"]').on("click.ipsPaste",function(){a.focus();a.loadSnapshot(u);a.getSelection().selectBookmarks(r);a.fire("paste",{type:"text",dataValue:b.data.dataValue,method:"paste",dataTransfer:CKEDITOR.plugins.clipboard.initPasteDataTransfer()});
n()})}}},this)}});