mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
add link disables HTML link when in code note (plus some related refactorings)
This commit is contained in:
parent
403cf02ea7
commit
8adb31757f
@ -8,19 +8,30 @@ const addLink = (function() {
|
|||||||
const clonePrefixEl = $("#clone-prefix");
|
const clonePrefixEl = $("#clone-prefix");
|
||||||
const linkTitleFormGroup = $("#add-link-title-form-group");
|
const linkTitleFormGroup = $("#add-link-title-form-group");
|
||||||
const prefixFormGroup = $("#add-link-prefix-form-group");
|
const prefixFormGroup = $("#add-link-prefix-form-group");
|
||||||
|
const linkTypeEls = $("input[name='add-link-type']");
|
||||||
|
const linkTypeHtmlEl = linkTypeEls.filter('input[value="html"]');
|
||||||
|
|
||||||
|
function setLinkType(linkType) {
|
||||||
|
linkTypeEls.each(function () {
|
||||||
|
$(this).prop('checked', $(this).val() === linkType);
|
||||||
|
});
|
||||||
|
|
||||||
|
linkTypeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
function showDialog() {
|
function showDialog() {
|
||||||
glob.activeDialog = dialogEl;
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
$('input[name="add-link-type"]').each(function () {
|
if (noteEditor.getCurrentNoteType() === 'text') {
|
||||||
$(this).prop('checked', $(this).val() === "html");
|
linkTypeHtmlEl.prop('disabled', false);
|
||||||
});
|
|
||||||
|
|
||||||
linkTitleEl.val('');
|
setLinkType('html');
|
||||||
clonePrefixEl.val('');
|
}
|
||||||
|
else {
|
||||||
|
linkTypeHtmlEl.prop('disabled', true);
|
||||||
|
|
||||||
linkTitleFormGroup.show();
|
setLinkType('selected-to-current');
|
||||||
prefixFormGroup.hide();
|
}
|
||||||
|
|
||||||
dialogEl.dialog({
|
dialogEl.dialog({
|
||||||
modal: true,
|
modal: true,
|
||||||
@ -28,6 +39,7 @@ const addLink = (function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
autoCompleteEl.val('').focus();
|
autoCompleteEl.val('').focus();
|
||||||
|
clonePrefixEl.val('');
|
||||||
linkTitleEl.val('');
|
linkTitleEl.val('');
|
||||||
|
|
||||||
function setDefaultLinkTitle(noteId) {
|
function setDefaultLinkTitle(noteId) {
|
||||||
@ -42,6 +54,10 @@ const addLink = (function() {
|
|||||||
change: () => {
|
change: () => {
|
||||||
const val = autoCompleteEl.val();
|
const val = autoCompleteEl.val();
|
||||||
const notePath = link.getNodePathFromLabel(val);
|
const notePath = link.getNodePathFromLabel(val);
|
||||||
|
if (!notePath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||||
|
|
||||||
if (noteId) {
|
if (noteId) {
|
||||||
@ -94,8 +110,10 @@ const addLink = (function() {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$("input[name='add-link-type']").change(function() {
|
function linkTypeChanged() {
|
||||||
if (this.value === 'html') {
|
const value = linkTypeEls.filter(":checked").val();
|
||||||
|
|
||||||
|
if (value === 'html') {
|
||||||
linkTitleFormGroup.show();
|
linkTitleFormGroup.show();
|
||||||
prefixFormGroup.hide();
|
prefixFormGroup.hide();
|
||||||
}
|
}
|
||||||
@ -103,7 +121,9 @@ const addLink = (function() {
|
|||||||
linkTitleFormGroup.hide();
|
linkTitleFormGroup.hide();
|
||||||
prefixFormGroup.show();
|
prefixFormGroup.show();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
linkTypeEls.change(linkTypeChanged);
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+l', e => {
|
$(document).bind('keydown', 'ctrl+l', e => {
|
||||||
showDialog();
|
showDialog();
|
||||||
|
@ -190,6 +190,12 @@ const noteEditor = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentNoteType() {
|
||||||
|
const currentNote = getCurrentNote();
|
||||||
|
|
||||||
|
return currentNote ? currentNote.detail.type : null;
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
noteTitleEl.on('input', () => {
|
noteTitleEl.on('input', () => {
|
||||||
noteChanged();
|
noteChanged();
|
||||||
@ -239,6 +245,7 @@ const noteEditor = (function() {
|
|||||||
setNoteBackgroundIfProtected,
|
setNoteBackgroundIfProtected,
|
||||||
loadNote,
|
loadNote,
|
||||||
getCurrentNote,
|
getCurrentNote,
|
||||||
|
getCurrentNoteType,
|
||||||
getCurrentNoteId,
|
getCurrentNoteId,
|
||||||
newNoteCreated,
|
newNoteCreated,
|
||||||
getEditor,
|
getEditor,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user