From 87df6c74c98498daf6994b3080fc5e3ddac42382 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 26 Sep 2019 14:31:20 +0100 Subject: [PATCH] * Ensure you can only drag and drop or paste images in when the insert image/media button is enabled in thr RTE toolbar/config * If disallowed then we add a new native browser event for dragover etc to prevent dropping & showing the no/stop sign icon --- .../src/common/services/tinymce.service.js | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js index a91e3d6ecc..27b02e7976 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js @@ -338,15 +338,28 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s body_class: "umb-rte", //see http://archive.tinymce.com/wiki.php/Configuration:cache_suffix - cache_suffix: "?umb__rnd=" + Umbraco.Sys.ServerVariables.application.cacheBuster, + cache_suffix: "?umb__rnd=" + Umbraco.Sys.ServerVariables.application.cacheBuster + }; + + // Need to check if we are allowed to UPLOAD images + // This is done by checking if the insert image toolbar button is available + var insertMediaButtonFound = false; + args.toolbar.forEach(toolbarItem => { + if(toolbarItem.indexOf("umbmediapicker") > -1){ + insertMediaButtonFound = true; + } + }); + + if(insertMediaButtonFound){ + // Update the TinyMCE Config object to allow pasting + config.images_upload_handler = uploadImageHandler; + config.automatic_uploads = false; + config.images_replace_blob_uris = false; // This allows images to be pasted in & stored as Base64 until they get uploaded to server - paste_data_images: true, + config.paste_data_images = true; + } - images_upload_handler: uploadImageHandler, - automatic_uploads: false, - images_replace_blob_uris: false - }; if (args.htmlId) { config.selector = "#" + args.htmlId; @@ -1247,6 +1260,29 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s startWatch(); } + // If we can not find the insert image/media toolbar button + // Then we need to add an event listener to the editor + // That will update native browser drag & drop events + // To update the icon to show you can NOT drop something into the editor + var insertMediaButtonFound = false; + var toolbarItems = args.editor.settings.toolbar; + toolbarItems = toolbarItems.split(" "); + toolbarItems.forEach(toolbarItem => { + if(toolbarItem.indexOf("umbmediapicker") > -1){ + insertMediaButtonFound = true; + } + }); + + if(insertMediaButtonFound === false){ + // Wire up the event listener + args.editor.on('dragend dragover draggesture dragdrop drop drag', function (e) { + e.preventDefault(); + e.dataTransfer.effectAllowed = "none"; + e.dataTransfer.dropEffect = "none"; + e.stopPropagation(); + }); + } + args.editor.on('SetContent', function (e) { var content = e.content;