mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
add link dialog now allows switching between reference link and normal hyperlink
This commit is contained in:
parent
9b17e9976e
commit
a36d6bf9be
2
libraries/ckeditor/ckeditor.js
vendored
2
libraries/ckeditor/ckeditor.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -6,6 +6,7 @@ const $dialog = $("#add-link-dialog");
|
|||||||
const $form = $("#add-link-form");
|
const $form = $("#add-link-form");
|
||||||
const $autoComplete = $("#add-link-note-autocomplete");
|
const $autoComplete = $("#add-link-note-autocomplete");
|
||||||
const $linkTitle = $("#link-title");
|
const $linkTitle = $("#link-title");
|
||||||
|
const $addLinkTitleSettings = $("#add-link-title-settings");
|
||||||
const $addLinkTitleFormGroup = $("#add-link-title-form-group");
|
const $addLinkTitleFormGroup = $("#add-link-title-form-group");
|
||||||
|
|
||||||
/** @var TextTypeWidget */
|
/** @var TextTypeWidget */
|
||||||
@ -14,7 +15,10 @@ let textTypeWidget;
|
|||||||
export async function showDialog(widget) {
|
export async function showDialog(widget) {
|
||||||
textTypeWidget = widget;
|
textTypeWidget = widget;
|
||||||
|
|
||||||
$addLinkTitleFormGroup.toggle(!textTypeWidget.hasSelection());
|
$addLinkTitleSettings.toggle(!textTypeWidget.hasSelection());
|
||||||
|
|
||||||
|
updateTitleFormGroupVisibility();
|
||||||
|
$addLinkTitleSettings.find('input[type=radio]').on('change', updateTitleFormGroupVisibility);
|
||||||
|
|
||||||
utils.openDialog($dialog);
|
utils.openDialog($dialog);
|
||||||
|
|
||||||
@ -50,13 +54,25 @@ export async function showDialog(widget) {
|
|||||||
noteAutocompleteService.showRecentNotes($autoComplete);
|
noteAutocompleteService.showRecentNotes($autoComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLinkType() {
|
||||||
|
return $addLinkTitleSettings.find('input[type=radio]:checked').val();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTitleFormGroupVisibility() {
|
||||||
|
const visible = getLinkType() === 'hyper-link';
|
||||||
|
|
||||||
|
$addLinkTitleFormGroup.toggle(visible);
|
||||||
|
}
|
||||||
|
|
||||||
$form.on('submit', () => {
|
$form.on('submit', () => {
|
||||||
const notePath = $autoComplete.getSelectedPath();
|
const notePath = $autoComplete.getSelectedPath();
|
||||||
|
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
$dialog.modal('hide');
|
$dialog.modal('hide');
|
||||||
|
|
||||||
textTypeWidget.addLink(notePath, $linkTitle.val());
|
const linkTitle = getLinkType() === 'reference-link' ? null : $linkTitle.val();
|
||||||
|
|
||||||
|
textTypeWidget.addLink(notePath, linkTitle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error("No path to add link.");
|
console.error("No path to add link.");
|
||||||
|
@ -220,7 +220,7 @@ export default class TextTypeWidget extends TypeWidget {
|
|||||||
async addLink(notePath, linkTitle) {
|
async addLink(notePath, linkTitle) {
|
||||||
await this.initialized;
|
await this.initialized;
|
||||||
|
|
||||||
if (linkTitle && false) {
|
if (linkTitle) {
|
||||||
if (this.hasSelection()) {
|
if (this.hasSelection()) {
|
||||||
this.textEditor.execute('link', '#' + notePath);
|
this.textEditor.execute('link', '#' + notePath);
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,9 +20,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group" id="add-link-title-form-group">
|
<div id="add-link-title-settings">
|
||||||
<label for="link-title">Link title</label>
|
<div class="form-check">
|
||||||
<input id="link-title" class="form-control" style="width: 100%;">
|
<input class="form-check-input" type="radio" name="link-type" value="reference-link" id="add-link-reference-link" checked>
|
||||||
|
<label class="form-check-label" for="add-link-reference-link">
|
||||||
|
link title mirrors the note's current title
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="link-type" value="hyper-link" id="add-link-hyper-link">
|
||||||
|
<label class="form-check-label" for="add-link-hyper-link">
|
||||||
|
link title can be changed arbitrarily
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="add-link-title-form-group">
|
||||||
|
<label for="link-title">Link title</label>
|
||||||
|
<input id="link-title" class="form-control" style="width: 100%;">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user