Letlabo Nature Reserve
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*!
  2. * Documenter 2.0
  3. * http://rxa.li/documenter
  4. *
  5. * Copyright 2011, Xaver Birsak
  6. * http://revaxarts.com
  7. *
  8. */
  9. $(document).ready(function() {
  10. var timeout,
  11. sections = new Array(),
  12. sectionscount = 0,
  13. win = $(window),
  14. sidebar = $('#documenter_sidebar'),
  15. nav = $('#documenter_nav'),
  16. logo = $('#documenter_logo'),
  17. navanchors = nav.find('a'),
  18. timeoffset = 50,
  19. hash = location.hash || null;
  20. iDeviceNotOS4 = (navigator.userAgent.match(/iphone|ipod|ipad/i) && !navigator.userAgent.match(/OS 5/i)) || false,
  21. badIE = $('html').prop('class').match(/ie(6|7|8)/)|| false;
  22. //handle external links (new window)
  23. $('a[href^=http]').bind('click',function(){
  24. window.open($(this).attr('href'));
  25. return false;
  26. });
  27. //IE 8 and lower doesn't like the smooth pagescroll
  28. if(!badIE){
  29. window.scroll(0,0);
  30. $('a[href^=#]').bind('click touchstart',function(){
  31. hash = $(this).attr('href');
  32. $.scrollTo.window().queue([]).stop();
  33. goTo(hash);
  34. return false;
  35. });
  36. //if a hash is set => go to it
  37. if(hash){
  38. setTimeout(function(){
  39. goTo(hash);
  40. },500);
  41. }
  42. }
  43. //We need the position of each section until the full page with all images is loaded
  44. win.bind('load',function(){
  45. var sectionselector = 'section';
  46. //Documentation has subcategories
  47. if(nav.find('ol').length){
  48. sectionselector = 'section, h4';
  49. }
  50. //saving some information
  51. $(sectionselector).each(function(i,e){
  52. var _this = $(this);
  53. var p = {
  54. id: this.id,
  55. pos: _this.offset().top
  56. };
  57. sections.push(p);
  58. });
  59. //iPhone, iPod and iPad don't trigger the scroll event
  60. if(iDeviceNotOS4){
  61. nav.find('a').bind('click',function(){
  62. setTimeout(function(){
  63. win.trigger('scroll');
  64. },duration);
  65. });
  66. //scroll to top
  67. window.scroll(0,0);
  68. }
  69. //how many sections
  70. sectionscount = sections.length;
  71. //bind the handler to the scroll event
  72. win.bind('scroll',function(event){
  73. clearInterval(timeout);
  74. //should occur with a delay
  75. timeout = setTimeout(function(){
  76. //get the position from the very top in all browsers
  77. pos = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  78. //iDeviceNotOS4s don't know the fixed property so we fake it
  79. if(iDeviceNotOS4){
  80. sidebar.css({height:document.height});
  81. logo.css({'margin-top':pos});
  82. }
  83. //activate Nav element at the current position
  84. activateNav(pos);
  85. },timeoffset);
  86. }).trigger('scroll');
  87. });
  88. //the function is called when the hash changes
  89. function hashchange(){
  90. goTo(location.hash, false);
  91. }
  92. //scroll to a section and set the hash
  93. function goTo(hash,changehash){
  94. win.unbind('hashchange', hashchange);
  95. hash = hash.replace(/!\//,'');
  96. win.stop().scrollTo(hash,duration,{
  97. easing:easing,
  98. axis:'y'
  99. });
  100. if(changehash !== false){
  101. var l = location;
  102. location.href = (l.protocol+'//'+l.host+l.pathname+'#!/'+hash.substr(1));
  103. }
  104. win.bind('hashchange', hashchange);
  105. }
  106. //activate current nav element
  107. function activateNav(pos){
  108. var offset = 100,
  109. current, next, parent, isSub, hasSub;
  110. win.unbind('hashchange', hashchange);
  111. for(var i=sectionscount;i>0;i--){
  112. if(sections[i-1].pos <= pos+offset){
  113. navanchors.removeClass('current');
  114. current = navanchors.eq(i-1);
  115. current.addClass('current');
  116. parent = current.parent().parent();
  117. next = current.next();
  118. hasSub = next.is('ul');
  119. isSub = !parent.is('#documenter_nav');
  120. nav.find('ol:visible').not(parent).slideUp('fast');
  121. if(isSub){
  122. parent.prev().addClass('current');
  123. parent.stop().slideDown('fast');
  124. }else if(hasSub){
  125. next.stop().slideDown('fast');
  126. }
  127. win.bind('hashchange', hashchange);
  128. break;
  129. };
  130. }
  131. }
  132. // make code pretty
  133. window.prettyPrint && prettyPrint();
  134. });