From 1d0e96a314ee78526189af6c80f0539119f466fd Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 4 Nov 2017 13:59:43 -0400 Subject: [PATCH] converted jump to note to module --- public/javascripts/jump_to_note.js | 56 ++++++++++++++++++------------ views/index.ejs | 2 +- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/public/javascripts/jump_to_note.js b/public/javascripts/jump_to_note.js index 188649214..47056bf80 100644 --- a/public/javascripts/jump_to_note.js +++ b/public/javascripts/jump_to_note.js @@ -1,28 +1,38 @@ -function showJumpToNote() { - $("#jump-to-note-autocomplete").val(''); +const jumpToNote = (function() { + const dialogEl = $("#jump-to-note-dialog"); + const autoCompleteEl = $("#jump-to-note-autocomplete"); + const formEl = $("#jump-to-note-form"); - $("#jump-to-note-dialog").dialog({ - modal: true, - width: 800 - }); + function showDialog() { + autoCompleteEl.val(''); - $("#jump-to-note-autocomplete").autocomplete({ - source: getAutocompleteItems(glob.allNoteIds), - minLength: 0 - }); -} + dialogEl.dialog({ + modal: true, + width: 800 + }); -$(document).bind('keydown', 'alt+j', showJumpToNote); - -$("#jump-to-note-form").submit(() => { - const val = $("#jump-to-note-autocomplete").val(); - const noteId = getNodeIdFromLabel(val); - - if (noteId) { - getNodeByKey(noteId).setActive(); - - $("#jump-to-note-dialog").dialog('close'); + autoCompleteEl.autocomplete({ + source: getAutocompleteItems(glob.allNoteIds), + minLength: 0 + }); } - return false; -}); \ No newline at end of file + $(document).bind('keydown', 'alt+j', showDialog); + + formEl.submit(() => { + const val = autoCompleteEl.val(); + const noteId = getNodeIdFromLabel(val); + + if (noteId) { + getNodeByKey(noteId).setActive(); + + dialogEl.dialog('close'); + } + + return false; + }); + + return { + showDialog + }; +})(); \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index a520f6f30..241719ef7 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -14,7 +14,7 @@
- +