Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 0d94386218c757892f9b228e764f1696802fe8d7 1 parent 50bfb57
Jannis Leidel authored June 21, 2013
2  django_docs/settings.py
@@ -47,6 +47,8 @@
47 47
 USE_I18N = True
48 48
 LANGUAGE_CODE = 'en'
49 49
 
  50
+STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
  51
+
50 52
 ### Docs settings
51 53
 
52 54
 if PRODUCTION:
41  docs/templates/docs/doc.html
@@ -6,7 +6,7 @@
6 6
 
7 7
 {% block extrabody %}
8 8
 {% if version == 'dev' %}
9  
-  <div class="dev-warning">
  9
+  <div id="dev-warning">
10 10
    {% 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." %}
11 11
   </div>
12 12
   <style type="text/css" media="screen">
@@ -14,6 +14,45 @@
14 14
     margin-top: 2em;
15 15
   }
16 16
   </style>
  17
+  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  18
+  <script>
  19
+  {% comment %}
  20
+  Here we are doing something really annoying, we catch clicks on
  21
+  internal anchors and scroll to the right place of the page.
  22
+  This is only needed because we want to show the developement version
  23
+  warning on top.
  24
+  {% endcomment %}
  25
+  $(document).ready(function(){
  26
+    // First handle the case in which someone clicks on a link
  27
+    $('a[href*=#]').click(function(event) {
  28
+      // check to see if this is an internal link, sigh.
  29
+      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
  30
+          && location.hostname == this.hostname) {
  31
+        // get the link target, use the weird id= query since it escapes dots
  32
+        var target = $("[id='" + this.hash.slice(1) + "']");
  33
+        // calculate the offset
  34
+        var targetOffset = target.offset().top - $('#dev-warning').height() - 20;
  35
+        // scroll to the place, there is probably a better way
  36
+        setTimeout(function() {
  37
+          $('html,body').scrollTop(targetOffset);
  38
+        }, 50);
  39
+      }
  40
+    });
  41
+    // this is the janky thing, there is probably a better way
  42
+    setTimeout(function() {
  43
+      // is there a hash in the current window's location?
  44
+      if (window.location.hash) {
  45
+        // again, get the target
  46
+        var target = $("[id='" + window.location.hash.slice(1) + "']");
  47
+        // calculate the offset
  48
+        var targetOffset = target.offset().top - $('#dev-warning').height() - 20;
  49
+        // scroll to the place
  50
+        $('html,body').scrollTop(targetOffset);
  51
+      }
  52
+    // use a delay that should work on all modern computers. should, not will.
  53
+    }, 50);
  54
+  });
  55
+  </script>
17 56
   {% endif %}
18 57
 {% endblock extrabody %}
19 58
 
2  static/css/base.css
@@ -531,7 +531,7 @@ div.admonition.warning {
531 531
     padding: 5px;
532 532
 }
533 533
 
534  
-.dev-warning {
  534
+#dev-warning {
535 535
   position:fixed;
536 536
   top: 0;
537 537
   width: 100%;

0 notes on commit 0d94386

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