Team:RHIT/static/wiki.js
From 2012.igem.org
(Difference between revisions)
(One intermediate revision not shown) | |||
Line 56: | Line 56: | ||
return /\/Team:RHIT/i.test($(obj).attr("href")); | return /\/Team:RHIT/i.test($(obj).attr("href")); | ||
} | } | ||
+ | |||
var is_external = function(obj) { return !is_internal(obj);} | var is_external = function(obj) { return !is_internal(obj);} | ||
Line 61: | Line 62: | ||
if((window.location.hash == '') || (window.location.hash == undefined) || !(window.location.hash.charAt(1) == '/')) | if((window.location.hash == '') || (window.location.hash == undefined) || !(window.location.hash.charAt(1) == '/')) | ||
{ | { | ||
- | |||
set_hash(the_url); | set_hash(the_url); | ||
- | |||
- | |||
- | |||
} | } | ||
else | else | ||
Line 93: | Line 90: | ||
$(window).ready(function() { | $(window).ready(function() { | ||
- | |||
- | |||
var login = get_login(); | var login = get_login(); | ||
set_login(login); | set_login(login); | ||
}); | }); |
Latest revision as of 14:27, 19 July 2012
var area = 'overview';
var subarea = 'home'; //the url that's loaded
var the_url = window.location.pathname; //the url that's being displayed
var int; //the interval
var set_hash = function(path) {//set the hash to the path given
int = window.clearInterval(int); //turn the path into a presentable hash var hash = path.replace(/http:\/\/2011.igem.org/i, ).replace(/\/Team:RHIT/i, ); window.location.hash = hash; the_url = get_hash(false); int = setInterval('check_hash();', 500);
}
var get_hash = function(absolute) {
var hash = window.location.hash.substr(1); if(!absolute || (absolute == undefined)) return "/Team:RHIT" + hash; return "https://2011.igem.org/Team:RHIT" + hash;
}
var check_hash = function() {//check if the hash has changed (e.g. back button press)
if(the_url != get_hash(false)) { int = clearInterval(int);//pause if((window.location.hash.charAt(1) == '/') || (window.location.hash == )) load_url(get_hash(false)); int = setInterval('check_hash();', 500); }
}
//update the edit, login and logout links after page change var update_links = function(current_url) {
$('#edit-link').attr('href', current_url + '?action=edit'); $('#edit-intro-link').attr('href', '/Team:RHIT/desc/' + area + '/' + subarea + '?action=edit'); $('#login-link' ).attr('href', '/wiki/index.php?title=Special:UserLogin&returnto=' + current_url); $('#logout-link').attr('href', '/wiki/index.php?title=Special:UserLogout&returnto=' + current_url);
}
var is_internal = function(obj) {
if($(obj).hasClass('RHIT-external')) return false; return /\/Team:RHIT/i.test($(obj).attr("href"));
}
var is_external = function(obj) { return !is_internal(obj);}
var wiki_main = function() {
if((window.location.hash == ) || (window.location.hash == undefined) || !(window.location.hash.charAt(1) == '/')) { set_hash(the_url); } else { load_url(get_hash()); }
}
var get_login = function() { var page = $('#menubar.right-menu').find('#pt-userpage'); if(page.length == 0) return undefined; return page.children('a').text(); }
var set_login = function(username) { if(username != undefined) { $('#user-link').text(username).attr('href', '/User:' + username); $('#edit-link').text('Edit Page'); $('#edit-intro-link').text('Edit Introduction'); $('#logged_out').hide(); $('#logged_in').show(); } }
$(window).ready(function() {
var login = get_login(); set_login(login);
});