Page 1 of 3
how to jump to #unread anchor
Posted: Thu Nov 19, 2020 9:33 am
by zawin
Hello,
in received email it is following link, which points to the last unread post: /Forum/viewtopic.php?f=5&t=1&e=1&view=unread#unread
It is possible to jump to the anchor #unread, after page with this link is loaded?
Thank you.
Re: how to jump to #unread anchor
Posted: Thu Nov 19, 2020 11:10 am
by axew3
yes, you read on my mind thank you for report, known problem.
FIXED
V6 will fix this, and any redirected link like these (as well any other):
Code: Select all
https://www.phpbb.com/community/viewtopic.php?f=496&t=2554596&e=1&view=unread#unread
added on queue into this thread
https://www.axew3.com/w3/forums/viewtop ... f=2&t=1585
where V5 code has been also reported to be patched to fix something else in the while.
I will check to fix on fly if i can find out a moment, even before V6
Re: how to jump to #unread anchor
Posted: Sat Nov 21, 2020 12:30 am
by axew3
The V5 overall_footer.html code has been updated to resolve this issue:
https://www.axew3.com/w3/2020/01/phpbb- ... iframe-v5/
To fix:
on added
overall_footer.html js code, find this line:
Code: Select all
var hash = window.location.hash.substr(1);
immediately after, add this:
Code: Select all
if( hash == 'unread' ){
var postN = 1;
$( "h3 > a" ).each(function (e) { // need to match on DOM
ns = this.href.split('#p');
if( typeof ns != 'undefined' && /viewtopic.php\?p=/ig.exec(this.href) != null ){
if(ns[1] > postN){
w3lh = ns[1];
}
}
})
if( typeof w3lh != 'undefined' ){
hash = "p" + w3lh;
}
}
remember to recompile phpBB template.
Note that the code search for
h3 elements, containing
a elements, than containing strings like this
viewtopic.php?p=
so on theme DOM, the posts titles links, needs to exists wrapped like they are into default subsilver, or this line:
$( "h3 > a" ).each(function (e) {
need to change selectors to match on DOM correct post's a links.
Work fine into all themes where post's links a elements are inside an h3 element, like it is on prosilver, but into all themes?
In case as said, the line of code that search for elements on DOM need to be changed to match.
Do not know if there is another way than this to achieve and resolve. I do not think that there is, at moment.
Re: how to jump to #unread anchor
Posted: Tue Nov 24, 2020 7:23 am
by zawin
Hello,
I can confirm that code works. I changed selector based on my page structure. Thank you
Re: how to jump to #unread anchor
Posted: Sat Nov 28, 2020 10:08 am
by zawin
Hello,
I found problem with this code - If I click to URL with #unread anchor, then page jumps to the latest post instead of the latest unread post.
Re: how to jump to #unread anchor
Posted: Sat Nov 28, 2020 10:15 am
by axew3
It scroll to last post, but should instead scroll to, the last unread post, which could be not the last one inserted on thread, when there are more new replies? Do not know how it work, not checked deeply in true, so i will check asap how phpBB execute this task, and how to mimic it.
P.s i see it exist a template S_LOAD_UNREADS var which
so i assume it is the easy and correct way to accomplish with this
mh... just checked, no it is not the way ... let see asap more deeply
p.s
and on fly, i see that could be possible checking for class unreadpost, so the above code need to be little changed to achieve correctly the result