From 9ed54eb3fd4c8facecf9ba5303e32710f164593d Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 2 Jul 2014 20:50:39 +0000 Subject: [PATCH] Drag & drop images don't work because of DB field sizes, so replace dropped images with error image so user knows right away it won't work. --- etemplate/js/et2_widget_htmlarea.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/etemplate/js/et2_widget_htmlarea.js b/etemplate/js/et2_widget_htmlarea.js index 1c53d51535..57aab079d3 100644 --- a/etemplate/js/et2_widget_htmlarea.js +++ b/etemplate/js/et2_widget_htmlarea.js @@ -139,6 +139,7 @@ var et2_htmlarea = et2_inputWidget.extend( if(this.ckeditor && this.options.config.preference_style) { + var editor = this.ckeditor; this.ckeditor.on('instanceReady', function(e) { // Add in user font preferences @@ -161,6 +162,33 @@ var et2_htmlarea = et2_inputWidget.extend( range.collapse(true); range.select(); }); + + // Drag & drop of images inline won't work, because of database + // field sizes. For some reason FF ignored just changing the cursor + // when dragging, so we replace dropped images with error icon. + var replaceImgText = function(html) { + var ret = html.replace( /]*src="(data:.*;base64,.*?)"[^>]*>/gi, function( img, src ){ + return img.replace(src,egw.image('error')); + }); + return ret; + } + + var chkImg = function() { + // don't execute code if the editor is readOnly + if (editor.readOnly) + return; + + setTimeout( function() { + editor.document.$.body.innerHTML = replaceImgText(editor.document.$.body.innerHTML); + },200); + }; + + editor.on( 'contentDom', function() { + // For Firefox + editor.document.on('drop', chkImg); + // For IE + editor.document.getBody().on('drop', chkImg); + }); } },