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

Contents of /doc/tmpl/js/crd.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3269 - (show annotations) (download) (as text)
Fri Jun 2 11:59:21 2017 UTC (6 years, 10 months ago) by schoenebeck
File MIME type: application/javascript
File size: 3690 byte(s)
- Site Template: don't show description popup for links
  in the header section for touch devices.

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

  ViewVC Help
Powered by ViewVC