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.

template.js 6.9 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
  2. $.browser.ipad = /ipad/.test(navigator.userAgent.toLowerCase());
  3. /**
  4. * Initializes page contents for progressive enhancement.
  5. */
  6. function initializeContents()
  7. {
  8. // hide all more buttons because they are not needed with JS
  9. $(".element a.more").hide();
  10. $(".clickable.class,.clickable.interface").click(function() {
  11. document.location = $("a.more", this).attr('href');
  12. });
  13. // change the cursor to a pointer to make it more explicit that this it clickable
  14. // do a background color change on hover to emphasize the clickability eveb more
  15. // we do not use CSS for this because when JS is disabled this behaviour does not
  16. // apply and we do not want the hover
  17. $(".element.method,.element.function,.element.class.clickable,.element.interface.clickable")
  18. .css("cursor", "pointer")
  19. .hover(function() {
  20. $(this).css('backgroundColor', '#F8FDF6')
  21. }, function(){
  22. $(this).css('backgroundColor', 'white')}
  23. );
  24. // do not show tooltips on iPad; it will cause the user having to click twice
  25. if (!$.browser.ipad) {
  26. $('.btn-group.visibility,.btn-group.view,.btn-group.type-filter')
  27. .tooltip({'placement':'bottom'});
  28. }
  29. $('.btn-group.visibility,.btn-group.view,.btn-group.type-filter')
  30. .show()
  31. .find('button')
  32. .find('i').click(function(){ $(this).parent().click(); });
  33. // set the events for the visibility buttons and enable by default.
  34. $('.visibility button.public').click(function(){
  35. $('.element.public,.side-nav li.public').toggle($(this).hasClass('active'));
  36. }).click();
  37. $('.visibility button.protected').click(function(){
  38. $('.element.protected,.side-nav li.protected').toggle($(this).hasClass('active'));
  39. }).click();
  40. $('.visibility button.private').click(function(){
  41. $('.element.private,.side-nav li.private').toggle($(this).hasClass('active'));
  42. }).click();
  43. $('.visibility button.inherited').click(function(){
  44. $('.element.inherited,.side-nav li.inherited').toggle($(this).hasClass('active'));
  45. }).click();
  46. $('.type-filter button.critical').click(function(){
  47. $('tr.critical').toggle($(this).hasClass('active'));
  48. });
  49. $('.type-filter button.error').click(function(){
  50. $('tr.error').toggle($(this).hasClass('active'));
  51. });
  52. $('.type-filter button.notice').click(function(){
  53. $('tr.notice').toggle($(this).hasClass('active'));
  54. });
  55. $('.view button.details').click(function(){
  56. $('.side-nav li.view-simple').removeClass('view-simple');
  57. }).button('toggle').click();
  58. $('.view button.details').click(function(){
  59. $('.side-nav li.view-simple').removeClass('view-simple');
  60. }).button('toggle').click();
  61. $('.view button.simple').click(function(){
  62. $('.side-nav li').addClass('view-simple');
  63. });
  64. // sorting example
  65. // $('ol li').sort(
  66. // function(a, b) { return a.innerHTML.toLowerCase() > b.innerHTML.toLowerCase() ? 1 : -1; }
  67. // ).appendTo('ol');
  68. }
  69. $(document).ready(function() {
  70. prettyPrint();
  71. initializeContents();
  72. // do not show tooltips on iPad; it will cause the user having to click twice
  73. if(!$.browser.ipad) {
  74. $(".side-nav a").tooltip({'placement': 'top'});
  75. }
  76. // chrome cannot deal with certain situations; warn the user about reduced features
  77. if ($.browser.chrome && (window.location.protocol == 'file:')) {
  78. $("body > .container").prepend(
  79. '<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a>' +
  80. 'You are using Google Chrome in a local environment; AJAX interaction has been ' +
  81. 'disabled because Chrome cannot <a href="http://code.google.com/p/chromium/issues/detail?id=40787">' +
  82. 'retrieve files using Ajax</a>.</div>'
  83. );
  84. }
  85. $('ul.nav-namespaces li a, ul.nav-packages li a').click(function(){
  86. // Google Chrome does not do Ajax locally
  87. if ($.browser.chrome && (window.location.protocol == 'file:'))
  88. {
  89. return true;
  90. }
  91. $(this).parents('.side-nav').find('.active').removeClass('active');
  92. $(this).parent().addClass('active');
  93. $('div.namespace-contents').load(
  94. this.href + ' div.namespace-contents', function(){
  95. initializeContents();
  96. $(window).scrollTop($('div.namespace-contents').position().top);
  97. }
  98. );
  99. $('div.package-contents').load(
  100. this.href + ' div.package-contents', function(){
  101. initializeContents();
  102. $(window).scrollTop($('div.package-contents').position().top);
  103. }
  104. );
  105. return false;
  106. });
  107. function filterPath(string)
  108. {
  109. return string
  110. .replace(/^\//, '')
  111. .replace(/(index|default).[a-zA-Z]{3,4}$/, '')
  112. .replace(/\/$/, '');
  113. }
  114. var locationPath = filterPath(location.pathname);
  115. // the ipad already smoothly scrolls and does not detect the scrollable
  116. // element if top=0; as such we disable this behaviour for the iPad
  117. if (!$.browser.ipad) {
  118. $('a[href*=#]').each(function ()
  119. {
  120. var thisPath = filterPath(this.pathname) || locationPath;
  121. if (locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/, ''))
  122. {
  123. var target = decodeURIComponent(this.hash.replace(/#/,''));
  124. // note: I'm using attribute selector, because id selector can't match elements with '$'
  125. var $target = $('[id="'+target+'"]');
  126. if ($target.length > 0)
  127. {
  128. $(this).click(function (event)
  129. {
  130. var scrollElem = scrollableElement('html', 'body');
  131. var targetOffset = $target.offset().top;
  132. event.preventDefault();
  133. $(scrollElem).animate({scrollTop:targetOffset}, 400, function ()
  134. {
  135. location.hash = target;
  136. });
  137. });
  138. }
  139. }
  140. });
  141. }
  142. // use the first element that is "scrollable"
  143. function scrollableElement(els)
  144. {
  145. for (var i = 0, argLength = arguments.length; i < argLength; i++)
  146. {
  147. var el = arguments[i], $scrollElement = $(el);
  148. if ($scrollElement.scrollTop() > 0)
  149. {
  150. return el;
  151. }
  152. else
  153. {
  154. $scrollElement.scrollTop(1);
  155. var isScrollable = $scrollElement.scrollTop() > 0;
  156. $scrollElement.scrollTop(0);
  157. if (isScrollable)
  158. {
  159. return el;
  160. }
  161. }
  162. }
  163. return [];
  164. }
  165. });