/* CrudeDoc Java Script Copyright (c) 2015 - 2017 Christian Schoenebeck. All rights reserved. http://www.crudebyte.com */ function crdWindowHeight() { return window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight; } function crdScrollTo(e) { $('html, body').animate({ scrollTop: $( "#" + $(e).attr("section") ).offset().top - 68 }, 300); var obj = $( "#" + $(e).attr("section") ); $(obj).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120); } function crdScrollToHash(h) { if (typeof h === 'undefined') { h = location.hash; if (!h || h.length < 2) return; } $('html, body').animate({ scrollTop: $( h ).offset().top - 68 }, 300); $(h).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120); } function crdOnScroll() { //var headers = $("body > article :header:in-viewport"); var headers = $("body > article :header"); var wst = $(window).scrollTop(); if (wst <= 0) { for (var i = 0; i < headers.length; ++i) { $("body > aside *[section]").removeClass("current"); var link = $("body > aside *[section='" + headers[i].id + "']"); $(link).addClass("current"); return; } } var wh = crdWindowHeight(); for (var i = headers.length - 1; i >= 0; --i) { var offset = headers[i].offsetTop - wst + wh/2; if (headers[i].id.length > 0 && (offset <= 0 || offset <= wh)) { $("body > aside *[section]").removeClass("current"); var link = $("body > aside *[section='" + headers[i].id + "']"); $(link).addClass("current"); break; } } } function crdOnWindowResize() { var wh = crdWindowHeight(); $("nav > ul > li ul").css("max-height", wh - 70); } function crdDetectFeatures() { if ($.support["transform"]) { $("body").addClass("hasTransform"); } var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; if (iOS) { $("body").addClass("iOS"); } } $(function() { crdDetectFeatures(); $(document).tooltip(); $("article img[caption]").each(function() { $(this).after( "
" + $(this).attr("caption") + "
" ); }); $("body > aside *[section]").click(function(e) { //e.preventDefault(); crdScrollTo(this); return false; }); crdOnScroll(); $(window).resize(function() { crdOnWindowResize(); }); if ("onhashchange" in window) { window.onhashchange = function() { crdScrollToHash(); }; } $("article a[href]").each(function() { var href = $(this).attr("href"); if (href && href.length > 1 && href.charAt(0) == '#') { $(this).click(function(e) { var anch = $(this).attr("href"); crdScrollToHash(anch); }); } }); }); $(document).ready(function() { crdOnWindowResize(); crdScrollToHash(); }); var _crdScrollTimeout; $(window).scroll(function() { crdOnScroll(); });