Remove hash when closing a method container again. Added small hash helper functions.

This commit is contained in:
Marco Jantke 2014-05-18 01:24:52 +02:00
parent 968a162544
commit df7be182cd

View File

@ -51,8 +51,32 @@
</p> </p>
<script type="text/javascript"> <script type="text/javascript">
var getHash = function() {
return window.location.hash || '';
};
var setHash = function(hash) {
window.location.hash = hash;
};
var clearHash = function() {
var scrollTop, scrollLeft;
if(typeof history === 'object' && typeof history.pushState === 'function') {
history.replaceState('', document.title, window.location.pathname + window.location.search);
} else {
scrollTop = document.body.scrollTop;
scrollLeft = document.body.scrollLeft;
setHash('');
document.body.scrollTop = scrollTop;
document.body.scrollLeft = scrollLeft;
}
};
$(window).load(function() { $(window).load(function() {
var id = (window.location.hash || '').substr(1).replace( /([:\.\[\]\{\}])/g, "\\$1"); var id = getHash().substr(1).replace( /([:\.\[\]\{\}])/g, "\\$1");
var elem = $('#' + id); var elem = $('#' + id);
if (elem.length) { if (elem.length) {
setTimeout(function() { setTimeout(function() {
@ -62,8 +86,17 @@
} }
}); });
$('.toggler').click(function() { $('.toggler').click(function(event) {
$(this).next().slideToggle('fast'); var contentContainer = $(this).next();
if(contentContainer.is(':visible')) {
clearHash();
} else {
setHash($(this).attr('href'));
}
contentContainer.slideToggle('fast');
return false;
}); });
{% if enableSandbox %} {% if enableSandbox %}