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