history.js icon indicating copy to clipboard operation
history.js copied to clipboard

Need to call stopImmediatePropagation() on popstate event

Open ataraxie opened this issue 10 years ago • 0 comments

I'm using History.js in an add-on for Atlassian Confluence. We have an environmental problem with the popstate event and we need to call event.immediatePropagation() on that popstate event. The internal handler is this:

History.onPopState = function(event,extra){...}

Unfortunately, outside of History.js I have no access to that event and I cannot call the method on it. Instead, a new event 'statechange' is triggered:

History.Adapter.trigger(window,'statechange')

In my listener, I have now only the statechange event available and not the popstate event (which causes the misbehaviour in my environment):

History.Adapter.bind(window, 'statechange', function(event) {
    // event is the statechange event and I have no access to the popstate event
});

I worked around this issue in my history code by passing the popstate event as parameter in the trigger call:

History.Adapter.trigger(window,'statechange',{popstateEvent: event})

Then I can do this in my listener:

History.Adapter.bind(window, 'statechange', function(event, data) {
    data.popstateEvent.stopImmediatePropagation();
});

Of course this is no desired solution to "patch" library code for my needs. Maybe you would consider this a useful edit? Or maybe you have a better solution for my problem in mind?

ataraxie avatar Aug 10 '15 10:08 ataraxie