1 // MediaWiki JavaScript support functions
3 var clientPC
= navigator
.userAgent
.toLowerCase(); // Get client info
4 var is_gecko
= ((clientPC
.indexOf('gecko')!=-1) && (clientPC
.indexOf('spoofer')==-1)
5 && (clientPC
.indexOf('khtml') == -1) && (clientPC
.indexOf('netscape/7.0')==-1));
6 var is_safari
= ((clientPC
.indexOf('applewebkit')!=-1) && (clientPC
.indexOf('spoofer')==-1));
7 var is_khtml
= (navigator
.vendor
== 'KDE' || ( document
.childNodes
&& !document
.all
&& !navigator
.taintEnabled
));
9 var is_ff2_win
= (clientPC
.indexOf('firefox/2')!=-1 || clientPC
.indexOf('minefield/3')!=-1) && clientPC
.indexOf('windows')!=-1;
10 var is_ff2_x11
= (clientPC
.indexOf('firefox/2')!=-1 || clientPC
.indexOf('minefield/3')!=-1) && clientPC
.indexOf('x11')!=-1;
11 if (clientPC
.indexOf('opera') != -1) {
13 var is_opera_preseven
= (window
.opera
&& !document
.childNodes
);
14 var is_opera_seven
= (window
.opera
&& document
.childNodes
);
17 // Global external objects used by this script.
18 /*extern ta, stylepath, skin */
20 // add any onload functions in this hook (please don't hard-code any events in the xhtml source)
23 if (!window
.onloadFuncts
) {
24 var onloadFuncts
= [];
27 function addOnloadHook(hookFunct
) {
28 // Allows add-on scripts to add onload functions
29 onloadFuncts
[onloadFuncts
.length
] = hookFunct
;
32 function hookEvent(hookName
, hookFunct
) {
33 if (window
.addEventListener
) {
34 window
.addEventListener(hookName
, hookFunct
, false);
35 } else if (window
.attachEvent
) {
36 window
.attachEvent("on" + hookName
, hookFunct
);
40 // document.write special stylesheet links
41 if (typeof stylepath
!= 'undefined' && typeof skin
!= 'undefined') {
42 if (is_opera_preseven
) {
43 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'/'+skin
+'/Opera6Fixes.css">');
44 } else if (is_opera_seven
) {
45 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'/'+skin
+'/Opera7Fixes.css">');
46 } else if (is_khtml
) {
47 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'/'+skin
+'/KHTMLFixes.css">');
52 // Un-trap us from framesets
53 if (window
.top
!= window
) {
54 window
.top
.location
= window
.location
;
58 // for enhanced RecentChanges
59 function toggleVisibility(_levelId
, _otherId
, _linkId
) {
60 var thisLevel
= document
.getElementById(_levelId
);
61 var otherLevel
= document
.getElementById(_otherId
);
62 var linkLevel
= document
.getElementById(_linkId
);
63 if (thisLevel
.style
.display
== 'none') {
64 thisLevel
.style
.display
= 'block';
65 otherLevel
.style
.display
= 'none';
66 linkLevel
.style
.display
= 'inline';
68 thisLevel
.style
.display
= 'none';
69 otherLevel
.style
.display
= 'inline';
70 linkLevel
.style
.display
= 'none';
74 function historyRadios(parent
) {
75 var inputs
= parent
.getElementsByTagName('input');
77 for (var i
= 0; i
< inputs
.length
; i
++) {
78 if (inputs
[i
].name
== "diff" || inputs
[i
].name
== "oldid") {
79 radios
[radios
.length
] = inputs
[i
];
85 // check selection and tweak visibility/class onclick
86 function diffcheck() {
87 var dli
= false; // the li where the diff radio is checked
88 var oli
= false; // the li where the oldid radio is checked
89 var hf
= document
.getElementById('pagehistory');
93 var lis
= hf
.getElementsByTagName('li');
94 for (var i
=0;i
<lis
.length
;i
++) {
95 var inputs
= historyRadios(lis
[i
]);
96 if (inputs
[1] && inputs
[0]) {
97 if (inputs
[1].checked
|| inputs
[0].checked
) { // this row has a checked radio button
98 if (inputs
[1].checked
&& inputs
[0].checked
&& inputs
[0].value
== inputs
[1].value
) {
101 if (oli
) { // it's the second checked radio
102 if (inputs
[1].checked
) {
103 oli
.className
= "selected";
106 } else if (inputs
[0].checked
) {
109 if (inputs
[0].checked
) {
113 inputs
[0].style
.visibility
= 'hidden';
116 inputs
[1].style
.visibility
= 'hidden';
118 lis
[i
].className
= "selected";
120 } else { // no radio is checked in this row
122 inputs
[0].style
.visibility
= 'hidden';
124 inputs
[0].style
.visibility
= 'visible';
127 inputs
[1].style
.visibility
= 'hidden';
129 inputs
[1].style
.visibility
= 'visible';
131 lis
[i
].className
= "";
138 // page history stuff
139 // attach event handlers to the input elements on history page
140 function histrowinit() {
141 var hf
= document
.getElementById('pagehistory');
145 var lis
= hf
.getElementsByTagName('li');
146 for (var i
= 0; i
< lis
.length
; i
++) {
147 var inputs
= historyRadios(lis
[i
]);
148 if (inputs
[0] && inputs
[1]) {
149 inputs
[0].onclick
= diffcheck
;
150 inputs
[1].onclick
= diffcheck
;
156 // generate toc from prefs form, fold sections
157 // XXX: needs testing on IE/Mac and safari
158 // more comments to follow
159 function tabbedprefs() {
160 var prefform
= document
.getElementById('preferences');
161 if (!prefform
|| !document
.createElement
) {
164 if (prefform
.nodeName
.toLowerCase() == 'a') {
165 return; // Occasional IE problem
167 prefform
.className
= prefform
.className
+ 'jsprefs';
169 var children
= prefform
.childNodes
;
171 for (var i
= 0; i
< children
.length
; i
++) {
172 if (children
[i
].nodeName
.toLowerCase() == 'fieldset') {
173 children
[i
].id
= 'prefsection-' + seci
;
174 children
[i
].className
= 'prefsection';
175 if (is_opera
|| is_khtml
) {
176 children
[i
].className
= 'prefsection operaprefsection';
178 var legends
= children
[i
].getElementsByTagName('legend');
180 legends
[0].className
= 'mainLegend';
181 if (legends
[0] && legends
[0].firstChild
.nodeValue
) {
182 sections
[seci
].text
= legends
[0].firstChild
.nodeValue
;
184 sections
[seci
].text
= '# ' + seci
;
186 sections
[seci
].secid
= children
[i
].id
;
188 if (sections
.length
!= 1) {
189 children
[i
].style
.display
= 'none';
191 var selectedid
= children
[i
].id
;
195 var toc
= document
.createElement('ul');
197 toc
.selectedid
= selectedid
;
198 for (i
= 0; i
< sections
.length
; i
++) {
199 var li
= document
.createElement('li');
201 li
.className
= 'selected';
203 var a
= document
.createElement('a');
204 a
.href
= '#' + sections
[i
].secid
;
205 a
.onmousedown
= a
.onclick
= uncoversection
;
206 a
.appendChild(document
.createTextNode(sections
[i
].text
));
207 a
.secid
= sections
[i
].secid
;
211 prefform
.parentNode
.insertBefore(toc
, prefform
.parentNode
.childNodes
[0]);
212 document
.getElementById('prefsubmit').id
= 'prefcontrol';
215 function uncoversection() {
216 var oldsecid
= this.parentNode
.parentNode
.selectedid
;
217 var newsec
= document
.getElementById(this.secid
);
218 if (oldsecid
!= this.secid
) {
219 var ul
= document
.getElementById('preftoc');
220 document
.getElementById(oldsecid
).style
.display
= 'none';
221 newsec
.style
.display
= 'block';
222 ul
.selectedid
= this.secid
;
223 var lis
= ul
.getElementsByTagName('li');
224 for (var i
= 0; i
< lis
.length
; i
++) {
225 lis
[i
].className
= '';
227 this.parentNode
.className
= 'selected';
233 // tz in format [+-]HHMM
234 function checkTimezone(tz
, msg
) {
235 var localclock
= new Date();
236 // returns negative offset from GMT in minutes
237 var tzRaw
= localclock
.getTimezoneOffset();
238 var tzHour
= Math
.floor( Math
.abs(tzRaw
) / 60);
239 var tzMin
= Math
.abs(tzRaw
) % 60;
240 var tzString
= ((tzRaw
>= 0) ? "-" : "+") + ((tzHour
< 10) ? "0" : "") + tzHour
+ ((tzMin
< 10) ? "0" : "") + tzMin
;
241 if (tz
!= tzString
) {
242 var junk
= msg
.split('$1');
243 document
.write(junk
[0] + "UTC" + tzString
+ junk
[1]);
247 function unhidetzbutton() {
248 var tzb
= document
.getElementById('guesstimezonebutton');
250 tzb
.style
.display
= 'inline';
254 // in [-]HH:MM format...
255 // won't yet work with non-even tzs
256 function fetchTimezone() {
257 // FIXME: work around Safari bug
258 var localclock
= new Date();
259 // returns negative offset from GMT in minutes
260 var tzRaw
= localclock
.getTimezoneOffset();
261 var tzHour
= Math
.floor( Math
.abs(tzRaw
) / 60);
262 var tzMin
= Math
.abs(tzRaw
) % 60;
263 var tzString
= ((tzRaw
>= 0) ? "-" : "") + ((tzHour
< 10) ? "0" : "") + tzHour
+
264 ":" + ((tzMin
< 10) ? "0" : "") + tzMin
;
268 function guessTimezone(box
) {
269 document
.getElementsByName("wpHourDiff")[0].value
= fetchTimezone();
272 function showTocToggle() {
273 if (document
.createTextNode
) {
274 // Uses DOM calls to avoid document.write + XHTML issues
276 var linkHolder
= document
.getElementById('toctitle');
281 var outerSpan
= document
.createElement('span');
282 outerSpan
.className
= 'toctoggle';
284 var toggleLink
= document
.createElement('a');
285 toggleLink
.id
= 'togglelink';
286 toggleLink
.className
= 'internal';
287 toggleLink
.href
= 'javascript:toggleToc()';
288 toggleLink
.appendChild(document
.createTextNode(tocHideText
));
290 outerSpan
.appendChild(document
.createTextNode('['));
291 outerSpan
.appendChild(toggleLink
);
292 outerSpan
.appendChild(document
.createTextNode(']'));
294 linkHolder
.appendChild(document
.createTextNode(' '));
295 linkHolder
.appendChild(outerSpan
);
297 var cookiePos
= document
.cookie
.indexOf("hidetoc=");
298 if (cookiePos
> -1 && document
.cookie
.charAt(cookiePos
+ 8) == 1) {
304 function changeText(el
, newText
) {
305 // Safari work around
307 el
.innerText
= newText
;
308 } else if (el
.firstChild
&& el
.firstChild
.nodeValue
) {
309 el
.firstChild
.nodeValue
= newText
;
313 function toggleToc() {
314 var toc
= document
.getElementById('toc').getElementsByTagName('ul')[0];
315 var toggleLink
= document
.getElementById('togglelink');
317 if (toc
&& toggleLink
&& toc
.style
.display
== 'none') {
318 changeText(toggleLink
, tocHideText
);
319 toc
.style
.display
= 'block';
320 document
.cookie
= "hidetoc=0";
322 changeText(toggleLink
, tocShowText
);
323 toc
.style
.display
= 'none';
324 document
.cookie
= "hidetoc=1";
328 var mwEditButtons
= [];
329 var mwCustomEditButtons
= []; // eg to add in MediaWiki:Common.js
331 // this function generates the actual toolbar buttons with localized text
332 // we use it to avoid creating the toolbar where javascript is not enabled
333 function addButton(imageFile
, speedTip
, tagOpen
, tagClose
, sampleText
) {
334 // Don't generate buttons for browsers which don't fully
336 mwEditButtons
[mwEditButtons
.length
] =
337 {"imageFile": imageFile
,
338 "speedTip": speedTip
,
340 "tagClose": tagClose
,
341 "sampleText": sampleText
};
344 // this function generates the actual toolbar buttons with localized text
345 // we use it to avoid creating the toolbar where javascript is not enabled
346 function mwInsertEditButton(parent
, item
) {
347 var image
= document
.createElement("img");
350 image
.src
= item
.imageFile
;
352 image
.alt
= item
.speedTip
;
353 image
.title
= item
.speedTip
;
354 image
.style
.cursor
= "pointer";
355 image
.onclick = function() {
356 insertTags(item
.tagOpen
, item
.tagClose
, item
.sampleText
);
360 parent
.appendChild(image
);
364 function mwSetupToolbar() {
365 var toolbar
= document
.getElementById('toolbar');
366 if (!toolbar
) { return false; }
368 var textbox
= document
.getElementById('wpTextbox1');
369 if (!textbox
) { return false; }
371 // Don't generate buttons for browsers which don't fully
373 if (!document
.selection
&& textbox
.selectionStart
=== null) {
377 for (var i
in mwEditButtons
) {
378 mwInsertEditButton(toolbar
, mwEditButtons
[i
]);
380 for (i
in mwCustomEditButtons
) {
381 mwInsertEditButton(toolbar
, mwCustomEditButtons
[i
]);
386 function escapeQuotes(text
) {
387 var re
= new RegExp("'","g");
388 text
= text
.replace(re
,"\\'");
389 re
= new RegExp("\\n","g");
390 text
= text
.replace(re
,"\\n");
391 return escapeQuotesHTML(text
);
394 function escapeQuotesHTML(text
) {
395 var re
= new RegExp('&',"g");
396 text
= text
.replace(re
,"&");
397 re
= new RegExp('"',"g");
398 text
= text
.replace(re
,""");
399 re
= new RegExp('<',"g");
400 text
= text
.replace(re
,"<");
401 re
= new RegExp('>',"g");
402 text
= text
.replace(re
,">");
406 // apply tagOpen/tagClose to selection in textarea,
407 // use sampleText instead of selection if there is none
408 // copied and adapted from phpBB
409 function insertTags(tagOpen
, tagClose
, sampleText
) {
411 if (document
.editform
) {
412 txtarea
= document
.editform
.wpTextbox1
;
414 // some alternate form? take the first one we can find
415 var areas
= document
.getElementsByTagName('textarea');
420 if (document
.selection
&& !is_gecko
) {
421 var theSelection
= document
.selection
.createRange().text
;
423 theSelection
=sampleText
;
426 if (theSelection
.charAt(theSelection
.length
- 1) == " ") { // exclude ending space char, if any
427 theSelection
= theSelection
.substring(0, theSelection
.length
- 1);
428 document
.selection
.createRange().text
= tagOpen
+ theSelection
+ tagClose
+ " ";
430 document
.selection
.createRange().text
= tagOpen
+ theSelection
+ tagClose
;
434 } else if(txtarea
.selectionStart
|| txtarea
.selectionStart
== '0') {
435 var replaced
= false;
436 var startPos
= txtarea
.selectionStart
;
437 var endPos
= txtarea
.selectionEnd
;
438 if (endPos
-startPos
) {
441 var scrollTop
= txtarea
.scrollTop
;
442 var myText
= (txtarea
.value
).substring(startPos
, endPos
);
447 if (myText
.charAt(myText
.length
- 1) == " ") { // exclude ending space char, if any
448 subst
= tagOpen
+ myText
.substring(0, (myText
.length
- 1)) + tagClose
+ " ";
450 subst
= tagOpen
+ myText
+ tagClose
;
452 txtarea
.value
= txtarea
.value
.substring(0, startPos
) + subst
+
453 txtarea
.value
.substring(endPos
, txtarea
.value
.length
);
457 var cPos
= startPos
+(tagOpen
.length
+myText
.length
+tagClose
.length
);
458 txtarea
.selectionStart
= cPos
;
459 txtarea
.selectionEnd
= cPos
;
461 txtarea
.selectionStart
= startPos
+tagOpen
.length
;
462 txtarea
.selectionEnd
= startPos
+tagOpen
.length
+myText
.length
;
464 txtarea
.scrollTop
= scrollTop
;
466 // All other browsers get no toolbar.
467 // There was previously support for a crippled "help"
468 // bar, but that caused more problems than it solved.
470 // reposition cursor if possible
471 if (txtarea
.createTextRange
) {
472 txtarea
.caretPos
= document
.selection
.createRange().duplicate();
478 * Set the accesskey prefix based on browser detection.
480 var tooltipAccessKeyPrefix
= 'alt-';
482 tooltipAccessKeyPrefix
= 'shift-esc-';
484 || navigator
.userAgent
.toLowerCase().indexOf('mac') != -1
485 || navigator
.userAgent
.toLowerCase().indexOf('konqueror') != -1 ) {
486 tooltipAccessKeyPrefix
= 'ctrl-';
487 } else if (is_ff2_x11
|| is_ff2_win
) {
488 tooltipAccessKeyPrefix
= 'alt-shift-';
490 var tooltipAccessKeyRegexp
= /\[(ctrl-)?(alt-)?(shift-)?(esc-)?.\]$/;
493 * Add the appropriate prefix to the accesskey shown in the tooltip.
494 * If the nodeList parameter is given, only those nodes are updated;
495 * otherwise, all the nodes that will probably have accesskeys by
496 * default are updated.
498 * @param Array nodeList -- list of elements to update
500 function updateTooltipAccessKeys( nodeList
) {
502 // skins without a "column-one" element don't seem to have links with accesskeys either
503 var columnOne
= document
.getElementById("column-one");
505 updateTooltipAccessKeys( columnOne
.getElementsByTagName("a") );
506 // these are rare enough that no such optimization is needed
507 updateTooltipAccessKeys( document
.getElementsByTagName("input") );
508 updateTooltipAccessKeys( document
.getElementsByTagName("label") );
512 for ( var i
= 0; i
< nodeList
.length
; i
++ ) {
513 var element
= nodeList
[i
];
514 var tip
= element
.getAttribute("title");
515 var key
= element
.getAttribute("accesskey");
516 if ( key
&& tooltipAccessKeyRegexp
.exec(tip
) ) {
517 tip
= tip
.replace(tooltipAccessKeyRegexp
,
518 "["+tooltipAccessKeyPrefix
+key
+"]");
519 element
.setAttribute("title", tip
);
525 * Add a link to one of the portlet menus on the page, including:
527 * p-cactions: Content actions (shown as tabs above the main content in Monobook)
528 * p-personal: Personal tools (shown at the top right of the page in Monobook)
529 * p-navigation: Navigation
532 * This function exists for the convenience of custom JS authors. All
533 * but the first three parameters are optional, though providing at
534 * least an id and a tooltip is recommended.
536 * By default the new link will be added to the end of the list. To
537 * add the link before a given existing item, pass the DOM node of
538 * that item (easily obtained with document.getElementById()) as the
539 * nextnode parameter; to add the link _after_ an existing item, pass
540 * the node's nextSibling instead.
542 * @param String portlet -- id of the target portlet ("p-cactions", "p-personal", "p-navigation" or "p-tb")
543 * @param String href -- link URL
544 * @param String text -- link text (will be automatically lowercased by CSS for p-cactions in Monobook)
545 * @param String id -- id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-")
546 * @param String tooltip -- text to show when hovering over the link, without accesskey suffix
547 * @param String accesskey -- accesskey to activate this link (one character, try to avoid conflicts)
548 * @param Node nextnode -- the DOM node before which the new item should be added, should be another item in the same list
550 * @return Node -- the DOM node of the new item (an LI element) or null
552 function addPortletLink(portlet
, href
, text
, id
, tooltip
, accesskey
, nextnode
) {
553 var node
= document
.getElementById(portlet
);
554 if ( !node
) return null;
555 node
= node
.getElementsByTagName( "ul" )[0];
556 if ( !node
) return null;
558 var link
= document
.createElement( "a" );
559 link
.appendChild( document
.createTextNode( text
) );
562 var item
= document
.createElement( "li" );
563 item
.appendChild( link
);
564 if ( id
) item
.id
= id
;
567 link
.setAttribute( "accesskey", accesskey
);
568 tooltip
+= " ["+accesskey
+"]";
571 link
.setAttribute( "title", tooltip
);
573 if ( accesskey
&& tooltip
) {
574 updateTooltipAccessKeys( new Array( link
) );
577 if ( nextnode
&& nextnode
.parentNode
== node
)
578 node
.insertBefore( item
, nextnode
);
580 node
.appendChild( item
); // IE compatibility (?)
587 * Set up accesskeys/tooltips from the deprecated ta array. If doId
588 * is specified, only set up for that id. Note that this function is
589 * deprecated and will not be supported indefinitely -- use
590 * updateTooltipAccessKey() instead.
592 * @param mixed doId string or null
594 function akeytt( doId
) {
595 // A lot of user scripts (and some of the code below) break if
596 // ta isn't defined, so we make sure it is. Explictly using
597 // window.ta avoids a "ta is not defined" error.
598 if (!window
.ta
) window
.ta
= new Array
;
600 // Make a local, possibly restricted, copy to avoid clobbering
605 ta
[doId
] = window
.ta
[doId
];
610 // Now deal with evil deprecated ta
611 var watchCheckboxExists
= document
.getElementById( 'wpWatchthis' ) ? true : false;
613 var n
= document
.getElementById(id
);
617 // Are we putting accesskey in it
618 if (ta
[id
][0].length
> 0) {
619 // Is this object a object? If not assume it's the next child.
621 if (n
.nodeName
.toLowerCase() == "a") {
626 // Don't add an accesskey for the watch tab if the watch
627 // checkbox is also available.
628 if (a
&& ((id
!= 'ca-watch' && id
!= 'ca-unwatch') || !watchCheckboxExists
)) {
629 a
.accessKey
= ta
[id
][0];
630 ak
= ' ['+tooltipAccessKeyPrefix
+ta
[id
][0]+']';
633 // We don't care what type the object is when assigning tooltip
639 a
.title
= ta
[id
][1]+ak
;
645 function setupRightClickEdit() {
646 if (document
.getElementsByTagName
) {
647 var spans
= document
.getElementsByTagName('span');
648 for (var i
= 0; i
< spans
.length
; i
++) {
650 if(el
.className
== 'editsection') {
651 addRightClickEditHandler(el
);
657 function addRightClickEditHandler(el
) {
658 for (var i
= 0; i
< el
.childNodes
.length
; i
++) {
659 var link
= el
.childNodes
[i
];
660 if (link
.nodeType
== 1 && link
.nodeName
.toLowerCase() == 'a') {
661 var editHref
= link
.getAttribute('href');
662 // find the enclosing (parent) header
663 var prev
= el
.parentNode
;
664 if (prev
&& prev
.nodeType
== 1 &&
665 prev
.nodeName
.match(/^[Hh][1-6]$/)) {
666 prev
.oncontextmenu = function(e
) {
667 if (!e
) { e
= window
.event
; }
668 // e is now the event in all browsers
670 if (e
.target
) { targ
= e
.target
; }
671 else if (e
.srcElement
) { targ
= e
.srcElement
; }
672 if (targ
.nodeType
== 3) { // defeat Safari bug
673 targ
= targ
.parentNode
;
675 // targ is now the target element
677 // We don't want to deprive the noble reader of a context menu
678 // for the section edit link, do we? (Might want to extend this
680 if (targ
.nodeName
.toLowerCase() != 'a'
681 || targ
.parentNode
.className
!= 'editsection') {
682 document
.location
= editHref
;
695 function setupCheckboxShiftClick() {
698 var inputs
= document
.getElementsByTagName('input');
699 addCheckboxClickHandlers(inputs
);
702 function addCheckboxClickHandlers(inputs
, start
) {
703 if ( !start
) start
= 0;
705 var finish
= start
+ 250;
706 if ( finish
> inputs
.length
)
707 finish
= inputs
.length
;
709 for ( var i
= start
; i
< finish
; i
++ ) {
711 if ( !cb
.type
|| cb
.type
.toLowerCase() != 'checkbox' )
713 cb
.index
= checkboxes
.push(cb
) - 1;
714 cb
.onmouseup
= checkboxMouseupHandler
;
717 if ( finish
< inputs
.length
) {
718 setTimeout( function () {
719 addCheckboxClickHandlers(inputs
, finish
);
724 function checkboxMouseupHandler(e
) {
725 if (typeof e
== 'undefined') {
728 if ( !e
.shiftKey
|| lastCheckbox
=== null ) {
729 lastCheckbox
= this.index
;
732 var endState
= !this.checked
;
733 if ( is_opera
) { // opera has already toggled the checkbox by this point
734 endState
= !endState
;
737 if ( this.index
< lastCheckbox
) {
738 start
= this.index
+ 1;
739 finish
= lastCheckbox
;
741 start
= lastCheckbox
;
742 finish
= this.index
- 1;
744 for (var i
= start
; i
<= finish
; ++i
) {
745 checkboxes
[i
].checked
= endState
;
747 lastCheckbox
= this.index
;
751 function toggle_element_activation(ida
,idb
) {
752 if (!document
.getElementById
) {
755 document
.getElementById(ida
).disabled
=true;
756 document
.getElementById(idb
).disabled
=false;
759 function toggle_element_check(ida
,idb
) {
760 if (!document
.getElementById
) {
763 document
.getElementById(ida
).checked
=true;
764 document
.getElementById(idb
).checked
=false;
767 function fillDestFilename(id
) {
768 if (!document
.getElementById
) {
771 var path
= document
.getElementById(id
).value
;
772 // Find trailing part
773 var slash
= path
.lastIndexOf('/');
774 var backslash
= path
.lastIndexOf('\\');
776 if (slash
== -1 && backslash
== -1) {
778 } else if (slash
> backslash
) {
779 fname
= path
.substring(slash
+1, 10000);
781 fname
= path
.substring(backslash
+1, 10000);
784 // Capitalise first letter and replace spaces by underscores
785 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
788 var destFile
= document
.getElementById('wpDestFile');
790 destFile
.value
= fname
;
795 function considerChangingExpiryFocus() {
796 if (!document
.getElementById
) {
799 var drop
= document
.getElementById('wpBlockExpiry');
803 var field
= document
.getElementById('wpBlockOther');
807 var opt
= drop
.value
;
808 if (opt
== 'other') {
809 field
.style
.display
= '';
811 field
.style
.display
= 'none';
815 function scrollEditBox() {
816 var editBoxEl
= document
.getElementById("wpTextbox1");
817 var scrollTopEl
= document
.getElementById("wpScrolltop");
818 var editFormEl
= document
.getElementById("editform");
820 if (editBoxEl
&& scrollTopEl
) {
821 if (scrollTopEl
.value
) { editBoxEl
.scrollTop
= scrollTopEl
.value
; }
822 editFormEl
.onsubmit = function() {
823 document
.getElementById("wpScrolltop").value
= document
.getElementById("wpTextbox1").scrollTop
;
828 hookEvent("load", scrollEditBox
);
830 var allmessages_nodelist
= false;
831 var allmessages_modified
= false;
832 var allmessages_timeout
= false;
833 var allmessages_running
= false;
835 function allmessagesmodified() {
836 allmessages_modified
= !allmessages_modified
;
840 function allmessagesfilter() {
841 if ( allmessages_timeout
)
842 window
.clearTimeout( allmessages_timeout
);
844 if ( !allmessages_running
)
845 allmessages_timeout
= window
.setTimeout( 'allmessagesfilter_do();', 500 );
848 function allmessagesfilter_do() {
849 if ( !allmessages_nodelist
)
852 var text
= document
.getElementById('allmessagesinput').value
;
853 var nodef
= allmessages_modified
;
855 allmessages_running
= true;
857 for ( var name
in allmessages_nodelist
) {
858 var nodes
= allmessages_nodelist
[name
];
859 var display
= ( name
.indexOf( text
) == -1 ? 'none' : '' );
861 for ( var i
= 0; i
< nodes
.length
; i
++)
862 nodes
[i
].style
.display
=
863 ( nodes
[i
].className
== "def" && nodef
864 ? 'none' : display
);
867 if ( text
!= document
.getElementById('allmessagesinput').value
||
868 nodef
!= allmessages_modified
)
869 allmessagesfilter_do(); // repeat
871 allmessages_running
= false;
874 function allmessagesfilter_init() {
875 if ( allmessages_nodelist
)
878 var nodelist
= new Array();
879 var templist
= new Array();
881 var table
= document
.getElementById('allmessagestable');
882 if ( !table
) return;
884 var rows
= document
.getElementsByTagName('tr');
885 for ( var i
= 0; i
< rows
.length
; i
++ ) {
886 var id
= rows
[i
].getAttribute('id')
887 if ( id
&& id
.substring(0,16) != 'sp-allmessages-r' ) continue;
888 templist
[ id
] = rows
[i
];
891 var spans
= table
.getElementsByTagName('span');
892 for ( var i
= 0; i
< spans
.length
; i
++ ) {
893 var id
= spans
[i
].getAttribute('id')
894 if ( id
&& id
.substring(0,17) != 'sp-allmessages-i-' ) continue;
895 if ( !spans
[i
].firstChild
|| spans
[i
].firstChild
.nodeType
!= 3 ) continue;
897 var nodes
= new Array();
898 var row1
= templist
[ id
.replace('i', 'r1') ];
899 var row2
= templist
[ id
.replace('i', 'r2') ];
901 if ( row1
) nodes
[nodes
.length
] = row1
;
902 if ( row2
) nodes
[nodes
.length
] = row2
;
903 nodelist
[ spans
[i
].firstChild
.nodeValue
] = nodes
;
906 var k
= document
.getElementById('allmessagesfilter');
907 if (k
) { k
.style
.display
= ''; }
909 allmessages_nodelist
= nodelist
;
912 hookEvent( "load", allmessagesfilter_init
);
915 Written by Jonathan Snook, http://www.snook.ca/jonathan
916 Add-ons by Robert Nyman, http://www.robertnyman.com
917 Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"
918 From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
920 function getElementsByClassName(oElm
, strTagName
, oClassNames
){
921 var arrElements
= (strTagName
== "*" && oElm
.all
)? oElm
.all
: oElm
.getElementsByTagName(strTagName
);
922 var arrReturnElements
= new Array();
923 var arrRegExpClassNames
= new Array();
924 if(typeof oClassNames
== "object"){
925 for(var i
=0; i
<oClassNames
.length
; i
++){
926 arrRegExpClassNames
.push(new RegExp("(^|\\s)" + oClassNames
[i
].replace(/\-/g, "\\-") + "(\\s|$)"));
930 arrRegExpClassNames
.push(new RegExp("(^|\\s)" + oClassNames
.replace(/\-/g, "\\-") + "(\\s|$)"));
934 for(var j
=0; j
<arrElements
.length
; j
++){
935 oElement
= arrElements
[j
];
937 for(var k
=0; k
<arrRegExpClassNames
.length
; k
++){
938 if(!arrRegExpClassNames
[k
].test(oElement
.className
)){
944 arrReturnElements
.push(oElement
);
947 return (arrReturnElements
)
950 function redirectToFragment(fragment
) {
951 var match
= navigator
.userAgent
.match(/AppleWebKit\/(\d+)/);
953 var webKitVersion
= parseInt(match
[1]);
954 if (webKitVersion
< 420) {
955 // Released Safari w/ WebKit 418.9.1 messes up horribly
956 // Nightlies of 420+ are ok
961 // Mozilla needs to wait until after load, otherwise the window doesn't scroll
962 addOnloadHook(function () {
963 if (window
.location
.hash
== "")
964 window
.location
.hash
= fragment
;
967 if (window
.location
.hash
== "")
968 window
.location
.hash
= fragment
;
973 * Table sorting script by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/.
974 * Based on a script from http://www.kryogenix.org/code/browser/sorttable/.
975 * Distributed under the MIT license: http://www.kryogenix.org/code/browser/licence.html .
977 * Copyright (c) 1997-2006 Stuart Langridge, Joost de Valk.
979 * @todo don't break on colspans/rowspans (bug 8028)
980 * @todo language-specific digit grouping/decimals (bug 8063)
981 * @todo support all accepted date formats (bug 8226)
984 var ts_image_path
= stylepath
+"/common/images/";
985 var ts_image_up
= "sort_up.gif";
986 var ts_image_down
= "sort_down.gif";
987 var ts_image_none
= "sort_none.gif";
988 var ts_europeandate
= wgContentLanguage
!= "en"; // The non-American-inclined can change to "true"
989 var ts_alternate_row_colors
= true;
990 var SORT_COLUMN_INDEX
;
992 function sortables_init() {
994 // Find all tables with class sortable and make them sortable
995 var tables
= getElementsByClassName(document
, "table", "sortable");
996 for (var ti
= 0; ti
< tables
.length
; ti
++) {
997 if (!tables
[ti
].id
) {
998 tables
[ti
].setAttribute('id','sortable_table_id_'+idnum
);
1001 ts_makeSortable(tables
[ti
]);
1005 function ts_makeSortable(table
) {
1007 if (table
.rows
&& table
.rows
.length
> 0) {
1008 if (table
.tHead
&& table
.tHead
.rows
.length
> 0) {
1009 firstRow
= table
.tHead
.rows
[table
.tHead
.rows
.length
-1];
1011 firstRow
= table
.rows
[0];
1014 if (!firstRow
) return;
1016 // We have a first row: assume it's the header, and make its contents clickable links
1017 for (var i
= 0; i
< firstRow
.cells
.length
; i
++) {
1018 var cell
= firstRow
.cells
[i
];
1019 if ((" "+cell
.className
+" ").indexOf(" unsortable ") == -1) {
1020 cell
.innerHTML
+= ' <a href="#" class="sortheader" onclick="ts_resortTable(this);return false;"><span class="sortarrow"><img src="'+ ts_image_path
+ ts_image_none
+ '" alt="↓"/></span></a>';
1023 if (ts_alternate_row_colors
) {
1024 ts_alternate(table
);
1028 function ts_getInnerText(el
) {
1029 if (typeof el
== "string") return el
;
1030 if (typeof el
== "undefined") { return el
};
1031 if (el
.innerText
) return el
.innerText
; // Not needed but it is faster
1034 var cs
= el
.childNodes
;
1036 for (var i
= 0; i
< l
; i
++) {
1037 switch (cs
[i
].nodeType
) {
1038 case 1: //ELEMENT_NODE
1039 str
+= ts_getInnerText(cs
[i
]);
1042 str
+= cs
[i
].nodeValue
;
1049 function ts_resortTable(lnk
) {
1051 var span
= lnk
.getElementsByTagName('span')[0];
1053 var td
= lnk
.parentNode
;
1054 var tr
= td
.parentNode
;
1055 var column
= td
.cellIndex
;
1057 var table
= tr
.parentNode
;
1058 while (table
&& !(table
.tagName
&& table
.tagName
.toLowerCase() == 'table'))
1059 table
= table
.parentNode
;
1062 // Work out a type for the column
1063 if (table
.rows
.length
<= 1) return;
1065 // Skip the first row if that's where the headings are
1066 var rowStart
= (table
.tHead
&& table
.tHead
.rows
.length
> 0 ? 0 : 1);
1069 for (var i
= rowStart
; i
< table
.rows
.length
; i
++) {
1070 if (table
.rows
[i
].cells
.length
> column
) {
1071 itm
= ts_getInnerText(table
.rows
[i
].cells
[column
]);
1072 itm
= itm
.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "");
1073 if (itm
!= "") break;
1077 sortfn
= ts_sort_caseinsensitive
;
1078 if (itm
.match(/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/))
1079 sortfn
= ts_sort_date
;
1080 if (itm
.match(/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/))
1081 sortfn
= ts_sort_date
;
1082 if (itm
.match(/^\d\d[\/.-]\d\d[\/.-]\d\d$/))
1083 sortfn
= ts_sort_date
;
1084 if (itm
.match(/^[£$\80Û¢´]/))
1085 sortfn
= ts_sort_currency
;
1086 if (itm
.match(/^[\d.,]+\%?$/))
1087 sortfn
= ts_sort_numeric
;
1089 var reverse
= (span
.getAttribute("sortdir") == 'down');
1091 var newRows
= new Array();
1092 for (var j
= rowStart
; j
< table
.rows
.length
; j
++) {
1093 var row
= table
.rows
[j
];
1094 var keyText
= ts_getInnerText(row
.cells
[column
]);
1095 var oldIndex
= (reverse
? -j
: j
);
1097 newRows
[newRows
.length
] = new Array(row
, keyText
, oldIndex
);
1100 newRows
.sort(sortfn
);
1104 arrowHTML
= '<img src="'+ ts_image_path
+ ts_image_down
+ '" alt="↓"/>';
1106 span
.setAttribute('sortdir','up');
1108 arrowHTML
= '<img src="'+ ts_image_path
+ ts_image_up
+ '" alt="↑"/>';
1109 span
.setAttribute('sortdir','down');
1112 // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
1113 // don't do sortbottom rows
1114 for (var i
= 0; i
< newRows
.length
; i
++) {
1115 if ((" "+newRows
[i
][0].className
+" ").indexOf(" sortbottom ") == -1)
1116 table
.tBodies
[0].appendChild(newRows
[i
][0]);
1118 // do sortbottom rows only
1119 for (var i
= 0; i
< newRows
.length
; i
++) {
1120 if ((" "+newRows
[i
][0].className
+" ").indexOf(" sortbottom ") != -1)
1121 table
.tBodies
[0].appendChild(newRows
[i
][0]);
1124 // Delete any other arrows there may be showing
1125 var spans
= getElementsByClassName(tr
, "span", "sortarrow");
1126 for (var i
= 0; i
< spans
.length
; i
++) {
1127 spans
[i
].innerHTML
= '<img src="'+ ts_image_path
+ ts_image_none
+ '" alt="↓"/>';
1129 span
.innerHTML
= arrowHTML
;
1131 ts_alternate(table
);
1134 function ts_dateToSortKey(date
) {
1135 // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
1136 if (date
.length
== 11) {
1137 switch (date
.substr(3,3).toLowerCase()) {
1138 case "jan": var month
= "01"; break;
1139 case "feb": var month
= "02"; break;
1140 case "mar": var month
= "03"; break;
1141 case "apr": var month
= "04"; break;
1142 case "may": var month
= "05"; break;
1143 case "jun": var month
= "06"; break;
1144 case "jul": var month
= "07"; break;
1145 case "aug": var month
= "08"; break;
1146 case "sep": var month
= "09"; break;
1147 case "oct": var month
= "10"; break;
1148 case "nov": var month
= "11"; break;
1149 case "dec": var month
= "12"; break;
1150 // default: var month = "00";
1152 return date
.substr(7,4)+month
+date
.substr(0,2);
1153 } else if (date
.length
== 10) {
1154 if (ts_europeandate
== false) {
1155 return date
.substr(6,4)+date
.substr(0,2)+date
.substr(3,2);
1157 return date
.substr(6,4)+date
.substr(3,2)+date
.substr(0,2);
1159 } else if (date
.length
== 8) {
1160 yr
= date
.substr(6,2);
1161 if (parseInt(yr
) < 50) {
1166 if (ts_europeandate
== true) {
1167 return yr
+date
.substr(3,2)+date
.substr(0,2);
1169 return yr
+date
.substr(0,2)+date
.substr(3,2);
1175 function ts_parseFloat(num
) {
1177 num
= parseFloat(num
.replace(/,/, ""));
1178 return (isNaN(num
) ? 0 : num
);
1181 function ts_sort_date(a
,b
) {
1182 var aa
= ts_dateToSortKey(a
[1]);
1183 var bb
= ts_dateToSortKey(b
[1]);
1184 return (aa
< bb
? -1 : aa
> bb
? 1 : a
[2] - b
[2]);
1187 function ts_sort_currency(a
,b
) {
1188 var aa
= ts_parseFloat(a
[1].replace(/[^0-9.]/g,''));
1189 var bb
= ts_parseFloat(b
[1].replace(/[^0-9.]/g,''));
1190 return (aa
!= bb
? aa
- bb
: a
[2] - b
[2]);
1193 function ts_sort_numeric(a
,b
) {
1194 var aa
= ts_parseFloat(a
[1]);
1195 var bb
= ts_parseFloat(b
[1]);
1196 return (aa
!= bb
? aa
- bb
: a
[2] - b
[2]);
1199 function ts_sort_caseinsensitive(a
,b
) {
1200 var aa
= a
[1].toLowerCase();
1201 var bb
= b
[1].toLowerCase();
1202 return (aa
< bb
? -1 : aa
> bb
? 1 : a
[2] - b
[2]);
1205 function ts_sort_default(a
,b
) {
1206 return (a
[1] < b
[1] ? -1 : a
[1] > b
[1] ? 1 : a
[2] - b
[2]);
1209 function ts_alternate(table
) {
1210 // Take object table and get all it's tbodies.
1211 var tableBodies
= table
.getElementsByTagName("tbody");
1212 // Loop through these tbodies
1213 for (var i
= 0; i
< tableBodies
.length
; i
++) {
1214 // Take the tbody, and get all it's rows
1215 var tableRows
= tableBodies
[i
].getElementsByTagName("tr");
1216 // Loop through these rows
1217 // Start at 1 because we want to leave the heading row untouched
1218 for (var j
= 0; j
< tableRows
.length
; j
++) {
1219 // Check if j is even, and apply classes for both possible results
1220 var oldClasses
= tableRows
[j
].className
.split(" ");
1221 var newClassName
= "";
1222 for (var k
= 0; k
< oldClasses
.length
; k
++) {
1223 if (oldClasses
[k
] != "" && oldClasses
[k
] != "even" && oldClasses
[k
] != "odd")
1224 newClassName
+= oldClasses
[k
] + " ";
1226 tableRows
[j
].className
= newClassName
+ (j
% 2 == 0 ? "even" : "odd");
1232 * End of table sorting code
1235 function runOnloadHook() {
1236 // don't run anything below this for non-dom browsers
1237 if (doneOnloadHook
|| !(document
.getElementById
&& document
.getElementsByTagName
)) {
1241 // set this before running any hooks, since any errors below
1242 // might cause the function to terminate prematurely
1243 doneOnloadHook
= true;
1248 updateTooltipAccessKeys( null );
1251 setupCheckboxShiftClick();
1254 // Run any added-on functions
1255 for (var i
= 0; i
< onloadFuncts
.length
; i
++) {
1260 //note: all skins should call runOnloadHook() at the end of html output,
1261 // so the below should be redundant. It's there just in case.
1262 hookEvent("load", runOnloadHook
);
1264 hookEvent("load", mwSetupToolbar
);