/* CrudeDoc Java Script Copyright (c) 2015 - 2017 Christian Schoenebeck. All rights reserved. http://www.crudebyte.com */ var g_isTouch = false; var g_isMouse = false; function crdWindowWidth() { return window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth; } 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 crdUpdateTOCStatus() { var noTOC = $("html").hasClass("no-toc"); $("nav > .foldbtn a").html( noTOC ? ">>>" : "<<<" ); $("nav > .foldbtn a").attr("title", noTOC ? "Show content menu." : "Hide content menu." ) } function crdToggleTOC() { $("html").toggleClass("no-toc"); if (typeof(Storage) !== "undefined") { try { sessionStorage.setItem("show-toc", $("html").hasClass("no-toc") ? "no" : "yes"); } catch (e) {} } crdUpdateTOCStatus(); } function crdOnWindowResize() { var wh = crdWindowHeight(); $("nav > ul > li ul").css("max-height", wh - 70); } function crdDetectFeatures() { if ('ontouchstart' in document.documentElement) { g_isTouch = true; document.documentElement.className += ' touch'; } else { g_isTouch = false; document.documentElement.className += ' no-touch'; } $(window).bind('mousemove.hasMouse', function(){ $(window).unbind('.hasMouse'); g_isMouse = true; $(document).tooltip(); }).bind('touchstart.hasMouse', function(){ $(window).unbind('.hasMouse'); g_isMouse = false; }); if ($.support["transform"]) { $("body").addClass("hasTransform"); } var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; if (iOS) { $("body").addClass("iOS"); } } $(function() { crdDetectFeatures(); $("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(); }; } if (g_isTouch) { $("nav > ul > li").each(function() { $(this).click(function() { var active = $(this).hasClass("active"); $("nav li.active").removeClass("active"); if (!active) $(this).addClass("active"); }); }); $("article").click(function() { $("nav li.active").removeClass("active"); }); } $("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); }); } }); var showToc = null; if (typeof(Storage) !== "undefined") { try { var s = sessionStorage.getItem("show-toc"); if (s) showToc = s != "no"; } catch (e) {} } if (!$("body aside") || !$("body aside").length) showToc = false; if (showToc === null) { var w = crdWindowWidth(); showToc = (w >= 1200); } $("html").addClass("no-effect"); if (!showToc) { $("html").addClass("no-toc"); } document.body.offsetHeight; $("html").removeClass("no-effect"); crdUpdateTOCStatus(); }); $(document).ready(function() { crdOnWindowResize(); crdScrollToHash(); }); var _crdScrollTimeout; $(window).scroll(function() { crdOnScroll(); });