/[svn]/doc/tmpl/js/crd.js
ViewVC logotype

Annotation of /doc/tmpl/js/crd.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3266 - (hide annotations) (download) (as text)
Thu Jun 1 13:13:27 2017 UTC (6 years, 10 months ago) by schoenebeck
File MIME type: application/javascript
File size: 3183 byte(s)
* Site template: visual improvements on anchor links.

1 schoenebeck 2732 /*
2     CrudeDoc Java Script
3 schoenebeck 3266 Copyright (c) 2015 - 2017 Christian Schoenebeck. All rights reserved.
4 schoenebeck 2732 http://www.crudebyte.com
5     */
6    
7     function crdWindowHeight() {
8     return window.innerHeight ||
9     document.documentElement.clientHeight ||
10     document.getElementsByTagName('body')[0].clientHeight;
11     }
12    
13     function crdScrollTo(e) {
14     $('html, body').animate({
15     scrollTop: $( "#" + $(e).attr("section") ).offset().top - 68
16     }, 300);
17 schoenebeck 3266 var obj = $( "#" + $(e).attr("section") );
18     $(obj).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120);
19 schoenebeck 2732 }
20    
21 schoenebeck 3266 function crdScrollToHash(h) {
22     if (typeof h === 'undefined') {
23     h = location.hash;
24     if (!h || h.length < 2) return;
25     }
26     $('html, body').animate({
27     scrollTop: $( h ).offset().top - 68
28     }, 300);
29     $(h).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120);
30     }
31    
32 schoenebeck 2732 function crdOnScroll() {
33     //var headers = $("body > article :header:in-viewport");
34     var headers = $("body > article :header");
35     var wst = $(window).scrollTop();
36     if (wst <= 0) {
37     for (var i = 0; i < headers.length; ++i) {
38     $("body > aside *[section]").removeClass("current");
39     var link = $("body > aside *[section='" + headers[i].id + "']");
40     $(link).addClass("current");
41     return;
42     }
43     }
44     var wh = crdWindowHeight();
45     for (var i = headers.length - 1; i >= 0; --i) {
46     var offset = headers[i].offsetTop - wst + wh/2;
47     if (headers[i].id.length > 0 && (offset <= 0 || offset <= wh)) {
48     $("body > aside *[section]").removeClass("current");
49     var link = $("body > aside *[section='" + headers[i].id + "']");
50     $(link).addClass("current");
51     break;
52     }
53     }
54     }
55    
56     function crdOnWindowResize() {
57     var wh = crdWindowHeight();
58     $("nav > ul > li ul").css("max-height", wh - 70);
59     }
60    
61     function crdDetectFeatures() {
62     if ($.support["transform"]) {
63     $("body").addClass("hasTransform");
64     }
65     }
66    
67     $(function() {
68     crdDetectFeatures();
69     $(document).tooltip();
70     $("article img[caption]").each(function() {
71     $(this).after(
72     "<div class='imgcptn'>" +
73     $(this).attr("caption") + "</div>"
74     );
75     });
76     $("body > aside *[section]").click(function(e) {
77     //e.preventDefault();
78     crdScrollTo(this);
79     return false;
80     });
81     crdOnScroll();
82     $(window).resize(function() {
83     crdOnWindowResize();
84     });
85 schoenebeck 3266 if ("onhashchange" in window) {
86     window.onhashchange = function() {
87     crdScrollToHash();
88     };
89     }
90     $("article a[href]").each(function() {
91     var href = $(this).attr("href");
92     if (href && href.length > 1 && href.charAt(0) == '#') {
93     $(this).click(function(e) {
94     var anch = $(this).attr("href");
95     crdScrollToHash(anch);
96     });
97     }
98     });
99 schoenebeck 2732 });
100    
101     $(document).ready(function() {
102     crdOnWindowResize();
103 schoenebeck 3266 crdScrollToHash();
104 schoenebeck 2732 });
105    
106     var _crdScrollTimeout;
107    
108     $(window).scroll(function() {
109     crdOnScroll();
110     });

  ViewVC Help
Powered by ViewVC