var hash = { oldHash: '', newHash: '', clicked: false, int: false, locat: function(href) { if(href !== undefined) location.href = href; }, changed: function() { var result = this.newHash.split('#/'); var hv = result[1]; var pairs = location.href.split("/"); // If straight link then dont override it with hash!! if(pairs[3] !== '#') return true; // Dont allow infinite loops // DEBUG: tässä on nyt vaan sellanen juttu et jos tullaan suoraan hash linkillä // niin tää palauttaakin false:n (tai jos vaan painetaan osoterivillä taas enter niin sillohan // ollaan samassa hash:issa kaks kertaa ja false tulee jolloin hypätään suoraan etusivulle.. if(this.oldHash === this.newHash) return false; if(result !== undefined && $("[href='/#/"+hv+"']").length > 0 && this.clicked === false) { $("[href='/#/"+hv+"']").find(".menuitem").click(); } }, exists: function() { var pairs = location.href.split( "/" ); if(pairs[3]) return true; if(this.newHash !== undefined && this.newHash !== '') return true;else return false; }, check: function() { var gethash = document.location.hash; if(gethash) { this.oldHash = this.newHash; if(this.oldHash !== gethash) { this.newHash = gethash; this.changed(); } } }, changeLinks: function(dest) { if(dest) { var url = location.protocol + "//"+location.hostname; $(dest).find('a').each( function() { if( ($(this).attr('href').substr(4,2) !== ":/" && $(this).attr('href').search("#") == -1 && $(this).attr('href').search("sites") == -1 && $(this).attr('href').substr(0,11) !== "javascript:") || ($(this).attr('href').search(url) !== -1 && $(this).attr('href').search("#") == -1)) { if($(this).attr('href').search(url) !== -1) { // IE is giving the whole url ex. www.teeko.fi/etusivu // and others is giving as it should and it has inputted ex. /etusivu $(this).attr('href', '/#'+$(this).attr('href').replace(url,'')); /// IE FIX } else $(this).attr('href', '/#'+$(this).attr('href')); // add click events to the hrefs //$(this).click(function(event){event.preventDefault();}); } }); } }, start: function(dest) { this.changeLinks(dest); clearInterval(this.int); this.int = setInterval('hash.check()',30); } } $(document).ready(function(){hash.check();hash.start(document);});