diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js index dee9a4409a..5d6a3bf12c 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js @@ -40,11 +40,18 @@ 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 - $scope.target.url = $scope.model.url.substring(0, $scope.model.url.search(/(#|\?)/)); + // 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.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); + } } } @@ -81,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]; }); } diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/linkpicker/linkpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/linkpicker/linkpicker.controller.js index 208eb88e51..4d6022e175 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/linkpicker/linkpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/linkpicker/linkpicker.controller.js @@ -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 = //gi; - var searchText = "Search..."; localizationService.localize("general_search").then(function (value) { searchText = value + "..."; @@ -52,8 +50,15 @@ 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 - $scope.model.target.url = $scope.model.target.url.substring(0, $scope.model.target.url.search(/(#|\?)/)); + // 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); + } } } else if (dialogOptions.anchors) { $scope.anchorValues = dialogOptions.anchors;