Giter Club home page Giter Club logo

Comments (6)

jostsg avatar jostsg commented on June 29, 2024

I'd find this very useful too.

We have the situation, where we allow links to open in a lightbox, but still change the URL. We do that with a special target tag. The easiest for our case would certainly be to have access to the dom element.

However that should probably not be the responsibility of page.js. Still I would like to be able to access the contents of that target attribute in my middlewares. One solution I can think of is to be able to manipulate the context when calling #page() inside my own click handler.

I was going to suggest to implement that. But it turns out, that something similar exists. You can prevent #start() from calling #replace() and then call #replace() yourself and pass a state object like so:

page.start( { dispatch: false } );
page.replace( location.pathname + location.search, { target: "#selector" }, true, true );

Thats for starting, after that you can just use #show().

// inside your click handler
page.show( $this.attr( "href" ),  { target: $this.attr( "data-target" ) } );

Just ignore that I assume jQuery ;) the idea stays the same.

from page.js.

rauchg avatar rauchg commented on June 29, 2024

The reference wouldn't be bad, but I am of the opinion that page shouldn't do any delegation at all, and that should be a separate component.

from page.js.

tj avatar tj commented on June 29, 2024

it seemed relatively non-leaky at the time but we're investigating better patterns for client-side routing, there's definitely a few gotchas/annoyances with page.js ATM

from page.js.

rauchg avatar rauchg commented on June 29, 2024

Although having links that automatically trigger pushState and a page() handler IS indeed very useful and I'd say covers a large percentage of use cases, so the functionality somehow needs to stay, maybe slightly different impl

from page.js.

tj avatar tj commented on June 29, 2024

it's stil pretty easy to do the inverse and .preventDefault() to disable page.js for links, the 80% use-case would be to dispatch so that still kinda works

from page.js.

tj avatar tj commented on June 29, 2024

we could always have some data-page sort of thing to opt-in/out depending on what the default is. I'm using target="_self" as a hack right now to bypass page haha

from page.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.