From 85ea47212945482f6fe8713f7e73fc3fa3c476f9 Mon Sep 17 00:00:00 2001 From: Nicholas-Westby Date: Wed, 18 May 2016 20:03:05 -0700 Subject: [PATCH] Fix for error during Archetype drags when there are rich text editors outside of Archetype: https://github.com/imulus/Archetype/issues/362 --- app/services/archetypeService.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/services/archetypeService.js b/app/services/archetypeService.js index a4379e4..6d74999 100644 --- a/app/services/archetypeService.js +++ b/app/services/archetypeService.js @@ -2,7 +2,7 @@ angular.module('umbraco.services').factory('archetypeService', function () { // Variables. var draggedRteArchetype; - var rteClass = ".umb-rte textarea"; + var rteClass = ".archetypeEditor .umb-rte textarea"; var editorSettings = {}; var disabledSortables = []; @@ -75,10 +75,12 @@ angular.module('umbraco.services').factory('archetypeService', function () { return reversed.join("-"); }, getFieldset: function(scope) { - return scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex]; + var renderModel = scope.archetypeRenderModel; + return renderModel ? renderModel.fieldsets[scope.fieldsetIndex] : null; }, getFieldsetProperty: function (scope) { - return this.getFieldset(scope).properties[scope.renderModelPropertyIndex]; + var fieldset = this.getFieldset(scope); + return fieldset ? fieldset.properties[scope.renderModelPropertyIndex] : null; }, setFieldsetValidity: function (fieldset) { // mark the entire fieldset as invalid if there are any invalid properties in the fieldset, otherwise mark it as valid @@ -146,10 +148,10 @@ angular.module('umbraco.services').factory('archetypeService', function () { // Get the property's temporary ID. var scope = angular.element(this).scope().$parent; var property = self.getFieldsetProperty(scope); - var tempId = property.editorState.temporaryId; + var tempId = property ? property.editorState.temporaryId : null; // Store the editor settings by the temporary ID? - if (editor && editor.settings) { + if (editor && editor.settings && tempId) { editorSettings[tempId] = editor.settings; } @@ -180,12 +182,14 @@ angular.module('umbraco.services').factory('archetypeService', function () { // Get the stored editor settings. var scope = angular.element(this).scope().$parent; var property = self.getFieldsetProperty(scope); - var tempId = property.editorState.temporaryId; + var tempId = property ? property.editorState.temporaryId : null; var settings = editorSettings[tempId]; // Remove and reinitialize the editor. - tinyMCE.execCommand("mceRemoveEditor", false, id); - tinyMCE.init(settings); + if (settings) { + tinyMCE.execCommand("mceRemoveEditor", false, id); + tinyMCE.init(settings); + } });