Advertisement
Guest User

Untitled

a guest
Feb 18th, 2012
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. var queue = 0;
  2.  
  3. $('document').ready(function() {
  4. if(window.addEventListener) {
  5. window.addEventListener("hashchange", hashChange, false);
  6. }
  7. else if (window.attachEvent) {
  8. window.attachEvent("hashchange", hashchange, false);
  9. }
  10. // Define window location variables
  11. var windowHost = window.location.host,
  12. windowHash = window.location.hash,
  13. windowPath = window.location.pathname;
  14.  
  15. // Grab the window hash value, by removing any special characters, i.e. '#!/'
  16. windowHash = windowHash.replace('#!/', '/');
  17. windowHash = windowHash ? windowHash : '/';
  18.  
  19. // On initial page load, if user goes directly to '/sample-page' for example, redirect to '/#!/sample-page'
  20. if(windowPath !== '/') {
  21. var path = windowPath.replace('/', '');
  22. window.location = 'http://' + windowHost + '/#!/' + path;
  23. } else if(windowHash === '/') {
  24. window.location = 'http://' + windowHost + '/#!' + windowPath;
  25. }
  26.  
  27. // Load content on menu click
  28. $('#nav-main ul li.menu-item-object-page a, .crosslink').live('click', function(e) {
  29. e.preventDefault();
  30.  
  31. var currentHash = window.location.hash,
  32. currentHash = currentHash.replace('#!', '');
  33.  
  34. $('.current_page_item').removeClass('current_page_item');
  35. $(this).parent().addClass('current_page_item');
  36.  
  37. var page = $(this).attr('href');
  38. page = page.replace('http://' + windowHost + '/', '#!/');
  39.  
  40.  
  41. var currentPage = page.replace('#!', '');
  42.  
  43. if(currentHash !== currentPage) {
  44. loadContent(page.replace('#!', ''), '#primary');
  45. }
  46. });
  47.  
  48. // Set navigation active state on load
  49. if(!$('#nav-main ul li.menu-item-object-page a[href="http://' + windowHost + windowHash + '"]').parent().hasClass('current_page_item')) {
  50. $('.current_page_item').removeClass('current_page_item');
  51. $('#nav-main ul li.menu-item-object-page a[href="http://' + windowHost + windowHash + '"]').parent().addClass('current_page_item');
  52. }
  53.  
  54. // Load content of hash page on load
  55. if(windowHash !== '/') {
  56. loadContent(windowHash, '#primary');
  57. }
  58. });
  59.  
  60. function hashChange() {
  61. var page = window.location.hash;
  62. loadContent(page.replace('#!', ''), '#primary');
  63. }
  64.  
  65. // Load content from other pages
  66. function loadContent(page, shell) {
  67. if(queue === 0) {
  68. window.location = 'http://' + window.location.host + '/#!' + page;
  69. queue = 1;
  70. $(shell).html('<div class="loadIndicator"></div>');
  71. $(shell).load(page + ' #content', function() {
  72. if($('#content').is(':hidden')) {
  73. $('#content').fadeIn(1000, function() {
  74. queue = 0;
  75. });
  76. }
  77. });
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement