mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	mobile web fixes
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| import server from "./server.js"; | ||||
| import noteDetailService from "./note_detail.js"; | ||||
| import treeService from './tree.js'; | ||||
| import utils from './utils.js'; | ||||
|  | ||||
| // this key needs to have this value so it's hit by the tooltip | ||||
| const SELECTED_PATH_KEY = "data-note-path"; | ||||
| @@ -21,84 +21,94 @@ async function autocompleteSource(term, cb) { | ||||
| } | ||||
|  | ||||
| function clearText($el) { | ||||
|     if (utils.isMobile()) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     $el.setSelectedPath(""); | ||||
|     $el.autocomplete("val", "").change(); | ||||
| } | ||||
|  | ||||
| function showRecentNotes($el) { | ||||
|     if (utils.isMobile()) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     $el.setSelectedPath(""); | ||||
|     $el.autocomplete("val", ""); | ||||
|     $el.focus(); | ||||
| } | ||||
|  | ||||
| function initNoteAutocomplete($el, options) { | ||||
|     if (!$el.hasClass("note-autocomplete-input")) { | ||||
|         options = options || {}; | ||||
|  | ||||
|         $el.addClass("note-autocomplete-input"); | ||||
|  | ||||
|         const $clearTextButton = $("<a>") | ||||
|                 .addClass("input-group-text input-clearer-button jam jam-close") | ||||
|                 .prop("title", "Clear text field"); | ||||
|  | ||||
|         const $showRecentNotesButton = $("<a>") | ||||
|                 .addClass("input-group-text show-recent-notes-button jam jam-clock") | ||||
|                 .prop("title", "Show recent notes"); | ||||
|  | ||||
|         const $goToSelectedNoteButton = $("<a>") | ||||
|             .addClass("input-group-text go-to-selected-note-button jam jam-arrow-right") | ||||
|             .attr("data-action", "note"); | ||||
|  | ||||
|         const $sideButtons = $("<div>") | ||||
|             .addClass("input-group-append") | ||||
|             .append($clearTextButton) | ||||
|             .append($showRecentNotesButton); | ||||
|  | ||||
|         if (!options.hideGoToSelectedNoteButton) { | ||||
|             $sideButtons.append($goToSelectedNoteButton); | ||||
|         } | ||||
|  | ||||
|         $el.after($sideButtons); | ||||
|  | ||||
|         $clearTextButton.click(() => clearText($el)); | ||||
|  | ||||
|         $showRecentNotesButton.click(e => { | ||||
|             showRecentNotes($el); | ||||
|  | ||||
|             // this will cause the click not give focus to the "show recent notes" button | ||||
|             // this is important because otherwise input will lose focus immediatelly and not show the results | ||||
|             return false; | ||||
|         }); | ||||
|  | ||||
|         $el.autocomplete({ | ||||
|             appendTo: document.querySelector('body'), | ||||
|             hint: false, | ||||
|             autoselect: true, | ||||
|             openOnFocus: true, | ||||
|             minLength: 0, | ||||
|             tabAutocomplete: false | ||||
|         }, [ | ||||
|             { | ||||
|                 source: autocompleteSource, | ||||
|                 displayKey: 'title', | ||||
|                 templates: { | ||||
|                     suggestion: function(suggestion) { | ||||
|                         return suggestion.highlighted; | ||||
|                     } | ||||
|                 }, | ||||
|                 // we can't cache identical searches because notes can be created / renamed, new recent notes can be added | ||||
|                 cache: false | ||||
|             } | ||||
|         ]); | ||||
|  | ||||
|         $el.on('autocomplete:selected', (event, suggestion) => $el.setSelectedPath(suggestion.path)); | ||||
|         $el.on('autocomplete:closed', () => { | ||||
|             if (!$el.val().trim()) { | ||||
|                 clearText($el); | ||||
|             } | ||||
|         }); | ||||
|     if ($el.hasClass("note-autocomplete-input") || utils.isMobile()) { | ||||
|         return $el; | ||||
|     } | ||||
|  | ||||
|     options = options || {}; | ||||
|  | ||||
|     $el.addClass("note-autocomplete-input"); | ||||
|  | ||||
|     const $clearTextButton = $("<a>") | ||||
|             .addClass("input-group-text input-clearer-button jam jam-close") | ||||
|             .prop("title", "Clear text field"); | ||||
|  | ||||
|     const $showRecentNotesButton = $("<a>") | ||||
|             .addClass("input-group-text show-recent-notes-button jam jam-clock") | ||||
|             .prop("title", "Show recent notes"); | ||||
|  | ||||
|     const $goToSelectedNoteButton = $("<a>") | ||||
|         .addClass("input-group-text go-to-selected-note-button jam jam-arrow-right") | ||||
|         .attr("data-action", "note"); | ||||
|  | ||||
|     const $sideButtons = $("<div>") | ||||
|         .addClass("input-group-append") | ||||
|         .append($clearTextButton) | ||||
|         .append($showRecentNotesButton); | ||||
|  | ||||
|     if (!options.hideGoToSelectedNoteButton) { | ||||
|         $sideButtons.append($goToSelectedNoteButton); | ||||
|     } | ||||
|  | ||||
|     $el.after($sideButtons); | ||||
|  | ||||
|     $clearTextButton.click(() => clearText($el)); | ||||
|  | ||||
|     $showRecentNotesButton.click(e => { | ||||
|         showRecentNotes($el); | ||||
|  | ||||
|         // this will cause the click not give focus to the "show recent notes" button | ||||
|         // this is important because otherwise input will lose focus immediatelly and not show the results | ||||
|         return false; | ||||
|     }); | ||||
|  | ||||
|     $el.autocomplete({ | ||||
|         appendTo: document.querySelector('body'), | ||||
|         hint: false, | ||||
|         autoselect: true, | ||||
|         openOnFocus: true, | ||||
|         minLength: 0, | ||||
|         tabAutocomplete: false | ||||
|     }, [ | ||||
|         { | ||||
|             source: autocompleteSource, | ||||
|             displayKey: 'title', | ||||
|             templates: { | ||||
|                 suggestion: function(suggestion) { | ||||
|                     return suggestion.highlighted; | ||||
|                 } | ||||
|             }, | ||||
|             // we can't cache identical searches because notes can be created / renamed, new recent notes can be added | ||||
|             cache: false | ||||
|         } | ||||
|     ]); | ||||
|  | ||||
|     $el.on('autocomplete:selected', (event, suggestion) => $el.setSelectedPath(suggestion.path)); | ||||
|     $el.on('autocomplete:closed', () => { | ||||
|         if (!$el.val().trim()) { | ||||
|             clearText($el); | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     return $el; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user