sammy icon indicating copy to clipboard operation
sammy copied to clipboard

DefaultApplicationProxy silent option would be nice

Open rayoub opened this issue 11 years ago • 1 comments

I think it would be nice to incorporate updating the url silently in Sammy since it already does the work of detecting HTML5 history api present or not. This is what I did. If history api is supported and you pass true for silent it will not trigger events and back buttons will work nicely. This is for updating of grid during paging and sorting and when you click to go to a detail page you want to come back to your same page. Using durandal.

// set the current location to `new_location`
setLocation: function(new_location, silent) {
    if (/^([^#\/]|$)/.test(new_location)) { // non-prefixed url
        if (_has_history && !this.app.disable_push_state) {
            new_location = '/' + new_location;
        } else {
            new_location = '#!/' + new_location;
        }
    }
    if (new_location != this.getLocation()) {
        // HTML5 History exists and new_location is a full path
        if (_has_history && !this.app.disable_push_state && /^\//.test(new_location)) {
            if (!silent) {
                history.pushState({ path: new_location }, window.title, new_location);
                this.app.trigger('location-changed');
            }
            else {
                history.pushState(null, null, new_location);
            }
        } else {
            return (window.location = new_location);
        }
    }
},

rayoub avatar May 31 '13 14:05 rayoub

+1 Not being able to silence URL changes has led to me searching for alternatives to Sammy.

rockerest avatar Apr 24 '15 15:04 rockerest