visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

Use event.composedPath as a fallback in onclick handler #469

Closed dthorne closed 6 years ago

dthorne commented 6 years ago

Before falling back to e.target from e.path use e.composedPath. This allows the onclick handler to work for browsers using ShadyDom AND Polymer 2.

IF I use Polymer 2 and Page.js in FF or Safari then e.path doesn't exist because there is no ShadowDOM. e.target is the Top-most shadow DOM and is therefore not helpful.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 91.429% when pulling 559a1d01755153b22b3ea223b1c77223a32e7455 on dthorne:master into 423c28021724cbf5ef9846a4adf500269de1bfa4 on visionmedia:master.

drewswaycool commented 6 years ago

This would be awesome and save some trouble in such cases.

matthewp commented 6 years ago

Thanks, but page.js is a generated file. Can you make the change in index.js instead?

drewswaycool commented 6 years ago

@matthewp If the change is made to index.js will the generated page.js reflect that change?

paulocoghi commented 6 years ago

@drewswaycool , yes it will reflect :)

dthorne commented 6 years ago

@matthewp Thanks for looking at this. I think it should be good now.

drewswaycool commented 6 years ago

@matthewp any updates?

cecilia-sanare commented 6 years ago

Here's a temporary workaround for anyone who's currently blocked by this issue.

// TODO: Remove this once v1.8.5 of page.js is released!
// Throw this before any page.js logic is invoked.
if (!('path' in Event.prototype)) {
  Object.defineProperty(Event.prototype, 'path', {
    get: function() {
      return this.composedPath ? this.composedPath() : [this.target];
    }
  });
}