itkach / aard2-web

Mozilla Public License 2.0
70 stars 15 forks source link

search word on double-click + persist page state via URL hash #17

Open glowinthedark opened 1 year ago

glowinthedark commented 1 year ago
  1. Store current dictionary and lookup word in the top page URL hash to allow persisting state on page refresh.

Allows reopening a specific article with the lookup word via a top frame URL like

With this change clicking refresh in the browser will allow the page state to survive, and the original search and definition to be shown rather than a reset to original empty state. Moreover, this allows bookmarking definitions in a specific dictionary.

  1. Double-clicking a word in the content frame initiates a lookup and opening 1st result in the content frame and searching the double-clicked word in the current dictionary.

  2. After a lookup open first entry in content frame

glowinthedark commented 1 year ago

@itkach let me know if you think it's an issue and if you think the two points addressed by this PR must go separately

regarding double-clicking on a word: currently this will open the double-clicked word in the 1st dictionary that appears in search (if any); do you think it might make sense to have double-click trigger a lookup in the same dictionary rather than the first one in the list?

Update: doubleclick action has been updated to emulate a link click in the current dictionary only — this imo is a more expected behaviour and also does not require setting directly the iframe content src as it was done in the original commit 7a842db949ae42b04d567aeb69fe553752844e80


Update 2: this change is messing up the history and back/forward don't work as expected, given that with frames the page has two histories: top-level history and the frame's own history; updating the URL hash apparently triggers a history push state for the top frame and this messes up the back/forward behaviour, given that with an unchanged top-frame history the history buttons act on the nested frame history rather than top-frame

not clear what would be the best approach to have the history working properly, apart from getting rid of frames entirely and use instead a DIV for rendering content.