MediaWiki:Common.js: Difference between revisions

From Katawa Shoujo Wiki

imported>Schiffy
Created page with "Any JavaScript here will be loaded for all users on every page load.: Auto Refresh: AjaxRCRefreshText = 'Auto-refresh'; AjaxRCRefreshHoverText = 'Automatically refre..."
 
No edit summary
 
(36 intermediate revisions by 2 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. */
/* Auto Refresh */
AjaxRCRefreshText = 'Auto-refresh';
AjaxRCRefreshHoverText = 'Automatically refresh the page';
ajaxPages = ["Special:RecentChanges","Special:WikiActivity"];
importScriptPage('AjaxRC/code.js', 'dev');
/* Collapsible */
importScriptPage('ShowHide/code.js', 'dev');


// <syntax type="javascript">
// <syntax type="javascript">
Line 17: Line 9:
     */
     */
   
   
// indexed array of toggler ids to array of associated toggle operations
// </syntax>
// each operation is a two element array, the first being the type, the second a class name or array of elements
 
// operation types are strings like "_reset" or "" for the default toggle operation
 
var togglers = new Array();   
/* Adds {{CreativeCommons}} template to all uploads in [[Special:Upload]]. Code by "[[wikipedia:User:Pinky49]]", created and coded specifically for [[wikia:c:cdnmilitary|Duty & Valour]]. */
var allClasses = new Object(); // associative map of class names to page elements
 
function preloadUploadDesc() {
function toggler(id)
if (mw.config.get('wgPageName').toLowerCase() != 'special:upload' && mw.config.get('wgPageName').toLowerCase() != 'special:multipleupload') {
{
return;
    var toBeToggled = togglers[id];
    if (!toBeToggled)
        return;
    // if some element is in list more than once, it will be toggled multiple times
    for (var i = 0; i < toBeToggled.length; i++)
    {
        // get array of elements to operate on
        var toggles = toBeToggled[i][1];
        if (typeof(toggles) == "string")
        {
            if (toggles.charAt(0) == '-')
            {
                // treat as an element ID, not as class
                toggles = document.getElementById(toggles.substring(1));
                if (toggles)
                    toggles = new Array(toggles);
            }
            else
                toggles = allClasses[toggles];
        }
        if (!toggles || !toggles.length)
            continue;
        var op = toBeToggled[i][0]; // what the operation will be
        switch (op)
        {
            case "_reset":
                for (var j in toggles)
                    toggles[j].style.display = toggles[j]._toggle_original_display;
                break;
            case "_show":
                for (var j in toggles)
                    toggles[j].style.display = '';
                break;
            case "_hide":
                for (var j in toggles)
                    toggles[j].style.display = 'none';
                break;
            case "":
            default:
                // Toggle
                for (var j in toggles)
                    toggles[j].style.display = ((toggles[j].style.display == 'none') ? '' : 'none');
                break;
        }
    }
}
function createTogglerLink(toggler, id)
{
    var toggle = document.createElement("a");
    toggle.className = 'toggler-link';
    toggle.setAttribute('id', 'toggler' + id);
    toggle.setAttribute('href', 'javascript:toggler("' + id + '");');
    var child = toggler.firstChild;
    toggler.removeChild(child);
    toggle.appendChild(child);
    toggler.insertBefore(toggle, toggler.firstChild);
}
function toggleInit()
{
    var togglerElems = new Array();
    var toggleGroup = new Array();
    // initialize/clear any old information
    togglers = new Array();   
    allClasses = new Object();
    allClasses.watch = undefined;
    allClasses.unwatch = undefined;
    // make list of all document classes
    var elems = document.getElementsByTagName("*");
    var numelems = elems.length;
    for (var i = 0; i < elems.length; i++)
    {
        var elem = elems[i];
        if (!elem.className)
            continue;
        elem._toggle_original_display = elem.style.display;
        var togglerID = -1;
        var elemClasses = elem.className.split(' '); // get list of classes
        for (var j = 0; j < elemClasses.length; j++)
        {
            var elemClass = elemClasses[j];
            if (! allClasses[elemClass])
                allClasses[elemClass] = new Array();
            allClasses[elemClass].push(elem);
            // all the special classes begin with _toggle
            if (elemClass.substring(0, 7) != "_toggle")
                continue;
            if (elemClass == "_togglegroup")
                toggleGroup = new Array();
            else if (elemClass == "_toggle")
                toggleGroup.push(elem);
            else if (elemClass.substring(0, 12) == "_toggle_init")
            {
                // set initial value for display (ignore the original CSS set value)
                // understands _toggle_initshow and _toggle_inithide
                var disp = elemClass.substring(12);
                if (disp == "show")
                    elem.style.display = '';
                else if (disp == "hide")
                    elem.style.display = 'none';
                elem._toggle_original_display = disp;
            }
            else if (elemClass.substring(0, 8) == "_toggler")
            {
                if (togglerID == -1)
                {
                    togglerID = togglers.length;
                    togglers[togglerID] = new Array();
                    togglerElems[togglerID] = elem;
                }
                // all classes are of form _toggler_op-CLASS
                // figure out what class we're toggling
                // if none is specified, then we use the current toggle group
                var toBeToggled;
                var hyphen = elemClass.indexOf('-');
                if (hyphen != -1)
                    toBeToggled = elemClass.substring(hyphen+1);
                else
                {
                    toBeToggled = toggleGroup;
                    hyphen = elemClass.length;
                }
                var op = elemClass.substring(8, hyphen);
                togglers[togglerID].push(new Array(op, toBeToggled));
            }
        }
    }
    // add javascript links to all toggler elements
    for (var i = 0; i < togglerElems.length; i++)
        createTogglerLink(togglerElems[i], i);
}
function owwsitesearch(f){
    f.q.value='site:http://openwetware.org/wiki/'+
        f.base.value+'++'+f.qfront.value
}
}
   
   
document.getElementById('wpUploadDescription').appendChild(document.createTextNode("<!--For official Katawa Shoujo images and other images licensed under Creative Commons-->\r{{CreativeCommons}}"));
   
   
addOnloadHook(toggleInit);
// </syntax>
// BEGINNING: JavaScript for placing the fair use rationale template inside the summary box on [[Special:Upload]]. Code by "[[wikipedia:User:Pinky49]]", created and coded specifically for [[wikia:c:cdnmilitary|Duty & Valour]].
function FairUseRationale() {
if((wgPageName == 'Special:Upload' || wgPageName == 'Special:MultipleUpload') && document.getElementById('wpDestFile').value == '') {
document.getElementById('wpUploadDescription').value = '{{Fair use rationale\n| Description      = \n| Source            = \n| Portion          = \n| Purpose          = \n| Resolution        = \n| Replaceability    = \n| Other Information = \n}}';
}
}
}
addOnloadHook(FairUseRationale);
addOnloadHook (preloadUploadDesc)
// ****** END: JavaScript for [[Special:Upload]] ******


 
/* importArticle({type:'script', article:'w:c:dev:DisplayClock/code.js'}); */
/****************************************/
/* sliders using jquery by User:Tierrie */
/****************************************/
//wsl.loadScript("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js");
//wsl.loadScript("http://ninjagaiden.wikia.com/index.php?title=MediaWiki:Jquery-ui.min.js&action=raw&ctype=text/javascript");
 
mw.loader.using( ['jquery.ui.tabs'], function() {
$(document).ready(function() {
  var $tabs = $("#portal_slider").tabs({ fx: {opacity:'toggle', duration:100} } );
  $("[class^=portal_sliderlink]").click(function() { // bind click event to link
    $tabs.tabs('select', this.className.replace("portal_sliderlink_", ""));
    return false;
  });
  $('#portal_next').click(function() {
    $tabs.tabs('select', ($tabs.tabs('option', 'selected') == ($tabs.tabs('length'))-1) ? 0 : $tabs.tabs('option', 'selected') + 1 ); // switch to next tab
    return false;
  });
  $('#portal_prev').click(function() { // bind click event to link
    $tabs.tabs('select', ($tabs.tabs('option', 'selected') == 0) ? ($tabs.tabs('length')-1) : $tabs.tabs('option', 'selected') - 1 ); // switch to previous tab
    return false;
  });
});
} );
 
/* Add UTC clock above articles */
importScript('MediaWiki:Common.js/displayTimer.js');


/* Replaces {{Visitor}} with the name of the user browsing the page.
/* Replaces {{Visitor}} with the name of the user browsing the page.
Line 224: Line 30:
   
   
function UserNameReplace() {
function UserNameReplace() {
     if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return;
     if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') == null) return;
     $("span.insertusername").html(wgUserName);
     $("span.insertusername").html(mw.config.get('wgUserName'));
  }
  }
  addOnloadHook(UserNameReplace);
  addOnloadHook(UserNameReplace);
Line 231: Line 37:
/* End of the {{Visitor}} replacement */
/* End of the {{Visitor}} replacement */


if ($('.page-User_Omega_natsu2').length != 0) {
/* importArticles({
$("#WikiaRail").append('<div style="clear:both;" align="center"><img src="http://images.wikia.com/fairytail/images/8/81/Kagura%27s_Working_Clothes.png" width="300"></div>');
type: 'script',
articles: [
// ...
'w:c:dev:SignatureCheck/code.js',
                'u:dev:Standard_Edit_Summary/code.js',
                'u:dev:UserTags/code.js'
// ...
]
}); */
 
/***User Tags***/
window.UserTagsJS = {
    modules: {},
    tags: {
        // group: { associated tag data }
        sysop: { u:'Administrator', link:'Katawa Shoujo Wiki:Administrators' },
        bureaucrat: { u:'Administrator', link:'Katawa Shoujo Wiki:Administrators' }
    }
};
 
UserTagsJS.modules.metafilter = {
'inactive': ['sysop', 'bureaucrat', 'autoconfirmed-user'],
        'new-user': ['sysop', 'bureaucrat', 'autoconfirmed-user'],
        'new-editor': ['sysop', 'bureaucrat', 'autoconfirmed-user']
};
 
/* Link to Game Download */
$('div#p-tb div.mw-portlet-body ul li:first-child').after('<li><a href="http://katawa-shoujo.com/download">Download Katawa Shoujo</a></li>');
 
 
/**** function displayTimer.js
* by Patrick Westerhoff [poke] - copied from https://bulbapedia.bulbagarden.net/wiki/MediaWiki:Bulba.js
*/
function displayTimer ()
{
  if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false )
    return;
 
  var date;
  var timerParent = document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0];
  var timerLink  = document.createElement( 'a' );
  var timerObj    = document.createElement( 'li' );
  timerLink.href              = '/wiki/' + mw.config.get('wgPageName') + '?action=purge';
  timerLink.title              = 'Purge the server cache and update the contents of this page.'
  timerObj.id                  = 'pt-timer';
  timerObj.style.textTransform = 'none';
  timerObj.style.fontWeight    = 'bold';
  timerObj.style.fontSize      = '100%';
  timerObj.appendChild( timerLink );
  timerParent.insertBefore( timerObj, timerParent.firstChild );
 
  function actualizeUTC ()
  {
    timerDate          = new Date();
    timerLink.innerHTML = ( timerDate.getUTCHours()  < 10 ? '0' : '' ) + timerDate.getUTCHours()  + ':'
                        + ( timerDate.getUTCMinutes() < 10 ? '0' : '' ) + timerDate.getUTCMinutes() + ':'
                        + ( timerDate.getUTCSeconds() < 10 ? '0' : '' ) + timerDate.getUTCSeconds() + ' (UTC)';
  }
 
  function actualizeCustom ()
  {
    timerDate          = new Date();
    timerDate.setMinutes( timerDate.getMinutes() + timerDate.getTimezoneOffset() + timerTimezone * 60 );
    timerLink.innerHTML = ( timerDate.getHours()  < 10 ? '0' : '' ) + timerDate.getHours()  + ':'
                        + ( timerDate.getMinutes() < 10 ? '0' : '' ) + timerDate.getMinutes() + ':'
                        + ( timerDate.getSeconds() < 10 ? '0' : '' ) + timerDate.getSeconds()
                        + ' (UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')';
  }
 
  // start
  if ( typeof( timerTimezone ) !== 'number' )
  {
    actualizeUTC();
    setInterval( actualizeUTC, 1000 );
  }
  else
  {
    actualizeCustom();
    setInterval( actualizeCustom, 1000 );
  }
}
}


if ($('.page-User_TheCarrotSaysYumYum').length != 0) {
addOnloadHook(displayTimer);
$("#WikiaRail").append('<div style="clear:both;" align="center"><img src="http://images.wikia.com/fairytail/images/6/65/Jellal_Zeref%27s_Awakening_Full_size.jpg" width="300"></div>');
}

Latest revision as of 20:44, 15 March 2025

/* Any JavaScript here will be loaded for all users on every page load. */

// <syntax type="javascript">
 
    /** 
        Toggles the display of elements on a page 
        Author/contact: Austin Che http://openwetware.org/wiki/User:Austin_J._Che
        See http://openwetware.org/wiki/OpenWetWare:Toggle for examples and documentation
     */
 
// </syntax>


/* Adds {{CreativeCommons}} template to all uploads in [[Special:Upload]]. Code by "[[wikipedia:User:Pinky49]]", created and coded specifically for [[wikia:c:cdnmilitary|Duty & Valour]]. */

function preloadUploadDesc() {
if (mw.config.get('wgPageName').toLowerCase() != 'special:upload' && mw.config.get('wgPageName').toLowerCase() != 'special:multipleupload') {
return;
}
 
document.getElementById('wpUploadDescription').appendChild(document.createTextNode("<!--For official Katawa Shoujo images and other images licensed under Creative Commons-->\r{{CreativeCommons}}"));
 
}
addOnloadHook (preloadUploadDesc)

/* importArticle({type:'script', article:'w:c:dev:DisplayClock/code.js'}); */

/* Replaces {{Visitor}} with the name of the user browsing the page.
   Requires copying Template:USERNAME. */
 
function UserNameReplace() {
    if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') == null) return;
    $("span.insertusername").html(mw.config.get('wgUserName'));
 }
 addOnloadHook(UserNameReplace);
 
/* End of the {{Visitor}} replacement */

/* importArticles({
	type: 'script',
	articles: [
		// ...
		'w:c:dev:SignatureCheck/code.js',
                'u:dev:Standard_Edit_Summary/code.js',
                'u:dev:UserTags/code.js'
		// ...
	]
}); */

/***User Tags***/
window.UserTagsJS = {
    modules: {},
    tags: {
        // group: { associated tag data }
        sysop: { u:'Administrator', link:'Katawa Shoujo Wiki:Administrators' },
        bureaucrat: { u:'Administrator', link:'Katawa Shoujo Wiki:Administrators' }
    }
};

UserTagsJS.modules.metafilter = {
	'inactive': ['sysop', 'bureaucrat', 'autoconfirmed-user'],
        'new-user': ['sysop', 'bureaucrat', 'autoconfirmed-user'],
        'new-editor': ['sysop', 'bureaucrat', 'autoconfirmed-user']
};

/* Link to Game Download */
$('div#p-tb div.mw-portlet-body ul li:first-child').after('<li><a href="http://katawa-shoujo.com/download">Download Katawa Shoujo</a></li>');


/**** function displayTimer.js
 * by Patrick Westerhoff [poke] - copied from https://bulbapedia.bulbagarden.net/wiki/MediaWiki:Bulba.js
 */
function displayTimer ()
{
  if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false )
    return;
  
  var date;
  var timerParent = document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0];
  var timerLink   = document.createElement( 'a' );
  var timerObj    = document.createElement( 'li' );
  timerLink.href               = '/wiki/' + mw.config.get('wgPageName') + '?action=purge';
  timerLink.title              = 'Purge the server cache and update the contents of this page.'
  timerObj.id                  = 'pt-timer';
  timerObj.style.textTransform = 'none';
  timerObj.style.fontWeight    = 'bold';
  timerObj.style.fontSize      = '100%';
  timerObj.appendChild( timerLink );
  timerParent.insertBefore( timerObj, timerParent.firstChild );
  
  function actualizeUTC ()
  {
    timerDate           = new Date();
    timerLink.innerHTML = ( timerDate.getUTCHours()   < 10 ? '0' : '' ) + timerDate.getUTCHours()   + ':'
                        + ( timerDate.getUTCMinutes() < 10 ? '0' : '' ) + timerDate.getUTCMinutes() + ':'
                        + ( timerDate.getUTCSeconds() < 10 ? '0' : '' ) + timerDate.getUTCSeconds() + ' (UTC)';
  }
  
  function actualizeCustom ()
  {
    timerDate           = new Date();
    timerDate.setMinutes( timerDate.getMinutes() + timerDate.getTimezoneOffset() + timerTimezone * 60 );
    timerLink.innerHTML = ( timerDate.getHours()   < 10 ? '0' : '' ) + timerDate.getHours()   + ':'
                        + ( timerDate.getMinutes() < 10 ? '0' : '' ) + timerDate.getMinutes() + ':'
                        + ( timerDate.getSeconds() < 10 ? '0' : '' ) + timerDate.getSeconds()
                        + ' (UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')';
  }
  
  // start
  if ( typeof( timerTimezone ) !== 'number' )
  {
    actualizeUTC();
    setInterval( actualizeUTC, 1000 );
  }
  else
  {
    actualizeCustom();
    setInterval( actualizeCustom, 1000 );
  }
}

addOnloadHook(displayTimer);