1 // Wikipedia JavaScript support functions
3 var clientVer = parseInt(navigator.appVersion); // Get browser version
4 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
5 var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
6 var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
7 && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
8 && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
10 var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
11 var is_mac = (clientPC.indexOf("mac")!=-1);
13 // for enhanced RecentChanges
14 function toggleVisibility( _levelId, _otherId, _linkId) {
15 var thisLevel = document.getElementById( _levelId );
16 var otherLevel = document.getElementById( _otherId );
17 var linkLevel = document.getElementById( _linkId );
18 if ( thisLevel.style.display == 'none' ) {
19 thisLevel.style.display = 'block';
20 otherLevel.style.display = 'none';
21 linkLevel.style.display = 'inline';
23 thisLevel.style.display = 'none';
24 otherLevel.style.display = 'inline';
25 linkLevel.style.display = 'none';
30 // tz in format [+-]HHMM
31 function checkTimezone( tz, msg ) {
32 var localclock = new Date();
33 // returns negative offset from GMT in minutes
34 var tzRaw = localclock.getTimezoneOffset();
35 var tzHour = Math.floor( Math.abs(tzRaw) / 60);
36 var tzMin = Math.abs(tzRaw) % 60;
37 var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin;
38 if( tz != tzString ) {
39 var junk = msg.split( '$1' );
40 document.write( junk[0] + "UTC" + tzString + junk[1] );
44 // in [-][H]H format...
45 // won't yet work with non-even tzs
46 function fetchTimezone() {
47 // FIXME: work around Safari bug
48 var localclock = new Date();
49 // returns negative offset from GMT in minutes
50 var tzRaw = localclock.getTimezoneOffset();
51 var tzHour = Math.floor( Math.abs(tzRaw) / 60);
52 var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "" : "0") + tzHour;
56 function guessTimezone(box) {
57 document.preferences.wpHourDiff.value = fetchTimezone();
60 function showTocToggle(show,hide) {
61 if(document.getElementById) {
62 document.writeln('<small>[<a href="javascript:toggleToc()" class="internal">' +
63 '<span id="showlink" style="display:none;">' + show + '</span>' +
64 '<span id="hidelink">' + hide + '</span>'
69 function toggleToc() {
70 var toc = document.getElementById('tocinside');
71 var showlink=document.getElementById('showlink');
72 var hidelink=document.getElementById('hidelink');
73 if(toc.style.display == 'none') {
74 toc.style.display = tocWas;
75 hidelink.style.display='';
76 showlink.style.display='none';
79 tocWas = toc.style.display;
80 toc.style.display = 'none';
81 hidelink.style.display='none';
82 showlink.style.display='';
87 // apply tagOpen/tagClose to selection in textarea,
88 // use sampleText instead of selection if there is none
89 // copied and adapted from phpBB
90 function insertTags(tagOpen, tagClose, sampleText) {
92 var txtarea = document.editform.wpTextbox1;
93 if ((clientVer >= 4) && is_ie && is_win) {
94 theSelection = document.selection.createRange().text;
96 txtarea.value += tagOpen + sampleText + tagClose;
100 document.selection.createRange().text = tagOpen + theSelection + tagClose;
104 else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
106 mozWrap(txtarea, tagOpen, tagClose, sampleText);
111 txtarea.value += tagOpen + sampleText + tagClose;
117 // From http://www.massless.org/mozedit/
118 function mozWrap(txtarea, open, close)
120 var txtarea = document.editform.wpTextbox1;
121 var selLength = txtarea.textLength;
122 var selStart = txtarea.selectionStart;
123 var selEnd = txtarea.selectionEnd;
124 if (selEnd == 1 || selEnd == 2)
127 var s1 = (txtarea.value).substring(0,selStart);
128 var s2 = (txtarea.value).substring(selStart, selEnd)
129 var s3 = (txtarea.value).substring(selEnd, selLength);
130 txtarea.value = s1 + open + s2 + close + s3;
134 // Insert at Claret position. Code from
135 // http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
136 function storeCaret(textEl) {
137 if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();