Skip to content

Instantly share code, notes, and snippets.

@dhaupin
Created May 18, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaupin/113fcb75b6fa0a7e59b74acb72eab412 to your computer and use it in GitHub Desktop.
Save dhaupin/113fcb75b6fa0a7e59b74acb72eab412 to your computer and use it in GitHub Desktop.
Script - Colorbox initialization with back button support
<script type="text/javascript">
$(document).ready(function() {
$('.colorbox').colorbox({
onLoad: function() {
history.pushState(null, document.title + ' [colorbox-active]', window.location.pathname + window.location.search + '#colorbox-active');
window.onpopstate = function(event) {
$.colorbox.close();
};
},
onClosed: function() {
history.replaceState(null, document.title, window.location.pathname + window.location.search);
},
title: function() {
var kids = $(this).children('img');
if (kids.attr('oldtitle')) {
return kids.attr('oldtitle');
} else if (kids.attr('title')) {
return kids.attr('title');
} else {
return kids.attr('alt');
}
},
overlayClose: true,
opacity: 0.5,
rel: "colorbox",
maxWidth: '100%',
maxHeight: '90%'
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment