Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var queue = 0;
- $('document').ready(function() {
- if(window.addEventListener) {
- window.addEventListener("hashchange", hashChange, false);
- }
- else if (window.attachEvent) {
- window.attachEvent("hashchange", hashchange, false);
- }
- // Define window location variables
- var windowHost = window.location.host,
- windowHash = window.location.hash,
- windowPath = window.location.pathname;
- // Grab the window hash value, by removing any special characters, i.e. '#!/'
- windowHash = windowHash.replace('#!/', '/');
- windowHash = windowHash ? windowHash : '/';
- // On initial page load, if user goes directly to '/sample-page' for example, redirect to '/#!/sample-page'
- if(windowPath !== '/') {
- var path = windowPath.replace('/', '');
- window.location = 'http://' + windowHost + '/#!/' + path;
- } else if(windowHash === '/') {
- window.location = 'http://' + windowHost + '/#!' + windowPath;
- }
- // Load content on menu click
- $('#nav-main ul li.menu-item-object-page a, .crosslink').live('click', function(e) {
- e.preventDefault();
- var currentHash = window.location.hash,
- currentHash = currentHash.replace('#!', '');
- $('.current_page_item').removeClass('current_page_item');
- $(this).parent().addClass('current_page_item');
- var page = $(this).attr('href');
- page = page.replace('http://' + windowHost + '/', '#!/');
- var currentPage = page.replace('#!', '');
- if(currentHash !== currentPage) {
- loadContent(page.replace('#!', ''), '#primary');
- }
- });
- // Set navigation active state on load
- if(!$('#nav-main ul li.menu-item-object-page a[href="http://' + windowHost + windowHash + '"]').parent().hasClass('current_page_item')) {
- $('.current_page_item').removeClass('current_page_item');
- $('#nav-main ul li.menu-item-object-page a[href="http://' + windowHost + windowHash + '"]').parent().addClass('current_page_item');
- }
- // Load content of hash page on load
- if(windowHash !== '/') {
- loadContent(windowHash, '#primary');
- }
- });
- function hashChange() {
- var page = window.location.hash;
- loadContent(page.replace('#!', ''), '#primary');
- }
- // Load content from other pages
- function loadContent(page, shell) {
- if(queue === 0) {
- window.location = 'http://' + window.location.host + '/#!' + page;
- queue = 1;
- $(shell).html('<div class="loadIndicator"></div>');
- $(shell).load(page + ' #content', function() {
- if($('#content').is(':hidden')) {
- $('#content').fadeIn(1000, function() {
- queue = 0;
- });
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement