Last active
June 10, 2016 14:20
-
-
Save shadyvb/ec9be34de53acb5242a194126bbfd9f9 to your computer and use it in GitHub Desktop.
Fix for the Jetpack gallery exit back button returning to gallery instead of moving back in history
This file contains hidden or 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
(function( $ ) { | |
// This script needs the 'hashchange' event to work | |
if ( 'undefined' === typeof window.onhashchange ) { | |
return; | |
} | |
var historyLengthBeforeGallery = 0; | |
// Catch the first hash change, ie: when the first slide opens | |
jQuery( window ).on( 'hashchange', function() { | |
if ( ! historyLengthBeforeGallery ) { | |
historyLengthBeforeGallery = history.length - 1; // 1 here is the new page recorded on the opening slide | |
} | |
} ); | |
// Restore the history back in time before the gallery's first slide opened | |
jQuery( document ).on( 'jp_carousel.afterClose', function() { | |
history.go( historyLengthBeforeGallery - history.length ) | |
} ); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment