scripting / feedlandBlogrollToolkit

Browser-based JavaScript code, html and styles for adding an OPML-based blogroll to a website, with a connection back to FeedLand for realtime updates.
MIT License
3 stars 0 forks source link

Popup menu scrolling not wanted #8

Open scripting opened 5 months ago

scripting commented 5 months ago

I did a video demo of this problem. Has nothing to do with any particular site.

https://www.youtube.com/shorts/iUGJJyANBR8

This is relatively new behavior. Something I did must have broken it..

Any ideas welcome. ;-)

NickGreen commented 5 months ago

I believe this is because the anchor is written like this: <a class="dropdown-toggle" href="#"

Since hashtags are also used as anchors, it jumps so the top of the viewport goes to that anchor. There are a couple of ways to handle it. One would be to use a button instead of an anchor tag, which would probably be more in line with JavaScript best practices.

The quicker solution would be to write your anchor tag like this: <a class="dropdown-toggle" href="javascript:void(0);"

This should prevent it from jumping. Let me know if it doesn't, and I can research further.

scripting commented 5 months ago

Thanks for the idea -- I did it the easy way, replacing the # with javascript:void(0); but no luck. It still scrolls to the top when you click it.

When you say use a button, not sure what means. Changing the <a> to a <button>?

scripting commented 5 months ago

I checked with ChatGPT and it offered similar advice. Oy. (See the second suggestion.)

I'm going to try the first one, see if it works.

scripting commented 5 months ago

I tried switching it to a button too (pretty straightforward) and it still scrolled to the top.

Theory: Some other code is catching the click and scrolling to the top. (Haven't had a chance yet to fully explore this.)

Right now this is not a super high priority, so I'm going to go look at some other problems and see if I can figure them out.

NickGreen commented 5 months ago

Hm. I'm surprised that's not working for you. I tried it locally, and it seemed to work 🤔

One thing I've done in the past also is to add preventDefault to the click event script.

For example:

$('a.someclass').click(function(e) {
    e.preventDefault();
});

Oh ha. I see that ChatGPT beat me to it 😆

scripting commented 5 months ago

We'll figure this one out, esp since you had it working there. I was probably making some mistake.

scripting commented 5 months ago

BTW, this bug isn't holding us back. The one I really want to understand is the underlining that isn't underlining (in the previous issue).