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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3267 - (hide annotations) (download) (as text)
Thu Jun 1 16:05:18 2017 UTC (6 years, 11 months ago) by schoenebeck
File MIME type: application/javascript
File size: 3319 byte(s)
* Site Template: Rendering fixes for iOS and MS IE.

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 schoenebeck 3267 var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
66     if (iOS) {
67     $("body").addClass("iOS");
68     }
69 schoenebeck 2732 }
70    
71     $(function() {
72     crdDetectFeatures();
73     $(document).tooltip();
74     $("article img[caption]").each(function() {
75     $(this).after(
76     "<div class='imgcptn'>" +
77     $(this).attr("caption") + "</div>"
78     );
79     });
80     $("body > aside *[section]").click(function(e) {
81     //e.preventDefault();
82     crdScrollTo(this);
83     return false;
84     });
85     crdOnScroll();
86     $(window).resize(function() {
87     crdOnWindowResize();
88     });
89 schoenebeck 3266 if ("onhashchange" in window) {
90     window.onhashchange = function() {
91     crdScrollToHash();
92     };
93     }
94     $("article a[href]").each(function() {
95     var href = $(this).attr("href");
96     if (href && href.length > 1 && href.charAt(0) == '#') {
97     $(this).click(function(e) {
98     var anch = $(this).attr("href");
99     crdScrollToHash(anch);
100     });
101     }
102     });
103 schoenebeck 2732 });
104    
105     $(document).ready(function() {
106     crdOnWindowResize();
107 schoenebeck 3266 crdScrollToHash();
108 schoenebeck 2732 });
109    
110     var _crdScrollTimeout;
111    
112     $(window).scroll(function() {
113     crdOnScroll();
114     });

  ViewVC Help
Powered by ViewVC