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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3270 - (hide annotations) (download) (as text)
Fri Jun 2 18:31:00 2017 UTC (6 years, 10 months ago) by schoenebeck
File MIME type: application/javascript
File size: 4431 byte(s)
* Site Template: Content menu can now be hidden.

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 schoenebeck 3269 var g_isTouch = false;
8    
9 schoenebeck 3270 function crdWindowWidth() {
10     return window.innerWidth ||
11     document.documentElement.clientWidth ||
12     document.getElementsByTagName('body')[0].clientWidth;
13     }
14    
15 schoenebeck 2732 function crdWindowHeight() {
16     return window.innerHeight ||
17     document.documentElement.clientHeight ||
18     document.getElementsByTagName('body')[0].clientHeight;
19     }
20    
21     function crdScrollTo(e) {
22     $('html, body').animate({
23     scrollTop: $( "#" + $(e).attr("section") ).offset().top - 68
24     }, 300);
25 schoenebeck 3266 var obj = $( "#" + $(e).attr("section") );
26     $(obj).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120);
27 schoenebeck 2732 }
28    
29 schoenebeck 3266 function crdScrollToHash(h) {
30     if (typeof h === 'undefined') {
31     h = location.hash;
32     if (!h || h.length < 2) return;
33     }
34     $('html, body').animate({
35     scrollTop: $( h ).offset().top - 68
36     }, 300);
37     $(h).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120);
38     }
39    
40 schoenebeck 2732 function crdOnScroll() {
41     //var headers = $("body > article :header:in-viewport");
42     var headers = $("body > article :header");
43     var wst = $(window).scrollTop();
44     if (wst <= 0) {
45     for (var i = 0; i < headers.length; ++i) {
46     $("body > aside *[section]").removeClass("current");
47     var link = $("body > aside *[section='" + headers[i].id + "']");
48     $(link).addClass("current");
49     return;
50     }
51     }
52     var wh = crdWindowHeight();
53     for (var i = headers.length - 1; i >= 0; --i) {
54     var offset = headers[i].offsetTop - wst + wh/2;
55     if (headers[i].id.length > 0 && (offset <= 0 || offset <= wh)) {
56     $("body > aside *[section]").removeClass("current");
57     var link = $("body > aside *[section='" + headers[i].id + "']");
58     $(link).addClass("current");
59     break;
60     }
61     }
62     }
63    
64 schoenebeck 3270 function crdUpdateTOCStatus() {
65     var noTOC = $("html").hasClass("no-toc");
66     $("nav > .foldbtn a").html(
67     noTOC ? "&gt;&gt;&gt;" : "&lt;&lt;&lt;"
68     );
69     $("nav > .foldbtn a").attr("title",
70     noTOC ? "Show content menu." : "Hide content menu."
71     )
72     }
73    
74     function crdToggleTOC() {
75     $("html").toggleClass("no-toc");
76     crdUpdateTOCStatus();
77     }
78    
79 schoenebeck 2732 function crdOnWindowResize() {
80     var wh = crdWindowHeight();
81     $("nav > ul > li ul").css("max-height", wh - 70);
82     }
83    
84     function crdDetectFeatures() {
85 schoenebeck 3268 if ('ontouchstart' in document.documentElement) {
86 schoenebeck 3269 g_isTouch = true;
87 schoenebeck 3268 document.documentElement.className += ' touch';
88     } else {
89 schoenebeck 3269 g_isTouch = false;
90 schoenebeck 3268 document.documentElement.className += ' no-touch';
91     }
92 schoenebeck 2732 if ($.support["transform"]) {
93     $("body").addClass("hasTransform");
94     }
95 schoenebeck 3267 var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
96     if (iOS) {
97     $("body").addClass("iOS");
98     }
99 schoenebeck 2732 }
100    
101     $(function() {
102     crdDetectFeatures();
103     $(document).tooltip();
104 schoenebeck 3269 if (g_isTouch) {
105     $("header a[title]" ).tooltip({
106     disabled: true
107     });
108 schoenebeck 3270 $("nav a[title]" ).tooltip({
109     disabled: true
110     });
111 schoenebeck 3269 }
112 schoenebeck 2732 $("article img[caption]").each(function() {
113     $(this).after(
114     "<div class='imgcptn'>" +
115     $(this).attr("caption") + "</div>"
116     );
117     });
118     $("body > aside *[section]").click(function(e) {
119     //e.preventDefault();
120     crdScrollTo(this);
121     return false;
122     });
123     crdOnScroll();
124     $(window).resize(function() {
125     crdOnWindowResize();
126     });
127 schoenebeck 3266 if ("onhashchange" in window) {
128     window.onhashchange = function() {
129     crdScrollToHash();
130     };
131     }
132     $("article a[href]").each(function() {
133     var href = $(this).attr("href");
134     if (href && href.length > 1 && href.charAt(0) == '#') {
135     $(this).click(function(e) {
136     var anch = $(this).attr("href");
137     crdScrollToHash(anch);
138     });
139     }
140     });
141 schoenebeck 3270 var w = crdWindowWidth();
142     if (w < 1200) {
143     $("html").addClass("no-toc");
144     }
145     crdUpdateTOCStatus();
146 schoenebeck 2732 });
147    
148     $(document).ready(function() {
149     crdOnWindowResize();
150 schoenebeck 3266 crdScrollToHash();
151 schoenebeck 2732 });
152    
153     var _crdScrollTimeout;
154    
155     $(window).scroll(function() {
156     crdOnScroll();
157     });

  ViewVC Help
Powered by ViewVC