scripts.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. * Documenter 2.0
  3. * http://rxa.li/documenter
  4. *
  5. * Copyright 2013, Xaver Birsak
  6. * http://revaxarts.com
  7. *
  8. */
  9. !function ($) {
  10. $(function(){
  11. var hash = location.hash || null,
  12. win = $(window),
  13. scrolloffset = $('div.navbar').height()+40,
  14. iDeviceNotOS4 = (navigator.userAgent.match(/iphone|ipod|ipad/i) && !navigator.userAgent.match(/OS 5/i)) || false,
  15. badIE = $('html').prop('class').match(/ie(6|7|8)/)|| false;
  16. duration = parseInt(duration,10);
  17. $('.dropdown-toggle').dropdown();
  18. $(".collapse").collapse();
  19. $(window).one('scroll', function(){
  20. $('.navbar').scrollspy();
  21. $('.nav').find('li.active').removeClass('active');
  22. });
  23. //handle external links (new window)
  24. $('a[href^=http]').bind('click',function(){
  25. window.open($(this).attr('href'));
  26. return false;
  27. });
  28. //IE 8 and lower doesn't like the smooth pagescroll
  29. if(!badIE){
  30. window.scroll(0,0);
  31. $('a[href^=#]').bind('click touchstart',function(){
  32. hash = $(this).attr('href');
  33. $.scrollTo.window().queue([]).stop();
  34. goTo(hash, true);
  35. return false;
  36. });
  37. //if a hash is set => go to it
  38. if(hash){
  39. setTimeout(function(){
  40. goTo(hash);
  41. },500);
  42. }
  43. }
  44. $('.brand').on('click', function(){
  45. goTo('#container', false);
  46. });
  47. //the function is called when the hash changes
  48. function hashchange(){
  49. goTo(location.hash, false);
  50. }
  51. //scroll to a section and set the hash
  52. function goTo(hash,changehash){
  53. win.unbind('hashchange', hashchange);
  54. hash = hash.replace(/!\//,'');
  55. win.stop().scrollTo(hash,duration,{
  56. offset:-scrolloffset,
  57. easing:easing,
  58. axis:'y'
  59. });
  60. if(changehash !== false){
  61. var l = location;
  62. location.href = (l.protocol+'//'+l.host+l.pathname+'#!/'+hash.substr(1));
  63. location.hash = hash.substr(1);
  64. }
  65. win.bind('hashchange', hashchange);
  66. }
  67. // make code pretty
  68. window.prettyPrint && prettyPrint();
  69. })
  70. }(window.jQuery)