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

Diff of /doc/tmpl/js/crd.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2732 by schoenebeck, Sun Apr 26 20:54:00 2015 UTC revision 3273 by schoenebeck, Sun Jun 4 15:59:26 2017 UTC
# Line 1  Line 1 
1  /*  /*
2    CrudeDoc Java Script    CrudeDoc Java Script
3    Copyright (c) 2015 Christian Schoenebeck. All rights reserved.    Copyright (c) 2015 - 2017 Christian Schoenebeck. All rights reserved.
4    http://www.crudebyte.com    http://www.crudebyte.com
5  */  */
6    
7    var g_isTouch = false;
8    var g_isMouse = false;
9    
10    function crdWindowWidth() {
11        return window.innerWidth ||
12               document.documentElement.clientWidth ||
13               document.getElementsByTagName('body')[0].clientWidth;
14    }
15    
16  function crdWindowHeight() {  function crdWindowHeight() {
17      return window.innerHeight ||      return window.innerHeight ||
18             document.documentElement.clientHeight ||             document.documentElement.clientHeight ||
# Line 14  function crdScrollTo(e) { Line 23  function crdScrollTo(e) {
23      $('html, body').animate({      $('html, body').animate({
24          scrollTop: $( "#" + $(e).attr("section") ).offset().top - 68          scrollTop: $( "#" + $(e).attr("section") ).offset().top - 68
25      }, 300);      }, 300);
26        var obj = $( "#" + $(e).attr("section") );
27        $(obj).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120);
28    }
29    
30    function crdScrollToHash(h) {
31        if (typeof h === 'undefined') {
32            h = location.hash;
33            if (!h || h.length < 2) return;
34        }
35        $('html, body').animate({
36            scrollTop: $( h ).offset().top - 68
37        }, 300);
38        $(h).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(120).fadeOut(100).fadeIn(120);
39  }  }
40    
41  function crdOnScroll() {  function crdOnScroll() {
# Line 40  function crdOnScroll() { Line 62  function crdOnScroll() {
62      }      }
63  }  }
64    
65    function crdUpdateTOCStatus() {
66        var noTOC = $("html").hasClass("no-toc");
67        $("nav > .foldbtn a").html(
68            noTOC ? "&gt;&gt;&gt;" : "&lt;&lt;&lt;"
69        );
70        $("nav > .foldbtn a").attr("title",
71            noTOC ? "Show content menu." : "Hide content menu."
72        )
73    }
74    
75    function crdToggleTOC() {
76        $("html").toggleClass("no-toc");
77        if (typeof(Storage) !== "undefined") {
78            try {
79                sessionStorage.setItem("show-toc", $("html").hasClass("no-toc") ? "no" : "yes");
80            } catch (e) {}
81        }
82        crdUpdateTOCStatus();
83    }
84    
85  function crdOnWindowResize() {  function crdOnWindowResize() {
86      var wh = crdWindowHeight();      var wh = crdWindowHeight();
87      $("nav > ul > li ul").css("max-height", wh - 70);      $("nav > ul > li ul").css("max-height", wh - 70);
88  }  }
89    
90  function crdDetectFeatures() {  function crdDetectFeatures() {
91        if ('ontouchstart' in document.documentElement) {
92            g_isTouch = true;
93            document.documentElement.className += ' touch';
94        } else {
95            g_isTouch = false;
96            document.documentElement.className += ' no-touch';
97        }
98        $(window).bind('mousemove.hasMouse', function(){
99            $(window).unbind('.hasMouse');
100            g_isMouse = true;
101            $(document).tooltip();
102        }).bind('touchstart.hasMouse', function(){
103            $(window).unbind('.hasMouse');
104            g_isMouse = false;
105        });
106      if ($.support["transform"]) {      if ($.support["transform"]) {
107          $("body").addClass("hasTransform");          $("body").addClass("hasTransform");
108      }      }
109        var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
110        if (iOS) {
111            $("body").addClass("iOS");
112        }
113  }  }
114    
115  $(function() {  $(function() {
116      crdDetectFeatures();      crdDetectFeatures();
     $(document).tooltip();  
117      $("article img[caption]").each(function() {      $("article img[caption]").each(function() {
118          $(this).after(          $(this).after(
119              "<div class='imgcptn'>" +              "<div class='imgcptn'>" +
# Line 69  $(function() { Line 129  $(function() {
129      $(window).resize(function() {      $(window).resize(function() {
130          crdOnWindowResize();          crdOnWindowResize();
131      });      });
132        if ("onhashchange" in window) {
133            window.onhashchange = function() {
134                crdScrollToHash();
135            };
136        }
137        if (g_isTouch) {
138            $("nav > ul > li").each(function() {
139                $(this).click(function() {
140                    var active = $(this).hasClass("active");
141                    $("nav li.active").removeClass("active");
142                    if (!active)
143                        $(this).addClass("active");
144                });
145            });
146            $("article").click(function() {
147                $("nav li.active").removeClass("active");
148            });
149        }
150        $("article a[href]").each(function() {
151            var href = $(this).attr("href");
152            if (href && href.length > 1 && href.charAt(0) == '#') {
153                $(this).click(function(e) {
154                    var anch = $(this).attr("href");
155                    crdScrollToHash(anch);
156                });
157            }
158        });
159        var showToc = null;
160        if (typeof(Storage) !== "undefined") {
161            try {
162                var s = sessionStorage.getItem("show-toc");
163                if (s)
164                    showToc = s != "no";
165            } catch (e) {}
166        }
167        if (!$("body aside") || !$("body aside").length)
168            showToc = false;
169        if (showToc === null) {
170            var w = crdWindowWidth();
171            showToc = (w >= 1200);
172        }
173        $("html").addClass("no-effect");
174        if (!showToc) {
175            $("html").addClass("no-toc");
176        }
177        document.body.offsetHeight;
178        $("html").removeClass("no-effect");
179        crdUpdateTOCStatus();
180  });  });
181    
182  $(document).ready(function() {  $(document).ready(function() {
183      crdOnWindowResize();      crdOnWindowResize();
184        crdScrollToHash();
185  });  });
186    
187  var _crdScrollTimeout;  var _crdScrollTimeout;

Legend:
Removed from v.2732  
changed lines
  Added in v.3273

  ViewVC Help
Powered by ViewVC