Suppressed the auto-scrolling on click and fixed initial-jump issues.

For the initial auto-scrolling to the selected route in location.hash:
 - Fixed typo in the calculation of the offset-top position.
 - Fixed requesting the selected route that has special chars (e.g. "/content/{page}")
 - Fixed for refreshes with F5. It needs a setTimeout workaround to get that working in Webkit.
    It needs also in Firefox a other dom element to fire scrollTop at.

Fixed also some old .delegation calls, which are deprecated in jQuery 1.7.

Why suppressing auto-scrolling on click:
When clicking through all methods it's very annoying when the browser always jumps to the clicked method,
especially when you go through all methods from bottom to up. This jump is unexpected and disturbing.
This commit is contained in:
Marc J. Schmidt 2013-12-09 18:01:31 +01:00
parent 21a0774265
commit d7ef725613

View File

@ -49,10 +49,13 @@
</p> </p>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(window).load(function() {
var elem = $(window.location.hash); var id = (window.location.hash || '').substr(1).replace( /([:\.\[\]\{\}])/g, "\\$1");
if(elem) { var elem = $('#' + id);
$('body').scrollTop(elem.top); if (elem.length) {
setTimeout(function() {
$('body,html').scrollTop(elem.position().top);
});
elem.find('a.toggler').click(); elem.find('a.toggler').click();
} }
}); });
@ -295,19 +298,26 @@
return false; return false;
}); });
$('.pane.sandbox').delegate('.to-raw', 'click', function(e) { $('.operations').on('click', '.operation > a', function(e) {
if (history.pushState) {
history.pushState(null, null, $(this).attr('href'));
e.preventDefault();
}
});
$('.pane.sandbox').on('click', '.to-raw', function(e) {
renderRawBody($(this).parents('.pane').find('.response')); renderRawBody($(this).parents('.pane').find('.response'));
e.preventDefault(); e.preventDefault();
}); });
$('.pane.sandbox').delegate('.to-prettify', 'click', function(e) { $('.pane.sandbox').on('click', '.to-prettify', function(e) {
renderPrettifiedBody($(this).parents('.pane').find('.response')); renderPrettifiedBody($(this).parents('.pane').find('.response'));
e.preventDefault(); e.preventDefault();
}); });
$('.pane.sandbox').delegate('.to-expand, .to-shrink', 'click', function(e) { $('.pane.sandbox').on('click', '.to-expand, .to-shrink', function(e) {
var $headers = $(this).parents('.result').find('.headers'); var $headers = $(this).parents('.result').find('.headers');
var $label = $(this).parents('.result').find('a.to-expand'); var $label = $(this).parents('.result').find('a.to-expand');