hg site extension
 
(Arne Babenhauserheide)
2014-02-09: include sjl.js (steve loshs sidebar-title-javascript

include sjl.js (steve loshs sidebar-title-javascript

diff --git a/sjl.js b/sjl.js
new file mode 100644
--- /dev/null
+++ b/sjl.js
@@ -0,0 +1,56 @@
+var h2s = null;
+
+function place_scrolly_header () {
+    var soff = 75;
+
+    var y = $(window).scrollTop();
+
+    var target_content = null;
+    var opacity = null;
+    var header_y = null;
+    h2s.each(function() {
+        var pre_header_y = $(this).position()['top'] - soff;
+        if (y < pre_header_y) {
+            return false;
+        };
+        header_y = pre_header_y;
+
+        target_content = $(this).html().replace(/ /g, ' ');
+
+        var opacity_y = y - (header_y + soff);
+        opacity = opacity_y / soff;
+        if (opacity > 1.0) {
+            opacity = 1.0;
+        }
+
+        if (opacity > 0.99) {
+            var next_headers = $(this).nextAll('h2');
+            if (next_headers.length) {
+                var next_header_y = next_headers.first().position()['top'];
+                var next_header_distance = next_header_y - y;
+                if (next_header_distance <= soff*2) {
+                    opacity = 1.0 / (soff - next_header_distance/2);
+                };
+            }
+        }
+    });
+    $('#scrolling-header').css({ opacity: opacity })
+                          .css('left', h2s.first().position()['left'] - 180 - 35)
+                          .html(target_content);
+}
+
+$(function() {
+    jQuery('span.timeago').timeago();
+
+    if ($('#leaf-stats').length) {
+        $('body').append('<div id="scrolling-header"></div>');
+        h2s = $('#leaf-content h2');
+
+        $(window).scroll(function () {
+            place_scrolly_header();
+        });
+        $(window).resize(function () {
+            place_scrolly_header();
+        });
+    }
+});
diff --git a/staticsite.py b/staticsite.py
--- a/staticsite.py
+++ b/staticsite.py
@@ -41,6 +41,7 @@ templates = {
     <link href='http://fonts.googleapis.com/css?family=OFL+Sorts+Mill+Goudy+TT:regular,italic' rel='stylesheet' type='text/css' />
     <link rel="stylesheet" href="{relpath}style.css" type="text/css" media="screen" />
     <link rel="stylesheet" href="{relpath}print.css" type="text/css" media="print" />
+    <script data-cfasync="false" src="{relpath}sjl.js" type="text/javascript"></script>
     <title>{title}</title>
 </head>
 <body>
@@ -1357,6 +1358,12 @@ def parsesite(ui, repo, target, **opts):
         highlightingfile = os.path.join(target, pretty)
         if not os.path.isfile(highlightingfile) or not samefilecontent(highlightingsrc, highlightingfile):
             shutil.copyfile(highlightingsrc, highlightingfile)
+    # and add steve loshs sidebar-title
+    for sjl in ["sjl.js"]:
+        sjlsrc = os.path.join(os.path.dirname(__file__), sjl)
+        sjlfile = os.path.join(target, sjl)
+        if not os.path.isfile(sjlfile) or not samefilecontent(sjlsrc, sjlfile):
+            shutil.copyfile(sjlsrc, sjlfile)
     
     ui.debug("[staticsite] writeoverview\n")
     # then the overview