mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 16:41:39 +00:00
added scroll position to nav history...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
7b78b5133a
commit
77e9f0819e
35
pwiki2.html
35
pwiki2.html
@ -375,6 +375,29 @@ require(['./browser'], function(browser){
|
||||
// NOTE: this seems not to work if the REFRESH_DELAY is too small...
|
||||
setTimeout(function(){
|
||||
pwiki.location = [path, hash] }, REFRESH_DELAY) })
|
||||
|
||||
// scroll...
|
||||
// NOTE: we restore scroll position only on history navigation...
|
||||
var save_scroll = function(){
|
||||
history.replaceState(
|
||||
{
|
||||
path: pwiki.location,
|
||||
// XXX HACK this will work only on full page...
|
||||
scroll: document.scrollingElement.scrollTop,
|
||||
},
|
||||
'',
|
||||
// XXX
|
||||
window.location.hash) }
|
||||
// save scroll position just after scroll is done...
|
||||
var scrolling
|
||||
window.addEventListener('scroll', function(evt){
|
||||
scrolling
|
||||
&& clearTimeout(scrolling)
|
||||
scrolling = setTimeout(save_scroll, 200) })
|
||||
// get scroll position from history state...
|
||||
window.addEventListener('popstate', function(evt){
|
||||
pwiki.__scroll = (evt.state ?? {}).scroll })
|
||||
|
||||
pwiki
|
||||
.onBeforeNavigate(function(){
|
||||
saveAll() })
|
||||
@ -382,7 +405,7 @@ require(['./browser'], function(browser){
|
||||
// NOTE: we do not need to directly update location.hash here as
|
||||
// that will push an extra history item...
|
||||
history.replaceState(
|
||||
{path: this.location},
|
||||
{ path: this.location },
|
||||
'',
|
||||
'#'+this.location
|
||||
+(this.hash ?
|
||||
@ -416,11 +439,15 @@ require(['./browser'], function(browser){
|
||||
`${titles.length > 1 ?
|
||||
titles.at(-1).innerText
|
||||
: this.title} — pWiki`
|
||||
// scroll to anchor element...
|
||||
this.hash
|
||||
&& this.dom
|
||||
// scroll...
|
||||
this.hash ?
|
||||
// to anchor element...
|
||||
this.dom
|
||||
.querySelector('#'+ this.hash)
|
||||
.scrollIntoView()
|
||||
// restore history position...
|
||||
// XXX HACK this will work only on full page...
|
||||
: (document.scrollingElement.scrollTop = this.__scroll ?? 0)
|
||||
|
||||
// XXX MediumEditor...
|
||||
//setupMediumEditor()
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
* -
|
||||
*
|
||||
*
|
||||
* XXX load new page at .scrollTop = 0 if no anchors are given...
|
||||
* ...and/or remember scroll position per page...
|
||||
* XXX sort: define a generic sort path argument...
|
||||
* ...this will unify all interfaces (macros/patterns/etc)
|
||||
* XXX macros: else/default macro args essentially mean the same thing, should we
|
||||
@ -51,6 +49,10 @@
|
||||
* await pwiki.parse('<macro src=../tags join=", ">@source(.)</macro>')
|
||||
* This will not:
|
||||
* await pwiki.parse('<macro src="../tags" join=", ">@source(.)</macro>')
|
||||
* XXX FEATURE: make the pwiki "widget" work bot as an element and as a
|
||||
* full page (current)...
|
||||
* ...would need to handle stuff like history, url, nav locally...
|
||||
* see: pwiki2.html
|
||||
* XXX ASAP test: can we store the file handler with permissions in a ServiceWorker??
|
||||
* XXX macros: Q: do we need macros for printing errors and the like???
|
||||
* XXX the parser should handle all action return values, including:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user