From a59fffd891aaadd2510486bc9f76a15368d69172 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 26 Sep 2019 15:10:23 +0100 Subject: [PATCH] Keep it DRY --- .../src/common/services/tinymce.service.js | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 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 27b02e7976..16b1c6ec9d 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 @@ -251,6 +251,16 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s } } + function isMediaPickerEnabled(toolbarItemArray){ + var insertMediaButtonFound = false; + toolbarItemArray.forEach(toolbarItem => { + if(toolbarItem.indexOf("umbmediapicker") > -1){ + insertMediaButtonFound = true; + } + }); + return insertMediaButtonFound; + } + return { /** @@ -343,14 +353,7 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s // 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){ + if(isMediaPickerEnabled(args.toolbar)){ // Update the TinyMCE Config object to allow pasting config.images_upload_handler = uploadImageHandler; config.automatic_uploads = false; @@ -1264,16 +1267,8 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s // 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){ + var toolbarItems = args.editor.settings.toolbar.split(" "); + if(isMediaPickerEnabled(toolbarItems) === false){ // Wire up the event listener args.editor.on('dragend dragover draggesture dragdrop drop drag', function (e) { e.preventDefault();