1 |
schoenebeck |
2732 |
/* |
2 |
|
|
CrudeDoc Java Script |
3 |
|
|
Copyright (c) 2015 Christian Schoenebeck. All rights reserved. |
4 |
|
|
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 |
|
|
} |
18 |
|
|
|
19 |
|
|
function crdOnScroll() { |
20 |
|
|
//var headers = $("body > article :header:in-viewport"); |
21 |
|
|
var headers = $("body > article :header"); |
22 |
|
|
var wst = $(window).scrollTop(); |
23 |
|
|
if (wst <= 0) { |
24 |
|
|
for (var i = 0; i < headers.length; ++i) { |
25 |
|
|
$("body > aside *[section]").removeClass("current"); |
26 |
|
|
var link = $("body > aside *[section='" + headers[i].id + "']"); |
27 |
|
|
$(link).addClass("current"); |
28 |
|
|
return; |
29 |
|
|
} |
30 |
|
|
} |
31 |
|
|
var wh = crdWindowHeight(); |
32 |
|
|
for (var i = headers.length - 1; i >= 0; --i) { |
33 |
|
|
var offset = headers[i].offsetTop - wst + wh/2; |
34 |
|
|
if (headers[i].id.length > 0 && (offset <= 0 || offset <= wh)) { |
35 |
|
|
$("body > aside *[section]").removeClass("current"); |
36 |
|
|
var link = $("body > aside *[section='" + headers[i].id + "']"); |
37 |
|
|
$(link).addClass("current"); |
38 |
|
|
break; |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
function crdOnWindowResize() { |
44 |
|
|
var wh = crdWindowHeight(); |
45 |
|
|
$("nav > ul > li ul").css("max-height", wh - 70); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
function crdDetectFeatures() { |
49 |
|
|
if ($.support["transform"]) { |
50 |
|
|
$("body").addClass("hasTransform"); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
$(function() { |
55 |
|
|
crdDetectFeatures(); |
56 |
|
|
$(document).tooltip(); |
57 |
|
|
$("article img[caption]").each(function() { |
58 |
|
|
$(this).after( |
59 |
|
|
"<div class='imgcptn'>" + |
60 |
|
|
$(this).attr("caption") + "</div>" |
61 |
|
|
); |
62 |
|
|
}); |
63 |
|
|
$("body > aside *[section]").click(function(e) { |
64 |
|
|
//e.preventDefault(); |
65 |
|
|
crdScrollTo(this); |
66 |
|
|
return false; |
67 |
|
|
}); |
68 |
|
|
crdOnScroll(); |
69 |
|
|
$(window).resize(function() { |
70 |
|
|
crdOnWindowResize(); |
71 |
|
|
}); |
72 |
|
|
}); |
73 |
|
|
|
74 |
|
|
$(document).ready(function() { |
75 |
|
|
crdOnWindowResize(); |
76 |
|
|
}); |
77 |
|
|
|
78 |
|
|
var _crdScrollTimeout; |
79 |
|
|
|
80 |
|
|
$(window).scroll(function() { |
81 |
|
|
crdOnScroll(); |
82 |
|
|
}); |