Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could be a possible to add navigation/links toggle? #90

Open
croban opened this issue Sep 12, 2021 · 4 comments
Open

Could be a possible to add navigation/links toggle? #90

croban opened this issue Sep 12, 2021 · 4 comments

Comments

@croban
Copy link

croban commented Sep 12, 2021

Basically at the moment all click events will be intercepted by tinro, except those with ignore attr.
It would be great if this could be turned off or defined only for links below an css selectors (e.g. id, class etc.)
e.g. closest(".app-widget a[href]")

@AlexxNB
Copy link
Owner

AlexxNB commented Sep 16, 2021

Globally turn off links handling except marked ones? Something like this:

<script>
   import {router} from 'tinro';
   router.handleLinks(false);
</script>

<a href="/foo/bar">Won't be handled by tinro</a>
<a href="/bar/foo" tinro>Will be handled by tinro</a>

@croban
Copy link
Author

croban commented Sep 16, 2021

I was thinking more something like this snippet bellow, because widget is injected inside external pages and I don't have any access to those.

<html ...>
<body>
...
<a href="/foo/bar">Won't be handled by tinro</a>
<a href="/bar/foo2">Won't be handled by tinro</a>
...
<div id="#sveltewidget"><!-- container for widget  --></div>
<script href=sveltewidgetapp.js" />
... 
</body>
//widgetapp.svelte

<script>
   import {router} from 'tinro';
   router.handleLinks("#sveltewidget"); <- handle only links below this node
</script>

<a href="/widget/bar">Will be handled by tinro</a>
<a href="/widget/foo">Will be handled by tinro</a>

@AlexxNB
Copy link
Owner

AlexxNB commented Sep 17, 2021

I got this idea but it doesn't solve a problem in all cases. Creator of widget may not know which id will have a container for widget. Or there may be two or more widgets on a page with independent links and routes.

Best solution is to have a reference for the root element(to check if the link is its child) right in Svelte context, but I don't know a way to get it.

Right now, best solution seems to turn off handling of all links on a page, except ones marked by creator in the widget.

@mgrubinger
Copy link

mgrubinger commented Aug 26, 2022

Are there plans to implement .handleLinks() in one way or another?
The fact that tinro listens to all clicks, even on links outside of the svelte apps root is a deal-breaker for us, as we try to embed a tinro-routed svelte app into a much larger application.

I'm happy to draft a PR if you want. It seems the (window.)addEventListener in https://github.com/AlexxNB/tinro/blob/master/src/router.js#L79 would be a good starting point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants