From 9a75d7ae73857d0caef47463a880a85f08800a38 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 9 May 2008 20:59:08 +0000 Subject: [PATCH] Pluck a few more KB of crap out of wikibits.js -- break out prefs.js for Special:Preferences --- includes/DefaultSettings.php | 2 +- includes/SpecialPreferences.php | 1 + skins/common/prefs.js | 119 ++++++++++++++++++++++++++++++++ skins/common/wikibits.js | 118 ------------------------------- 4 files changed, 121 insertions(+), 119 deletions(-) create mode 100644 skins/common/prefs.js diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 81a71491c3..14b25a4bb1 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1347,7 +1347,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '143'; +$wgStyleVersion = '144'; # Server-side caching: diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index c9ab9a7ac4..2c48252ca4 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -525,6 +525,7 @@ class PreferencesForm { $wgOut->setPageTitle( wfMsg( 'preferences' ) ); $wgOut->setArticleRelated( false ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->addScriptFile( 'prefs.js' ); $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc. diff --git a/skins/common/prefs.js b/skins/common/prefs.js new file mode 100644 index 0000000000..a6b3337515 --- /dev/null +++ b/skins/common/prefs.js @@ -0,0 +1,119 @@ + +// generate toc from prefs form, fold sections +// XXX: needs testing on IE/Mac and safari +// more comments to follow +function tabbedprefs() { + var prefform = document.getElementById('preferences'); + if (!prefform || !document.createElement) { + return; + } + if (prefform.nodeName.toLowerCase() == 'a') { + return; // Occasional IE problem + } + prefform.className = prefform.className + 'jsprefs'; + var sections = []; + var children = prefform.childNodes; + var seci = 0; + for (var i = 0; i < children.length; i++) { + if (children[i].nodeName.toLowerCase() == 'fieldset') { + children[i].id = 'prefsection-' + seci; + children[i].className = 'prefsection'; + if (is_opera || is_khtml) { + children[i].className = 'prefsection operaprefsection'; + } + var legends = children[i].getElementsByTagName('legend'); + sections[seci] = {}; + legends[0].className = 'mainLegend'; + if (legends[0] && legends[0].firstChild.nodeValue) { + sections[seci].text = legends[0].firstChild.nodeValue; + } else { + sections[seci].text = '# ' + seci; + } + sections[seci].secid = children[i].id; + seci++; + if (sections.length != 1) { + children[i].style.display = 'none'; + } else { + var selectedid = children[i].id; + } + } + } + var toc = document.createElement('ul'); + toc.id = 'preftoc'; + toc.selectedid = selectedid; + for (i = 0; i < sections.length; i++) { + var li = document.createElement('li'); + if (i === 0) { + li.className = 'selected'; + } + var a = document.createElement('a'); + a.href = '#' + sections[i].secid; + a.onmousedown = a.onclick = uncoversection; + a.appendChild(document.createTextNode(sections[i].text)); + a.secid = sections[i].secid; + li.appendChild(a); + toc.appendChild(li); + } + prefform.parentNode.insertBefore(toc, prefform.parentNode.childNodes[0]); + document.getElementById('prefsubmit').id = 'prefcontrol'; +} + +function uncoversection() { + var oldsecid = this.parentNode.parentNode.selectedid; + var newsec = document.getElementById(this.secid); + if (oldsecid != this.secid) { + var ul = document.getElementById('preftoc'); + document.getElementById(oldsecid).style.display = 'none'; + newsec.style.display = 'block'; + ul.selectedid = this.secid; + var lis = ul.getElementsByTagName('li'); + for (var i = 0; i< lis.length; i++) { + lis[i].className = ''; + } + this.parentNode.className = 'selected'; + } + return false; +} + +// Timezone stuff +// tz in format [+-]HHMM +function checkTimezone(tz, msg) { + var localclock = new Date(); + // returns negative offset from GMT in minutes + var tzRaw = localclock.getTimezoneOffset(); + var tzHour = Math.floor( Math.abs(tzRaw) / 60); + var tzMin = Math.abs(tzRaw) % 60; + var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin; + if (tz != tzString) { + var junk = msg.split('$1'); + document.write(junk[0] + "UTC" + tzString + junk[1]); + } +} + +function unhidetzbutton() { + var tzb = document.getElementById('guesstimezonebutton'); + if (tzb) { + tzb.style.display = 'inline'; + } +} + +// in [-]HH:MM format... +// won't yet work with non-even tzs +function fetchTimezone() { + // FIXME: work around Safari bug + var localclock = new Date(); + // returns negative offset from GMT in minutes + var tzRaw = localclock.getTimezoneOffset(); + var tzHour = Math.floor( Math.abs(tzRaw) / 60); + var tzMin = Math.abs(tzRaw) % 60; + var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour + + ":" + ((tzMin < 10) ? "0" : "") + tzMin; + return tzString; +} + +function guessTimezone(box) { + document.getElementsByName("wpHourDiff")[0].value = fetchTimezone(); +} + +hookEvent("load", unhidetzbutton); +hookEvent("load", tabbedprefs); diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index c16c9246e1..839e624523 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -76,122 +76,6 @@ function toggleVisibility(_levelId, _otherId, _linkId) { } } -// generate toc from prefs form, fold sections -// XXX: needs testing on IE/Mac and safari -// more comments to follow -function tabbedprefs() { - var prefform = document.getElementById('preferences'); - if (!prefform || !document.createElement) { - return; - } - if (prefform.nodeName.toLowerCase() == 'a') { - return; // Occasional IE problem - } - prefform.className = prefform.className + 'jsprefs'; - var sections = []; - var children = prefform.childNodes; - var seci = 0; - for (var i = 0; i < children.length; i++) { - if (children[i].nodeName.toLowerCase() == 'fieldset') { - children[i].id = 'prefsection-' + seci; - children[i].className = 'prefsection'; - if (is_opera || is_khtml) { - children[i].className = 'prefsection operaprefsection'; - } - var legends = children[i].getElementsByTagName('legend'); - sections[seci] = {}; - legends[0].className = 'mainLegend'; - if (legends[0] && legends[0].firstChild.nodeValue) { - sections[seci].text = legends[0].firstChild.nodeValue; - } else { - sections[seci].text = '# ' + seci; - } - sections[seci].secid = children[i].id; - seci++; - if (sections.length != 1) { - children[i].style.display = 'none'; - } else { - var selectedid = children[i].id; - } - } - } - var toc = document.createElement('ul'); - toc.id = 'preftoc'; - toc.selectedid = selectedid; - for (i = 0; i < sections.length; i++) { - var li = document.createElement('li'); - if (i === 0) { - li.className = 'selected'; - } - var a = document.createElement('a'); - a.href = '#' + sections[i].secid; - a.onmousedown = a.onclick = uncoversection; - a.appendChild(document.createTextNode(sections[i].text)); - a.secid = sections[i].secid; - li.appendChild(a); - toc.appendChild(li); - } - prefform.parentNode.insertBefore(toc, prefform.parentNode.childNodes[0]); - document.getElementById('prefsubmit').id = 'prefcontrol'; -} - -function uncoversection() { - var oldsecid = this.parentNode.parentNode.selectedid; - var newsec = document.getElementById(this.secid); - if (oldsecid != this.secid) { - var ul = document.getElementById('preftoc'); - document.getElementById(oldsecid).style.display = 'none'; - newsec.style.display = 'block'; - ul.selectedid = this.secid; - var lis = ul.getElementsByTagName('li'); - for (var i = 0; i< lis.length; i++) { - lis[i].className = ''; - } - this.parentNode.className = 'selected'; - } - return false; -} - -// Timezone stuff -// tz in format [+-]HHMM -function checkTimezone(tz, msg) { - var localclock = new Date(); - // returns negative offset from GMT in minutes - var tzRaw = localclock.getTimezoneOffset(); - var tzHour = Math.floor( Math.abs(tzRaw) / 60); - var tzMin = Math.abs(tzRaw) % 60; - var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin; - if (tz != tzString) { - var junk = msg.split('$1'); - document.write(junk[0] + "UTC" + tzString + junk[1]); - } -} - -function unhidetzbutton() { - var tzb = document.getElementById('guesstimezonebutton'); - if (tzb) { - tzb.style.display = 'inline'; - } -} - -// in [-]HH:MM format... -// won't yet work with non-even tzs -function fetchTimezone() { - // FIXME: work around Safari bug - var localclock = new Date(); - // returns negative offset from GMT in minutes - var tzRaw = localclock.getTimezoneOffset(); - var tzHour = Math.floor( Math.abs(tzRaw) / 60); - var tzMin = Math.abs(tzRaw) % 60; - var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour + - ":" + ((tzMin < 10) ? "0" : "") + tzMin; - return tzString; -} - -function guessTimezone(box) { - document.getElementsByName("wpHourDiff")[0].value = fetchTimezone(); -} - function showTocToggle() { if (document.createTextNode) { // Uses DOM calls to avoid document.write + XHTML issues @@ -1127,8 +1011,6 @@ function runOnloadHook() { // might cause the function to terminate prematurely doneOnloadHook = true; - unhidetzbutton(); - tabbedprefs(); updateTooltipAccessKeys( null ); akeytt( null ); scrollEditBox(); -- 2.20.1