|
|
(13 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Any JavaScript here will be loaded for all users on every page load. */ |
| | |
| | /*************************************** |
| | |
| | /* Automatically add Aboutfile template to file upload description. Source: Porplemontage at khwiki.com (http://www.khwiki.com/MediaWiki:Common.js) */ |
| | if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload' && !document.getElementById('wpForReUpload') && !document.getElementsByClassName('warning')[0] && !document.getElementsByClassName('error')[0]) { |
| | function loadAutoAboutfileTemplate() { |
| | uploadDescription = document.getElementById('wpUploadDescription'); |
| | var doubleBracket = '{' + '{'; |
| | uploadDescription.value = doubleBracket + 'AboutFile\n|description=\n|use=\n|source=\n}}'; |
| | } |
| | |
| | addOnloadHook(loadAutoAboutfileTemplate); |
| | } |
| | |
|
| |
|
| /*************************************** | | /*************************************** |
Line 15: |
Line 29: |
| }; | | }; |
| })(); | | })(); |
|
| |
| /***********************************************************
| |
| * Name: collapseTable
| |
| * Description: Collapses a single table, showing only the header.
| |
| * Maintainers: (Wikipedia) [[User:R. Koot]], (Dragon Quest Wiki) [[User:FlyingRagnar]]
| |
| * Source: Wikipedia Common.js, imported 2/1/10
| |
| * Additional Notes: This is the primary method used to collapse navigational templates.
| |
| * This code has been updated to use the jQuery toggle() function. Various effects were tested, but due
| |
| * to the fact that multiple <tr>s are being toggled, they did not look good. As a result, it does just a basic toggle
| |
| * with no effects.
| |
| */
| |
| mw.loader.load( 'jquery.effects.core' );
| |
| var autoCollapse = 2;
| |
| var collapseCaption = "hide";
| |
| var expandCaption = "show";
| |
| function collapseTable( tableIndex )
| |
| {
| |
| var Button = document.getElementById( "collapseButton" + tableIndex );
| |
| var Table = document.getElementById( "collapsibleTable" + tableIndex );
| |
|
| |
| if ( !Table || !Button ) {
| |
| return false;
| |
| }
| |
|
| |
| var targt = "#collapsibleTable" + tableIndex + " tr";
| |
| $( targt + ":first-child").addClass("master");
| |
| $( targt + ":not(.master)").toggle();
| |
|
| |
| if ( Button.firstChild.data == collapseCaption ) {
| |
| Button.firstChild.data = expandCaption;
| |
| } else {
| |
| Button.firstChild.data = collapseCaption;
| |
| }
| |
| }
| |
|
| |
| /***********************************************************
| |
| * Name: createTableCollapseButtons
| |
| * Description: Runs at page load, finds each table with class collapsible and inserts the necessary
| |
| * elements to make the table have collapsible functionality. The actual collapsing is then handled
| |
| * by the collapseTable function.
| |
| * Maintainers: (Wikipedia) [[User:R. Koot]], (Dragon Quest Wiki) [[User:FlyingRagnar]]
| |
| * Source: Wikipedia Common.js, imported 2/1/10
| |
| * Additional Notes: This method sets up the collapsing functionality. Dragon Quest wiki does not currently use the 'innercollapse', 'outercollapse', or 'autocollapse'
| |
| * functionality. It is generally preferred to allow tables to size themselves rather than specify a fixed width.
| |
| * Usage: Create a table and give it the class "collapsible". Ensure that the table has a header row. Add the class
| |
| * "collapsed" if you wish the table to be collapsed on page load.
| |
| */
| |
| function createTableCollapseButtons()
| |
| {
| |
| var tableIndex = 0;
| |
| var NavigationBoxes = new Object();
| |
| var Tables = document.getElementsByTagName( "table" );
| |
|
| |
| for ( var i = 0; i < Tables.length; i++ ) {
| |
| if ( hasClass( Tables[i], "collapsible" ) ) {
| |
|
| |
| // only add button and increment count if there is a header row to work with
| |
| var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
| |
| if (!HeaderRow) continue;
| |
| var Header = HeaderRow.getElementsByTagName( "th" )[0];
| |
| if (!Header) continue;
| |
|
| |
| NavigationBoxes[ tableIndex ] = Tables[i];
| |
| Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
| |
|
| |
| var Button = document.createElement( "span" );
| |
| var ButtonLink = document.createElement( "a" );
| |
| var ButtonText = document.createTextNode( collapseCaption );
| |
|
| |
| Button.className = "collapseButton"; //Styles are declared in Common.css
| |
|
| |
| ButtonLink.style.color = Header.style.color;
| |
| ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
| |
| ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
| |
| ButtonLink.appendChild( ButtonText );
| |
|
| |
| // fix width of table to be the same when shown or hidden (IE only)
| |
| // Tables[i].style.width = Tables[i].offsetWidth;
| |
|
| |
| Button.appendChild( document.createTextNode( "[" ) );
| |
| Button.appendChild( ButtonLink );
| |
| Button.appendChild( document.createTextNode( "]" ) );
| |
|
| |
| Header.insertBefore( Button, Header.childNodes[0] );
| |
| tableIndex++;
| |
| }
| |
| }
| |
|
| |
| for ( var i = 0; i < tableIndex; i++ ) {
| |
| if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
| |
| collapseTable( i );
| |
| }
| |
| else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
| |
| var element = NavigationBoxes[i];
| |
| while (element = element.parentNode) {
| |
| if ( hasClass( element, "outercollapse" ) ) {
| |
| collapseTable ( i );
| |
| break;
| |
| }
| |
| }
| |
| }
| |
| }
| |
| }
| |
|
| |
| addOnloadHook( createTableCollapseButtons );
| |
|
| |
|
| /*********************************************************** | | /*********************************************************** |
Line 306: |
Line 215: |
|
| |
|
| addPortletLink("p-tb", url, "Page logs", "pt-logs"); | | addPortletLink("p-tb", url, "Page logs", "pt-logs"); |
| });
| |
| //
| |
| // --------------------------------------------------------
| |
| // user rights
| |
| // adds a link in the tool box while on user pages to a user's rights management page.
| |
| // --------------------------------------------------------
| |
| addOnloadHook(function () {
| |
| if (!rights_isAdmin)
| |
| return; //Restrict this feature to admins.
| |
| if (wgNamespaceNumber != "2" && wgNamespaceNumber != "3")
| |
| return; // restrict to User and User talk
| |
|
| |
| var title = wgTitle;
| |
|
| |
| addPortletLink('p-tb', '/wiki/index.php?title=Special:Userrights/'+title,
| |
| 'User rights', 't-userrights', 'User rights for "'+title+'"');
| |
|
| |
| }); | | }); |
| // | | // |
Line 410: |
Line 302: |
| } | | } |
| addOnloadHook(patroltab); | | addOnloadHook(patroltab); |
| //
| |
|
| |
| // --------------------------------------------------------
| |
| // Recent Changes Edit Colors
| |
| // Colors the page size changes on the recent changes
| |
| // --------------------------------------------------------
| |
| importStylesheetURI("http://zeldawiki.org/User:Matt/RC_Colors.css" + "&ctype=text/css&action=raw");
| |
| // | | // |
|
| |
|
Line 470: |
Line 355: |
| return node; | | return node; |
| } | | } |
| /*</pre>
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
| /*
| |
| #########
| |
| ### ProjectLinks
| |
| ### by [[user:Pathoschild]] (idea from an older, uncredited script)
| |
| ### * generates a sidebar list of links to other projects from {{projectlinks}}
| |
| #########
| |
| */
| |
| function Projectlinks() {
| |
| var elements = new Array();
| |
| var spans = document.getElementsByTagName('span');
| |
|
| |
| // filter for projectlinks
| |
| for (var i=0, j=0; i<spans.length; i++) {
| |
| if (spans[i].className == 'interProject') {
| |
| elements[j] = spans[i].getElementsByTagName('a')[0];
| |
| j++;
| |
| }
| |
| }
| |
|
| |
| if (j == 0)
| |
| return;
| |
|
| |
| // sort alphabetically
| |
| function sortbylabel(a,b) {
| |
| // get labels
| |
| a = a.innerHTML.replace(/^.*<a[^>]*>(.*)<\/a>.*$/i,'$1');
| |
| b = b.innerHTML.replace(/^.*<a[^>]*>(.*)<\/a>.*$/i,'$1');
| |
|
| |
| // return sort order
| |
| if (a < b) return -1;
| |
| if (a > b) return 1;
| |
| return 0;
| |
| }
| |
| elements.sort(sortbylabel);
| |
|
| |
| // Create the list of project links
| |
| var pllist = newNode('ul');
| |
| for (var i=0; i<elements.length; i++) {
| |
| pllist.appendChild(newNode('li', elements[i]));
| |
| }
| |
| var projectBox = newNode('div', {'class': 'portlet portal', id: 'p-projects'},
| |
| newNode('h5', 'On other wikis'),
| |
| newNode('div', {'class': 'pBody body'}, pllist)
| |
| );
| |
|
| |
| var insert = document.getElementById('p-tb');
| |
| if (!insert)
| |
| return;
| |
|
| |
| if (insert.nextSibling)
| |
| insert.parentNode.insertBefore(projectBox, insert.nextSibling);
| |
| else
| |
| insert.parentNode.appendChild(projectBox);
| |
| }
| |
|
| |
| addOnloadHook(Projectlinks);
| |
|
| |
| addOnloadHook( createNavigationBarToggleButton );
| |
| // Code courtesy of pcj of WoWWiki.
| |
| // This is a modified version of the WoWWiki site version, in that it is designed for global.js use.
| |
|
| |
| // Code adds a checkbox at the top of the Special:RecentChanges list, next to the header.
| |
| // Ticking it sets a cookie (should be individual to wikis) and starts updating the RC list.
| |
| // This occurs silently every 60 seconds without a full page reload occuring.
| |
|
| |
| function setCookie(c_name,value,expiredays) {
| |
| var exdate=new Date()
| |
| exdate.setDate(exdate.getDate()+expiredays)
| |
| document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
| |
| }
| |
|
| |
| function getCookie(c_name) {
| |
| if (document.cookie.length>0) {
| |
| c_start=document.cookie.indexOf(c_name + "=")
| |
| if (c_start!=-1) {
| |
| c_start=c_start + c_name.length+1
| |
| c_end=document.cookie.indexOf(";",c_start)
| |
| if (c_end==-1) c_end=document.cookie.length
| |
| return unescape(document.cookie.substring(c_start,c_end))
| |
| }
| |
| }
| |
| return ""
| |
| }
| |
|
| |
| function getXmlHttpRequestObject() {
| |
| if (window.XMLHttpRequest) {
| |
| return new XMLHttpRequest(); //Not Internet Explorer
| |
| } else if(window.ActiveXObject) {
| |
| return new ActiveXObject("Microsoft.XMLHTTP"); //Internet Explorer
| |
| } else {
| |
| //fail silently
| |
| }
| |
| }
| |
| getRCDataRO = getXmlHttpRequestObject();
| |
| var cr = new RegExp("\r", "gm");
| |
| var lf = new RegExp("\n", "gm");
| |
| var endText = new RegExp('</div>[\t\s]*?<!-- end content -->[\t\s]*?<div class="visualClear">', "mi");
| |
| var rcTimer;
| |
| var rcRefresh = 60000;
| |
| function preloadAJAXRC() {
| |
| s = 0;
| |
| ajaxRCCookie = getCookie("ajaxRC")=="on" ? true:false;
| |
| document.getElementsByTagName("h1")[s].innerHTML += ' <span style="font-size: xx-small; border-bottom: 1px dotted; cursor:help;" title="Enable auto-refreshing recent changes">Auto-Refresh:</span><input type="checkbox" id="ajaxRCtoggle" onClick="toggleRC();">';
| |
| document.getElementById("ajaxRCtoggle").checked = ajaxRCCookie;
| |
| if (getCookie("ajaxRC")=="on") loadRCData();
| |
| }
| |
|
| |
| function toggleRC() {
| |
| if (document.getElementById("ajaxRCtoggle").checked == true) {
| |
| setCookie("ajaxRC", "on", 30);
| |
| loadRCData();
| |
| } else {
| |
| setCookie("ajaxRC", "off", 30);
| |
| clearTimeout(rcTimer);
| |
| }
| |
| }
| |
|
| |
| function loadRCData() {
| |
| if (getRCDataRO.readyState == 4 || getRCDataRO.readyState == 0) {
| |
| if (location.href.indexOf("/wiki/")) {
| |
| rcURL = "http://" + location.hostname + "/wiki/Special:RecentChanges" + location.search;
| |
| } else {
| |
| rcURL = "http://" + location.hostname + "/Special:RecentChanges" + location.search;
| |
| }
| |
| getRCDataRO.open("GET", rcURL, true);
| |
| getRCDataRO.onreadystatechange = parseRCdata;
| |
| getRCDataRO.send(null);
| |
| }
| |
| }
| |
|
| |
| function parseRCdata() {
| |
| if (getRCDataRO.readyState == 4) {
| |
| textFilter = new RegExp('<div id="bodyContent">.*?</div>[\t\s]*?<!-- end content -->[\t\s]*?<div class="visualClear">', "i");
| |
| rawRCdata = getRCDataRO.responseText.replace(cr, "").replace(lf, "");
| |
| filteredRCdata = textFilter.exec(rawRCdata);
| |
| updatedText = filteredRCdata[0].replace('<div id="bodyContent">', "").replace(endText, "");
| |
| document.getElementById("bodyContent").innerHTML = updatedText;
| |
| rcTimer = setTimeout("loadRCData();", rcRefresh);
| |
| }
| |
| }
| |
|
| |
| if (wgPageName == "Special:RecentChanges") addOnloadHook(preloadAJAXRC);
| |