MediaWiki:Common.js: Difference between revisions
From Bulbanews, your community Pokémon newspaper.
Jump to navigationJump to search
m (yayz) |
m (this is a test...) |
||
Line 146: | Line 146: | ||
} | } | ||
function createContentTabs() { | |||
var ict=0; var ctdiv; var tabs; var toggle;var firstTab;var firstToggle; | |||
var divs = document.getElementsByTagName("div"); | |||
for (var i=0; i<divs.length; i++) { | |||
ctdiv = divs[i]; | |||
if (ctdiv.className == "Tabs") { | |||
ict++; | |||
//alert("tab for div i "+i + " ict="+ict); | |||
if (document.getElementById("ct_"+ict)) continue; | |||
ctdiv.parentNode.id = "ct_"+ict; | |||
tabs = ctdiv.childNodes; | |||
for (var j=0; j < tabs.length; j++) { | |||
var tab = tabs[j]; | |||
var toggle = document.createElement("a"); | |||
var tabName = tab.className; | |||
if (!tabName) continue; | |||
//toggle.setAttribute('href', 'javascript:toggleTab(this,\''+'ct_'+ict+'\', \'' + tabName + '\',0);'); | |||
toggle.setAttribute('href', 'javascript:void(0)'); | |||
toggle.setAttribute('onclick', 'toggleTab(this,\''+'ct_'+ict+'\', \'' + tabName + '\',0);'); | |||
var spLabel = tab.innerHTML; | |||
if (!spLabel) continue; | |||
toggle.innerHTML = spLabel; | |||
if (!firstTab) { | |||
firstTab = tabName; | |||
toggle.setAttribute('id','ct_'+ict+'_first'); | |||
//toggle.setAttribute('class',"first"); | |||
} | |||
ctdiv.appendChild(toggle); | |||
ctdiv.removeChild(tab); | |||
} | |||
toggleTab(1,'ct_'+ict, firstTab,1); | |||
firstTab=null; | |||
} | |||
} | |||
} | |||
function toggleTab(elem,ct_id,tab_id,first) { | |||
//alert("in "+ct_id+ " hiding all but " +tab_id + " sender: "+elem); | |||
var ctdiv = document.getElementById(ct_id); | |||
for (var i=0; i < ctdiv.childNodes.length;i++) { | |||
if (ctdiv.childNodes[i].className=="Contents") { | |||
var contentdiv = ctdiv.childNodes[i]; | |||
for (var j=0; j <contentdiv.childNodes.length;j++) { | |||
if (contentdiv.childNodes[j].style) contentdiv.childNodes[j].style.display = "none"; | |||
} | |||
} | |||
if (ctdiv.childNodes[i].className=="Tabs") { | |||
var contentdiv = ctdiv.childNodes[i]; | |||
for (var j=0; j <contentdiv.childNodes.length;j++) { | |||
if (contentdiv.childNodes[j].className){ | |||
contentdiv.childNodes[j].className = ""; | |||
} | |||
} | |||
if (first) contentdiv.childNodes[0].className = "active"; | |||
} | |||
} | |||
if (document.getElementById(tab_id).style) { | |||
//alert("setting style of id "+tab_id); | |||
document.getElementById(tab_id).style.display = "block"; | |||
if (!first) elem.className = "active"; | |||
} | |||
} | |||
addOnloadHook(createNavigationBarToggleButton); | |||
addOnloadHook(createSpoiler); | |||
addOnloadHook(createContentTabs); | |||
/* </pre> */ | /* </pre> */ |
Revision as of 19:32, 18 July 2009
/* <pre> */ /* Any JavaScript here will be loaded for all users on every page load. */ if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 ) { var script = document.createElement( 'script' ); script.src = '/w/index.php?title=User:Poke/CollapsibleTables.js&action=raw&ctype=text/javascript'; script.type = 'text/javascript'; document.getElementsByTagName( 'head' )[0].appendChild( script ); hookEvent( 'load', function() { new CollapsibleTables(); } ); } function formatDate(t) { var month = new Array(); month[0] = 'January'; month[1] = 'February'; month[2] = 'March'; month[3] = 'April'; month[4] = 'May'; month[5] = 'June'; month[6] = 'July'; month[7] = 'August'; month[8] = 'September'; month[9] = 'October'; month[10] = 'November'; month[11] = 'December'; y = t.getUTCFullYear(); M = t.getUTCMonth(); D = t.getUTCDate(); h = t.getUTCHours(); m = t.getUTCMinutes(); s = t.getUTCSeconds(); if (h > 0 || m > 0 || s > 0) { hms = ''; if (s > 10) hms = ':' + s; else if (s > 0) hms = ':0' + s; if (m > 10) hms = ':' + m + hms; else if (m > 0) hms = ':0' + m + hms; if (h > 12) hms = (h - 12) + hms + ' PM'; else if (h > 0) hms = h + hms + ' AM'; else hms = '12' + hms + ' AM'; return hms + ', ' + month[M] + ' ' + D + ', ' + y; } else { return month[M] + ' ' + D + ', ' + y; } } function formatTime(h, m, s) { var o = ''; if (h != 1) { o = h + ' hours '; } else { o = '1 hour '; } if (m != 1) { o += m + ' minutes '; } else { o += '1 minute '; } if (s != 1) { o += s + ' seconds'; } else { o += '1 second'; } return o; } function updateClocks() { var t = new Date(); setTimeout(updateClocks, 1000); D = t.getUTCDate(); M = t.getUTCMonth(); y = t.getUTCFullYear(); h = t.getUTCHours(); m = t.getUTCMinutes(); s = t.getUTCSeconds(); t = Date.UTC(y, M, D, h, m, s); t = (T - t) / 1000; if (t < 0 && t > -86400 && (h > 0 || m > 0 || s > 0)) { document.getElementById('countdown-big').innerHTML = 'Today'; document.getElementById('countdown-small').innerHTML = ''; document.getElementById('countdown-target').innerHTML = 'is ' + formatDate(new Date(T + tzOffset)) + ' ' + tz; return; } else if (t < 0) { document.getElementById('countdown-big').innerHTML = 'Past'; document.getElementById('countdown-target').innerHTML = formatDate(new Date(T + tzOffset)) + ' ' + tz; return; } D = Math.floor(t / 86400.0); h = Math.floor(t % 86400.0 / 3600.0); m = Math.floor(t % 3600.0 / 60.0); s = Math.floor(t % 60.0) if (D == 1) { document.getElementById('countdown-big').innerHTML = '1 day'; } else if (D == 0) { document.getElementById('countdown-big').innerHTML = ''; } else { document.getElementById('countdown-big').innerHTML = D + ' days'; } document.getElementById('countdown-small').innerHTML = formatTime(h, m, s); } function startCountdown() { document.getElementById('countdown-target').innerHTML = 'to ' + formatDate(new Date(T + tzOffset)) + ' ' + tz; document.getElementById('countdown').style.display = 'block'; updateClocks(); } function createContentTabs() { var ict=0; var ctdiv; var tabs; var toggle;var firstTab;var firstToggle; var divs = document.getElementsByTagName("div"); for (var i=0; i<divs.length; i++) { ctdiv = divs[i]; if (ctdiv.className == "Tabs") { ict++; //alert("tab for div i "+i + " ict="+ict); if (document.getElementById("ct_"+ict)) continue; ctdiv.parentNode.id = "ct_"+ict; tabs = ctdiv.childNodes; for (var j=0; j < tabs.length; j++) { var tab = tabs[j]; var toggle = document.createElement("a"); var tabName = tab.className; if (!tabName) continue; //toggle.setAttribute('href', 'javascript:toggleTab(this,\''+'ct_'+ict+'\', \'' + tabName + '\',0);'); toggle.setAttribute('href', 'javascript:void(0)'); toggle.setAttribute('onclick', 'toggleTab(this,\''+'ct_'+ict+'\', \'' + tabName + '\',0);'); var spLabel = tab.innerHTML; if (!spLabel) continue; toggle.innerHTML = spLabel; if (!firstTab) { firstTab = tabName; toggle.setAttribute('id','ct_'+ict+'_first'); //toggle.setAttribute('class',"first"); } ctdiv.appendChild(toggle); ctdiv.removeChild(tab); } toggleTab(1,'ct_'+ict, firstTab,1); firstTab=null; } } } function toggleTab(elem,ct_id,tab_id,first) { //alert("in "+ct_id+ " hiding all but " +tab_id + " sender: "+elem); var ctdiv = document.getElementById(ct_id); for (var i=0; i < ctdiv.childNodes.length;i++) { if (ctdiv.childNodes[i].className=="Contents") { var contentdiv = ctdiv.childNodes[i]; for (var j=0; j <contentdiv.childNodes.length;j++) { if (contentdiv.childNodes[j].style) contentdiv.childNodes[j].style.display = "none"; } } if (ctdiv.childNodes[i].className=="Tabs") { var contentdiv = ctdiv.childNodes[i]; for (var j=0; j <contentdiv.childNodes.length;j++) { if (contentdiv.childNodes[j].className){ contentdiv.childNodes[j].className = ""; } } if (first) contentdiv.childNodes[0].className = "active"; } } if (document.getElementById(tab_id).style) { //alert("setting style of id "+tab_id); document.getElementById(tab_id).style.display = "block"; if (!first) elem.className = "active"; } } addOnloadHook(createNavigationBarToggleButton); addOnloadHook(createSpoiler); addOnloadHook(createContentTabs); /* </pre> */