general.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. (function($){
  2. var currentPage, currentHash;
  3. function resizeUI() {
  4. $('#doc3').css('height', (window.innerHeight || document.documentElement.clientHeight) - $('#hd').height() - 12);
  5. }
  6. function scrollToHash(hash) {
  7. if (hash) {
  8. $(hash).each(function() {
  9. $(this)[0].scrollIntoView();
  10. });
  11. }
  12. }
  13. function loadURL(url) {
  14. var parts, hash;
  15. // Trim away everything but the file name
  16. url = /([^\/]+)$/.exec(url)[0];
  17. // Parse out parts
  18. parts = /^([^#]+)(#.+)?$/.exec(url);
  19. hash = parts[2];
  20. // In page link, no need to load anything
  21. if (parts[1] == currentPage) {
  22. if (hash)
  23. scrollToHash(hash);
  24. else
  25. $('#detailsView')[0].scrollTop = 0;
  26. return;
  27. }
  28. currentPage = parts[1];
  29. $("#classView a.selected").removeClass('selected');
  30. $("#classView a[href='" + currentPage.replace(/^.*\/([^\/]+)$/, '$1') + "']").addClass('selected').focus().parents("li.expandable").each(function() {
  31. var li = $(this).removeClass("expandable").addClass("collapsable");
  32. li.find("> div.expandable-hitarea").removeClass("expandable-hitarea").addClass("collapsable-hitarea");
  33. li.find("> ul").show();
  34. });
  35. $('#detailsView').find("div.page").hide();
  36. // Check if the page has been loaded before
  37. if ($("#detailsView div[url='" + currentPage + "']").show().length == 0) {
  38. $('#detailsView').addClass("loading");
  39. // Load page and cache it in a div
  40. $.get(currentPage, "", function(data) {
  41. data = /<body[^>]*>([\s\S]+)<\/body>/.exec(data);
  42. if (data) {
  43. $('#detailsView').removeClass("loading").append('<div url="' + currentPage + '" class="page">' + data[1] + '</div>')[0].scrollTop = 0;
  44. SyntaxHighlighter.config.clipboardSwf = 'js/clipboard.swf';
  45. SyntaxHighlighter.highlight({gutter : false});
  46. scrollToHash(hash);
  47. }
  48. });
  49. } else
  50. scrollToHash(hash);
  51. }
  52. $().ready(function(){
  53. $("#browser").treeview();
  54. $(window).resize(resizeUI).trigger('resize');
  55. window.setInterval(function() {
  56. var hash = document.location.hash;
  57. if (hash != currentHash && hash) {
  58. loadURL(hash.replace(/\-/g, '#').substring(1));
  59. currentHash = hash;
  60. }
  61. }, 100);
  62. $("a").live("click", function(e) {
  63. var url = e.target.href;
  64. if (e.button == 0) {
  65. if (url.indexOf('class_') != -1 || url.indexOf('alias_') != -1 || url.indexOf('member_') != -1) {
  66. document.location.hash = e.target.href.replace(/^.*\/([^\/]+)/, '$1').replace(/#/g, '-');
  67. loadURL(url);
  68. }
  69. e.preventDefault();
  70. }
  71. });
  72. });
  73. })(jQuery);