scripts.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*!
  2. * Documenter 2.0
  3. * http://rxa.li/documenter
  4. *
  5. * Copyright 2011, 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. $('.navbar').scrollspy();
  19. $(".collapse").collapse();
  20. //handle external links (new window)
  21. $('a[href^=http]').bind('click',function(){
  22. window.open($(this).attr('href'));
  23. return false;
  24. });
  25. //IE 8 and lower doesn't like the smooth pagescroll
  26. if(!badIE){
  27. window.scroll(0,0);
  28. $('a[href^=#]').bind('click touchstart',function(){
  29. hash = $(this).attr('href');
  30. $.scrollTo.window().queue([]).stop();
  31. goTo(hash, true);
  32. return false;
  33. });
  34. //if a hash is set => go to it
  35. if(hash){
  36. setTimeout(function(){
  37. goTo(hash);
  38. },500);
  39. }
  40. }
  41. $('.brand').on('click', function(){
  42. goTo('#container', false);
  43. });
  44. //the function is called when the hash changes
  45. function hashchange(){
  46. goTo(location.hash, false);
  47. }
  48. //scroll to a section and set the hash
  49. function goTo(hash,changehash){
  50. win.unbind('hashchange', hashchange);
  51. hash = hash.replace(/!\//,'');
  52. win.stop().scrollTo(hash,duration,{
  53. offset:-scrolloffset,
  54. easing:easing,
  55. axis:'y'
  56. });
  57. if(changehash !== false){
  58. var l = location;
  59. location.href = (l.protocol+'//'+l.host+l.pathname+'#!/'+hash.substr(1));
  60. location.hash = hash.substr(1);
  61. }
  62. win.bind('hashchange', hashchange);
  63. }
  64. // make code pretty
  65. window.prettyPrint && prettyPrint();
  66. })
  67. }(window.jQuery)