Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #20638 -- Scroll a bit further for internal anchor links.

  • Loading branch information...
commit 0d94386218c757892f9b228e764f1696802fe8d7 1 parent 50bfb57
@jezdez jezdez authored
View
2  django_docs/settings.py
@@ -47,6 +47,8 @@
USE_I18N = True
LANGUAGE_CODE = 'en'
+STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
+
### Docs settings
if PRODUCTION:
View
41 docs/templates/docs/doc.html
@@ -6,7 +6,7 @@
{% block extrabody %}
{% if version == 'dev' %}
- <div class="dev-warning">
+ <div id="dev-warning">
{% trans "This document is for Django's development version, which can be significantly different from previous releases. Use the version selector in the bottom right corner for older releases." %}
</div>
<style type="text/css" media="screen">
@@ -14,6 +14,45 @@
margin-top: 2em;
}
</style>
+ <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
+ <script>
+ {% comment %}
+ Here we are doing something really annoying, we catch clicks on
+ internal anchors and scroll to the right place of the page.
+ This is only needed because we want to show the developement version
+ warning on top.
+ {% endcomment %}
+ $(document).ready(function(){
+ // First handle the case in which someone clicks on a link
+ $('a[href*=#]').click(function(event) {
+ // check to see if this is an internal link, sigh.
+ if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
+ && location.hostname == this.hostname) {
+ // get the link target, use the weird id= query since it escapes dots
+ var target = $("[id='" + this.hash.slice(1) + "']");
+ // calculate the offset
+ var targetOffset = target.offset().top - $('#dev-warning').height() - 20;
+ // scroll to the place, there is probably a better way
+ setTimeout(function() {
+ $('html,body').scrollTop(targetOffset);
+ }, 50);
+ }
+ });
+ // this is the janky thing, there is probably a better way
+ setTimeout(function() {
+ // is there a hash in the current window's location?
+ if (window.location.hash) {
+ // again, get the target
+ var target = $("[id='" + window.location.hash.slice(1) + "']");
+ // calculate the offset
+ var targetOffset = target.offset().top - $('#dev-warning').height() - 20;
+ // scroll to the place
+ $('html,body').scrollTop(targetOffset);
+ }
+ // use a delay that should work on all modern computers. should, not will.
+ }, 50);
+ });
+ </script>
{% endif %}
{% endblock extrabody %}
View
2  static/css/base.css
@@ -531,7 +531,7 @@ div.admonition.warning {
padding: 5px;
}
-.dev-warning {
+#dev-warning {
position:fixed;
top: 0;
width: 100%;

0 comments on commit 0d94386

Please sign in to comment.
Something went wrong with that request. Please try again.