Populates the anchor when found

Also fixes one of the JS files where .model was seemingly used randomly, but the view doesn't want a .model in there
This commit is contained in:
Sebastiaan Janssen
2018-08-23 21:31:31 +02:00
parent 05fdfc6b34
commit 1b1df84863
2 changed files with 12 additions and 8 deletions

View File

@@ -40,14 +40,17 @@ angular.module("umbraco").controller("Umbraco.Dialogs.LinkPickerController",
// if a link exists, get the properties to build the anchor name list
contentResource.getById(id).then(function (resp) {
$scope.anchorValues = tinyMceService.getAnchorNames(JSON.stringify(resp.properties));
$scope.model.target.url = resp.urls[0];
$scope.target.url = resp.urls[0];
});
} else if ($scope.target.url.length) {
// a url but no id/udi indicates an external link - trim the url to remove the anchor/qs
// only do the substring if there's a # or a ?
var indexOfAnchor = $scope.model.target.url.search(/(#|\?)/);
if (indexOfAnchor > -1) {
$scope.model.target.url = $scope.model.target.url.substring(0, indexOfAnchor);
var indexOfAnchor = $scope.target.url.search(/(#|\?)/);
if (indexOfAnchor > -1) {
// populate the anchor
$scope.target.anchor = $scope.target.url.substring(indexOfAnchor);
// then rewrite the model and populate the link
$scope.target.url = $scope.target.url.substring(0, indexOfAnchor);
}
}
}
@@ -85,7 +88,7 @@ angular.module("umbraco").controller("Umbraco.Dialogs.LinkPickerController",
} else {
contentResource.getById(args.node.id).then(function (resp) {
$scope.anchorValues = tinyMceService.getAnchorNames(JSON.stringify(resp.properties));
$scope.model.target.url = resp.urls[0];
$scope.target.url = resp.urls[0];
});
}

View File

@@ -3,8 +3,6 @@ angular.module("umbraco").controller("Umbraco.Overlays.LinkPickerController",
function ($scope, eventsService, dialogService, entityResource, contentResource, mediaHelper, userService, localizationService, tinyMceService) {
var dialogOptions = $scope.model;
var anchorPattern = /<a id=\\"(.*?)\\">/gi;
var searchText = "Search...";
localizationService.localize("general_search").then(function (value) {
searchText = value + "...";
@@ -52,10 +50,13 @@ angular.module("umbraco").controller("Umbraco.Overlays.LinkPickerController",
$scope.model.target.url = resp.urls[0];
});
} else if ($scope.model.target.url.length) {
// a url but no id/udi indicates an external link - trim the url to remove the anchor/qs
// a url but no id/udi indicates an external link - trim the url to remove the anchor/qs
// only do the substring if there's a # or a ?
var indexOfAnchor = $scope.model.target.url.search(/(#|\?)/);
if (indexOfAnchor > -1) {
// populate the anchor
$scope.model.target.anchor = $scope.model.target.url.substring(indexOfAnchor);
// then rewrite the model and populate the link
$scope.model.target.url = $scope.model.target.url.substring(0, indexOfAnchor);
}
}