Created
May 18, 2017 15:04
-
-
Save dhaupin/113fcb75b6fa0a7e59b74acb72eab412 to your computer and use it in GitHub Desktop.
Script - Colorbox initialization with back button support
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
<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