refactoring of legacy js events

This commit is contained in:
zadam 2019-11-09 17:45:22 +01:00
parent 31bcc037f1
commit 3a1c80c189
22 changed files with 34 additions and 31 deletions

View File

@ -96,7 +96,7 @@ $("#logout-button").on('click', () => {
.append($(`<input type="hidden" name="_csrf" value="${glob.csrfToken}"/>`));
$("body").append($logoutForm);
$logoutForm.submit();
$logoutForm.trigger('submit');
});
$("#tree").on("click", ".unhoist-button", hoistedNoteService.unhoist);

View File

@ -19,7 +19,7 @@ export async function showDialog() {
$dialog.modal();
$autoComplete.val('').focus();
$autoComplete.val('').trigger('focus');
$linkTitle.val('');
async function setDefaultLinkTitle(noteId) {
@ -51,7 +51,7 @@ export async function showDialog() {
noteAutocompleteService.showRecentNotes($autoComplete);
}
$form.submit(() => {
$form.on('submit', () => {
const notePath = $autoComplete.getSelectedPath();
if (notePath) {

View File

@ -99,7 +99,7 @@ function AttributesModel() {
await showAttributes(attributes);
// attribute might not be rendered immediatelly so could not focus
setTimeout(() => $(".attribute-type-select:last").focus(), 1000);
setTimeout(() => $(".attribute-type-select:last").trigger('focus'), 1000);
};
this.deleteAttribute = function(data, event) {
@ -129,7 +129,7 @@ function AttributesModel() {
// we need to defocus from input (in case of enter-triggered save) because value is updated
// on blur event (because of conflict with jQuery UI Autocomplete). Without this, input would
// stay in focus, blur wouldn't be triggered and change wouldn't be updated in the viewmodel.
$saveAttributesButton.focus();
$saveAttributesButton.trigger('focus');
if (!isValid()) {
alert("Please fix all validation errors and try saving again.");

View File

@ -41,10 +41,10 @@ async function savePrefix() {
toastService.showMessage("Branch prefix has been saved.");
}
$form.submit(() => {
$form.on('submit', () => {
savePrefix();
return false;
});
$dialog.on('shown.bs.modal', () => $treePrefixInput.focus());
$dialog.on('shown.bs.modal', () => $treePrefixInput.trigger('focus'));

View File

@ -26,13 +26,13 @@ export async function showDialog(noteId) {
$dialog.modal();
$noteAutoComplete.val('').focus();
$noteAutoComplete.val('').trigger('focus');
noteAutocompleteService.initNoteAutocomplete($noteAutoComplete);
noteAutocompleteService.showRecentNotes($noteAutoComplete);
}
$form.submit(() => {
$form.on('submit', () => {
const notePath = $noteAutoComplete.getSelectedPath();
if (notePath) {

View File

@ -64,7 +64,7 @@ $dialog.on("hidden.bs.modal", () => {
}
if ($originallyFocused) {
$originallyFocused.focus();
$originallyFocused.trigger('focus');
$originallyFocused = null;
}
});

View File

@ -49,7 +49,7 @@ export async function showDialog(node, defaultType) {
$noteTitle.html(noteTitle);
}
$form.submit(() => {
$form.on('submit', () => {
$dialog.modal('hide');
const exportType = $dialog.find("input[name='export-type']:checked").val();

View File

@ -35,7 +35,7 @@ export async function showDialog(node) {
$dialog.modal();
}
$form.submit(() => {
$form.on('submit', () => {
// disabling so that import is not triggered again.
$importButton.attr("disabled", "disabled");

View File

@ -29,7 +29,7 @@ $dialog.on("hidden.bs.modal", () => {
}
if ($originallyFocused) {
$originallyFocused.focus();
$originallyFocused.trigger('focus');
$originallyFocused = null;
}
});

View File

@ -51,6 +51,6 @@ async function sendForm() {
$importButton.on('click', sendForm);
$dialog.on('shown.bs.modal', () => $importTextarea.focus());
$dialog.on('shown.bs.modal', () => $importTextarea.trigger('focus'));
utils.bindElShortcut($dialog, 'ctrl+return', sendForm);

View File

@ -31,7 +31,7 @@ export default class ChangePasswordOptions {
this.$newPassword1 = $("#new-password1");
this.$newPassword2 = $("#new-password2");
this.$form.submit(() => this.save());
this.$form.on('submit', () => this.save());
}
optionsLoaded(options) {}

View File

@ -47,7 +47,7 @@ export default class SyncOptions {
this.$syncProxy = $("#sync-proxy");
this.$testSyncButton = $("#test-sync-button");
this.$form.submit(() => this.save());
this.$form.on('submit', () => this.save());
this.$testSyncButton.on('click', async () => {
const result = await server.post('sync/test');

View File

@ -44,7 +44,7 @@ $dialog.on('shown.bs.modal', () => {
shownCb({ $dialog, $question, $answer, $form });
}
$answer.focus().select();
$answer.trigger('focus').select();
});
$dialog.on("hidden.bs.modal", () => {
@ -53,7 +53,7 @@ $dialog.on("hidden.bs.modal", () => {
}
});
$form.submit(() => {
$form.on('submit', () => {
resolve($answer.val());
$dialog.modal('hide');

View File

@ -7,7 +7,7 @@ const $passwordInput = $dialog.find(".protected-session-password");
export function show() {
$dialog.modal();
$passwordInput.focus();
$passwordInput.trigger('focus');
}
export function close() {
@ -18,7 +18,7 @@ export function close() {
catch (e) {}
}
$passwordForm.submit(() => {
$passwordForm.on('submit', () => {
const password = $passwordInput.val();
$passwordInput.val("");

View File

@ -137,7 +137,7 @@ $("#switch-to-desktop-button").on('click', () => {
});
$("#log-out-button").on('click', () => {
$("#logout-form").submit();
$("#logout-form").trigger('submit');
});
// this is done so that startNotePath is not used

View File

@ -213,7 +213,7 @@ class Attributes {
$tr.after($new);
$new.find('input').focus();
$new.find('input').trigger('focus');
});
const removeButton = $("<span>")

View File

@ -36,7 +36,7 @@ function showRecentNotes($el) {
$el.setSelectedPath("");
$el.autocomplete("val", "");
$el.focus();
$el.trigger('focus');
}
function initNoteAutocomplete($el, options) {

View File

@ -289,11 +289,14 @@ async function refreshTabs(sourceTabId, noteId) {
}
function focusOnTitle() {
getActiveTabContext().$noteTitle.focus();
getActiveTabContext().$noteTitle.trigger('focus');
}
function focusAndSelectTitle() {
getActiveTabContext().$noteTitle.focus().select();
getActiveTabContext()
.$noteTitle
.trigger('focus')
.trigger('select');
}
/**

View File

@ -25,7 +25,7 @@ class NoteDetailEmpty {
});
noteAutocompleteService.showRecentNotes(this.$autoComplete);
this.$autoComplete.focus();
this.$autoComplete.trigger('focus');
}
show() {}

View File

@ -10,7 +10,7 @@ class NoteDetailProtectedSession {
this.$passwordForm = ctx.$tabContent.find(".protected-session-password-form");
this.$passwordInput = ctx.$tabContent.find(".protected-session-password");
this.$passwordForm.submit(() => {
this.$passwordForm.on('submit', () => {
const password = this.$passwordInput.val();
this.$passwordInput.val("");

View File

@ -110,7 +110,7 @@ class NoteDetailText {
}
focus() {
this.$editorEl.focus();
this.$editorEl.trigger('focus');
}
show() {}

View File

@ -41,7 +41,7 @@ function showSearch() {
}
});
$searchInput.focus();
$searchInput.trigger('focus');
}
function hideSearch() {
@ -75,7 +75,7 @@ async function doSearch(searchText) {
if (searchText.trim().length === 0) {
toastService.showMessage("Please enter search criteria first.");
$searchInput.focus();
$searchInput.trigger('focus');
return;
}
@ -151,7 +151,7 @@ function init() {
}
}
$searchInput.keyup(e => {
$searchInput.on('keyup',e => {
const searchText = $searchInput.val();
if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") {