add link disables HTML link when in code note (plus some related refactorings)

This commit is contained in:
azivner 2018-01-23 20:14:10 -05:00
parent 403cf02ea7
commit 8adb31757f
2 changed files with 37 additions and 10 deletions

View File

@ -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();

View File

@ -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,