more manual merging - getting anchors back in tinymce

This commit is contained in:
Shannon
2019-07-01 16:22:54 +10:00
parent 958c3b147b
commit 80e6880bb7
6 changed files with 64 additions and 28 deletions

View File

@@ -6,7 +6,7 @@
* @description
* A service containing all logic for all of the Umbraco TinyMCE plugins
*/
function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, stylesheetResource, macroResource, macroService, $routeParams, umbRequestHelper, angularHelper, userService, editorService, editorState) {
function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, stylesheetResource, macroResource, macroService, $routeParams, umbRequestHelper, angularHelper, userService, editorService, editorState, contentEditingHelper) {
//These are absolutely required in order for the macros to render inline
//we put these as extended elements because they get merged on top of the normal allowed elements by tiny mce
@@ -1077,6 +1077,42 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s
startWatch();
}
/**
* Internal method ... to retrieve the anchor named properties from the serialized string of a content item's properties
*
* From the given string, generates a string array where each item is the id attribute value from a named anchor
* 'some string <a id="anchor"></a>with a named anchor' returns ['anchor']
*/
function getCurrentAnchorNames() {
if (!editorState.current || !editorState.current.variants) {
return null;
}
//fixme - this only takes into account the first variant , not the 'current' one.
var jsonProperties = JSON.stringify(contentEditingHelper.getAllProps(editorState.current.variants[0]));
if (!jsonProperties) {
return null;
}
var anchors = [];
var anchorPattern = /<a id=\\"(.*?)\\">/gi;
var matches = jsonProperties.match(anchorPattern);
if (matches) {
anchors = matches.map(function (v) {
return v.substring(v.indexOf('"') + 1, v.lastIndexOf('\\'));
});
}
return anchors.filter(function (val, i, self) {
return self.indexOf(val) === i;
});
}
args.editor.on('init', function (e) {
if (args.model.value) {
@@ -1118,7 +1154,7 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s
self.createLinkPicker(args.editor, function (currentTarget, anchorElement) {
var linkPicker = {
currentTarget: currentTarget,
anchors: editorState.current ? self.getAnchorNames(JSON.stringify(editorState.current.properties)) : [],
anchors: getCurrentAnchorNames(),
submit: function (model) {
self.insertLinkInEditor(args.editor, model.target, anchorElement);
editorService.close();

View File

@@ -1,6 +1,6 @@
//used for the media picker dialog
angular.module("umbraco").controller("Umbraco.Editors.LinkPickerController",
function ($scope, eventsService, entityResource, mediaResource, mediaHelper, udiParser, userService, localizationService, tinyMceService, editorService, contentEditingHelper) {
function ($scope, eventsService, entityResource, mediaResource, mediaHelper, udiParser, userService, localizationService, editorService) {
var vm = this;
var dialogOptions = $scope.model;