Last active
August 29, 2015 14:06
-
-
Save allanesquina/0d7e35e200a67156e9b1 to your computer and use it in GitHub Desktop.
onpopstate equivalent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dep: jQuery | |
//armazena state | |
var __old = history.state; | |
// checa state | |
setInterval( function() { | |
if( history.state !== __old ) { | |
//triga o evento | |
$( window ).trigger( 'meuevento', [1,3,2] ); | |
// cacheia state atual | |
__old = history.state; | |
} | |
}, 100); | |
// Evento a ser disparado | |
$( window ).on( 'meuevento', function( e ) { | |
console.log( 'disparou ', arguments ); | |
}) | |
// Simula alguns pushstats | |
var stateObj = { foo: "bar1" }; | |
history.pushState( stateObj, "page 2", "http://localhost/teste" ); | |
stateObj = { foo: "bar2" }; | |
history.pushState( stateObj, "page 3", "http://localhost/teste2" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment