/* * activeNav.js - Active Navigation Class * * Controls pathing in the address bar, watching for changes and handling initilizing ajax requests for ajax-driven sites * * Yooia by Jason Corradino is licensed under a Creative Commons Attribution 3.0 License. * License: http://creativecommons.org/licenses/by/3.0/us/ * * Based on a work at ImYourDeveloper.com. */ function activeNavigation() { var obj = this; var getCurrentLocation = document.location.href; this.getHash = function() { // pull and return the hash from the url var hash = getCurrentLocation.split("#"); hash.shift(); hash = hash.join().split("/"); if (hash[0] == "") { hash.shift(); } if (hash[ hash.length - 1 ] == "") { hash.pop(); } if (hash.length >= 1) { return hash; } else { return false; } } this.getUrlPath = function() { // pull and return the path in the url var hash = getCurrentLocation; if (hash.indexOf("/share/") != -1) { hash = hash.split("/share/"); hash.shift(); hash = hash.join().split("/"); return hash; } return false; } this.getLoaderLink = function() { // var navPath = this.getHash() ? this.getHash() : this.getUrlPath(); var url = "/r"; if (navPath.length != 0 && navPath != "") { for (x in navPath) { url = url + '/' + navPath[x]; } return url; } else { return false; } } this.loader = function() { var loaderLink = this.getLoaderLink(); // $.ajax({url: loaderLink, success: function(data) { // $("#fill").html(data); // }}); console.log(loaderLink); } this.navUpdate = function(location) { // takes a string or an array of items. obj.expectedChange = true; var newHash = ""; if (location instanceof Array) { for (x in location) { newHash = newHash + "/" + location[x]; } } else { newHash = "/" + location; } document.location.hash = newHash; } this.monitor = setInterval(function() { if (getCurrentLocation != document.location.href) { if (obj.expectedChange == true) { delete obj.expectedChange; getCurrentLocation = document.location.href; } else { getCurrentLocation = document.location.href; obj.loader(); } } }, 1000); this.loader(); }