--- /dev/null
+/*\r
+ * @file image paste plugin for CKEditor\r
+ Feature introduced in: https://bugzilla.mozilla.org/show_bug.cgi?id=490879\r
+ doesn't include images inside HTML (paste from word): https://bugzilla.mozilla.org/show_bug.cgi?id=665341\r
+ * Copyright (C) 2011 Alfonso Mart�nez de Lizarrondo\r
+ *\r
+ * == BEGIN LICENSE ==\r
+ *\r
+ * Licensed under the terms of any of the following licenses at your\r
+ * choice:\r
+ *\r
+ * - GNU General Public License Version 2 or later (the "GPL")\r
+ * http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ * http://www.gnu.org/licenses/lgpl.html\r
+ *\r
+ * - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ * http://www.mozilla.org/MPL/MPL-1.1.html\r
+ *\r
+ * == END LICENSE ==\r
+ *\r
+ */\r
+\r
+ // Handles image pasting in Firefox\r
+CKEDITOR.plugins.add( 'imagepaste',\r
+{\r
+ init : function( editor )\r
+ {\r
+\r
+ // Paste from clipboard:\r
+ editor.on( 'paste', function(e) {\r
+\r
+ var html = e.data.html;\r
+ if (!html)\r
+ return;\r
+\r
+ // Replace data: images in Firefox and upload them\r
+ e.data.html = html.replace( /<img src="data:image\/png;base64,.*?" alt="">/g, function( img )\r
+ {\r
+ var data = img.match(/"data:image\/png;base64,(.*?)"/)[1];\r
+ var id = CKEDITOR.tools.getNextId();\r
+\r
+ var url= editor.config.filebrowserImageUploadUrl + '&CKEditor=' + editor.name + '&CKEditorFuncNum=2&langCode=' + editor.langCode;\r
+\r
+ var xhr = new XMLHttpRequest();\r
+\r
+ xhr.open("POST", url);\r
+ xhr.onload = function() {\r
+ // Upon finish, get the url and update the file\r
+ if(xhr.responseText.match(/2,\s*'(.*?)',/) != null){\r
+ var imageUrl = xhr.responseText.match(/2,\s*'(.*?)',/)[1];\r
+ var theImage = editor.document.getById( id );\r
+ theImage.data( 'cke-saved-src', imageUrl);\r
+ theImage.setAttribute( 'src', imageUrl);\r
+ theImage.removeAttribute( 'id' );\r
+ } else {\r
+ return;\r
+ }\r
+ }\r
+\r
+ // Create the multipart data upload. Is it possible somehow to use FormData instead?\r
+ var BOUNDARY = "---------------------------1966284435497298061834782736";\r
+ var rn = "\r\n";\r
+ var req = "--" + BOUNDARY;\r
+\r
+ req += rn + "Content-Disposition: form-data; name=\"upload\"";\r
+\r
+ var bin = window.atob( data );\r
+ // add timestamp?\r
+ req += "; filename=\"" + id + ".png\"" + rn + "Content-type: image/png";\r
+\r
+ req += rn + rn + bin + rn + "--" + BOUNDARY;\r
+\r
+ req += "--";\r
+\r
+ xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);\r
+ xhr.sendAsBinary(req);\r
+\r
+ return img.replace(/>/, ' id="' + id + '">')\r
+\r
+ });\r
+ });\r
+\r
+ } //Init\r
+} );\r