V8: Make the markdown editor use the Umbraco link picker (#5745)

This commit is contained in:
Kenn Jacobsen
2020-01-10 10:05:52 +01:00
committed by Sebastiaan Janssen
parent 16faeb1886
commit 2b4279315a
2 changed files with 26 additions and 4 deletions

View File

@@ -60,6 +60,7 @@
* its own image insertion dialog, this hook should return true, and the callback should be called with the chosen
* image url (or null if the user cancelled). If this hook returns false, the default dialog will be used.
*/
hooks.addFalse("insertLinkDialog");
this.getConverter = function () { return markdownConverter; }
@@ -1636,7 +1637,7 @@
var that = this;
// The function to be executed when you enter a link and press OK or Cancel.
// Marks up the link and adds the ref.
var linkEnteredCallback = function (link) {
var linkEnteredCallback = function (link, title) {
if (link !== null) {
// ( $1
@@ -1667,10 +1668,10 @@
if (!chunk.selection) {
if (isImage) {
chunk.selection = "enter image description here";
chunk.selection = title || "enter image description here";
}
else {
chunk.selection = "enter link description here";
chunk.selection = title || "enter link description here";
}
}
}
@@ -1683,7 +1684,8 @@
ui.prompt('Insert Image', imageDialogText, imageDefaultText, linkEnteredCallback);
}
else {
ui.prompt('Insert Link', linkDialogText, linkDefaultText, linkEnteredCallback);
if (!this.hooks.insertLinkDialog(linkEnteredCallback))
ui.prompt('Insert Link', linkDialogText, linkDefaultText, linkEnteredCallback);
}
return true;
}

View File

@@ -27,6 +27,20 @@ function MarkdownEditorController($scope, $element, assetsService, editorService
editorService.mediaPicker(mediaPicker);
}
function openLinkPicker(callback) {
var linkPicker = {
hideTarget: true,
submit: function(model) {
callback(model.target.url, model.target.name);
editorService.close();
},
close: function() {
editorService.close();
}
};
editorService.linkPicker(linkPicker);
}
assetsService
.load([
"lib/markdown/markdown.converter.js",
@@ -53,6 +67,12 @@ function MarkdownEditorController($scope, $element, assetsService, editorService
return true; // tell the editor that we'll take care of getting the image url
});
//subscribe to the link dialog clicks
editor2.hooks.set("insertLinkDialog", function (callback) {
openLinkPicker(callback);
return true; // tell the editor that we'll take care of getting the link url
});
editor2.hooks.set("onPreviewRefresh", function () {
// We must manually update the model as there is no way to hook into the markdown editor events without exstensive edits to the library.
if ($scope.model.value !== $("textarea", $element).val()) {