Skip to content

Instantly share code, notes, and snippets.

@chrisblakley
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisblakley/e9c387e7f40a2a929ab2 to your computer and use it in GitHub Desktop.
Save chrisblakley/e9c387e7f40a2a929ab2 to your computer and use it in GitHub Desktop.
Close a mmenu using the back button with the History API and popstate
jQuery("#mmenu").mmenu({
/* Options Here */
}, {
/* Configuration Here */
}).on('opened.mm', function(){
history.replaceState(null, document.title, location);
history.pushState(null, document.title, location);
});
//Close mmenu on back button click
if (window.history && window.history.pushState) {
window.addEventListener("popstate", function(e) {
if ( jQuery('html.mm-opened').is('*') ) {
jQuery(".mm-menu").trigger("close.mm");
e.stopPropagation();
}
}, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment