MediaWiki:Common.js

From Tardis Wiki, the free Doctor Who reference
Revision as of 01:57, 5 March 2024 by Tardis sysadmin (talk | contribs) (adding Quick Intro Edit + Null Edit button)
Clear your cache often around here

After changes are made to this site's CSS or Javascript, you have to bypass your browser's cache to see the changes. You can always do this by going to your browser's preferences panel. But many browsers also offer keyboard shortcuts to save you that trouble. The following shortcuts work in the versions of the browsers that Tardis currently supports. They may not work in earlier versions.

  • Firefox: hold down Shift while performing a page reload.
  • Opera offers no default keyboard shortcut, but you can create a custom keyboard shortcut with the value Clear disk cache
  • Safari users should simultaneously hold down + Option + E. You may need to enable the Develop menu first
  • Chrome: press Ctrl + F5 or Shift + F5 while performing a page reload.
/* This adds functionality to perform a null edit
* Author: M3w
* assistance from Doru, Kockadmiralac, Becasita, Stjn for base set up
*/
(function($, mw) {

    if ($("#t-ne").length > 0) {
        return;
    }
    else {
        $.when( mw.loader.using( 'mediawiki.util' ), mw.loader.using( 'mediawiki.api' ), $.ready ).then( function () { 
            if(mw.config.get("wgNamespaceNumber") === -1 || mw.config.get("wgNamespaceNumber") === -2) {
                return;
            }
            
            // set up for skins
            if ((mw.config.get('skin') === 'monobook') || (mw.config.get('skin') === 'vector')) {
            	mw.util.addPortletLink('p-tb', '#', "Null Edit", 't-ne');
            }
            if ((mw.config.get('skin') === 'timeless') || (mw.config.get('skin') === 'citizen')) {
            	mw.util.addPortletLink('p-cactions', '#', "Null Edit", 't-ne');
            }
            
            $('#t-ne').click(function () {
                nullEdit("Null Edit");
            });

            function nullEdit(nullEditReason) {
                var Api = new mw.Api();
                var token = mw.user.tokens.get('csrfToken');
                
                // Get the current timestamp of the page to use as basetimestamp
                Api.get({
                    action: 'query',
                    titles: mw.config.get("wgPageName"),
                    prop: 'revisions',
                    rvprop: 'timestamp'
                }).done(function(data) {
                    var pageTimestamp = Object.values(data.query.pages)[0].revisions[0].timestamp;

                    // Perform the null edit with basetimestamp
                    Api.post({
                        action: 'edit',
                        title: mw.config.get("wgPageName"),
                        reason: nullEditReason,
                        token: token,
                        basetimestamp: pageTimestamp,
                        appendtext: ''  // Add an empty text parameter for null edit
                    }).done(function(data) {
                        if (data.error) {
                            console.error("Null edit failed: " + data.error.info);
                        } else {
                            console.log("Null edit successful");
                            location.reload();
                        }
                    }).fail(function(jqXHR, textStatus, errorThrown) {
                        console.error("Null edit request failed");
                    });
                });
            }
        });
    }
}) (this.jQuery, this.mediaWiki);


/* This adds functionality to quick edit the intro paragraph of pages
* Author: M3w
* assistance from Doru, Kockadmiralac, Becasita, Stjn for base set up
*/
(function($, mw) {
    if ($("#t-editintro").length > 0) {
        return;
    }
    else {
        $.when( mw.loader.using( 'mediawiki.util' ), mw.loader.using( 'mediawiki.api' ), $.ready ).then( function () { 
            if(mw.config.get("wgNamespaceNumber") === -1 || mw.config.get("wgNamespaceNumber") === -2) {
                return;
            }            
            // set up for skins
            if ((mw.config.get('skin') === 'monobook') || (mw.config.get('skin') === 'vector')) {
            	mw.util.addPortletLink('p-tb', 'javascript:void(0);', "Edit Intro", 't-editintro');
            }
            if ((mw.config.get('skin') === 'timeless') || (mw.config.get('skin') === 'citizen')) {
            	mw.util.addPortletLink('p-cactions', 'javascript:void(0);', "Edit Intro", 't-editintro');
            }

            $('#t-introedit').click(function () {
                // Set the current location to the edit link
                window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', section: 0 });
            });

        });
    }
}) (this.jQuery, this.mediaWiki);


/* ================
   TABLE stuff 
   ================ */

//$("tr:odd").addClass("zebra-stripe"); (adversely affects TOCs for a reason I've not yet determined)

$("table").delegate('td','mouseover mouseleave', function(e) {
    if (e.type == 'mouseover') {
      $(this).parent().addClass("hover");
      $("colgroup").eq($(this).index()).addClass("hover2");
    }
    else {
      $(this).parent().removeClass("hover");
      $("colgroup").eq($(this).index()).removeClass("hover2");
    }
});
/* ================
   ROTATING PICS
   helps with infobox
   images of characters
   with mulitple 
   actors, principally
   [[The Doctor]] and
   [[The Master]].
   
   Also has some helper
   CSS elsewhere.
   ================
   
   globals defaults:true, window:false, $:false

   First of all we need to detect whether browser
   supports animation natively or it needs a javascript
   polyfill.

   The detection code by the courtesy of Christian Heilmann
   http://hacks.mozilla.org/2011/09/detecting-and-generating-css-animations-in-javascript/ */

var animation = false,
    elm = document.createElement('detect'),
    animationstring = 'animation',
    keyframeprefix = '',
    domPrefixes = 'Webkit Moz O ms Khtml'.split(' '),
    pfx  = '';


if( elm.style.animationName ) { animation = true; }

if( animation === false ) {
  for( var i = 0; i < domPrefixes.length; i++ ) {
    if( elm.style[ domPrefixes[i] + 'AnimationName' ] !== undefined ) {
      pfx = domPrefixes[ i ];
      animationstring = pfx + 'Animation';
      keyframeprefix = '-' + pfx.toLowerCase() + '-';
      animation = true;
      break;
    }
  }
}

(function ($) {
    $.slowEach = function (array, interval, callback) {
        if (!array.length) {
            return;
        }
        var i = 0;
        function next() {
            if (callback.call(array[i], i, array[i]) !== false) {
                if (++i < array.length) {
                    setTimeout(next, interval);
                }
            }
        }
        next();
        return array;
    };
    $.fn.dissolve = function (options) {
        var op = $.extend(defaults, options),
            $that = $(this),
            interval = op.visibleItemDuration + op.transitionDuration;
        return $.slowEach(this, interval, function () {
            var $this = $(this);
            $this
                .animate({
                    opacity: 1
                }, op.transitionDuration, function () {
                    function initCarousel() {
                        $that.dissolve(options);
                    }
                    if ($this.is(':last-child')) {
                        setTimeout(initCarousel, op.visibleItemDuration);
                    }
                })
                .delay(op.visibleItemDuration)
                .animate({
                    opacity: 0
                }, op.transitionDuration);
        });
    };
    var defaults = {
        visibleItemDuration: 4000,
        transitionDuration: 1000
    };
}(window.jQuery));

$(function () {
    if( animation === false ) {
        $('.dissolve .item').dissolve({
            // TUNE YOUR CAROUSEL HERE

            // duration of an item being visible in miliseconds
            visibleItemDuration: 4000,

            // duration of a transition between items in miliseconds
            transitionDuration: 1000
        });
    }
});
/* ================
   AJAX 
   customisation
   ================ */
window.ajaxPages = ["Special:RecentChanges","Special:WikiActivity","Special:Watchlist","Special:Log","Special:Contributions"];
window.ajaxRefresh = 30000;
AjaxRCRefreshText = 'Auto-refresh via AJAX';
AjaxRCRefreshHoverText = 'Automatically refreshes the page';
/* ================
   ARCHIVE TOOL
   customisation 
   ================ */
var ArchiveToolConfig = { 
   archiveListTemplate: 'ArchCat',
   archivePageTemplate: 'ArchPage',
   archiveSubpage: 'Archive',
   userLang: true
}; 
/* ================
   SPOILER ALERT
   customisation 
   ================ */

/** 
 * SpoilerAlert
 * documentation at: http://dev.wikia.com/wiki/SpoilerAlert
 * © Peter Coester, 2012
 * 
 * __NOWYSIWYG__
 */

window.SpoilerAlertJS = {
            question: 'This section may contain spoilers about unreleased stories. Are you sure you want to read it?',
           yes : 'Hit me with your best shot',
            no : 'Get me the hell out of here',
     fadeDelay : 1000
};

/* ================
   AutoCreateUserPages
   customisation 
   ================ */
/** 
 * documentation at: https://dev.fandom.com/wiki/AutoCreateUserPages
*/

window.AutoCreateUserPagesConfig = {
    content: {
        2: '{{Remove this message to start building your user page}}',
        3: '{{sub'+'st:Welcome}}'
    },
    summary: 'Automatic creation of user pages via script',
    notify: '<a href="/wiki/User talk:$2">Welcome to Tardis!, $1!</a>'
};

/* ================
   {{cite source}}
   Accesability
   tweaks
   ================ */
$(document).ready(function(){
	$('.cse').each(function(i, obj) {
	    $(obj).attr("aria-hidden","true");
	    var citeID = $(obj).attr('id');
	    var citeIDNum = citeID.slice(23); //get number at end of ID
	    var toggle = $(".mw-customtoggle-cs" + citeIDNum);
	    $(toggle).attr("aria-controls",citeID);
		$(toggle).attr("title","Show " + $(toggle).attr("title").slice(7));
		$(toggle).attr("aria-label",$(toggle).attr("title"));
	});
}); 
$(".cse").on("afterExpand.mw-collapsible", function() {
	$(this).attr("aria-hidden","false");
	var citeIDNum = $(this).attr('id').slice(23); //get number at end of ID
	var toggle = $(".mw-customtoggle-cs" + citeIDNum);
	$(toggle).attr("aria-expanded","true");
	$(toggle).attr("title","Hide " + $(toggle).attr("title").slice(5));
	$(toggle).attr("aria-label",$(toggle).attr("title"));
});
$(".cse").on("afterCollapse.mw-collapsible", function() {
	$(this).attr("aria-hidden","true");
	var citeIDNum = $(this).attr('id').slice(23); //get number at end of ID
	var toggle = $(".mw-customtoggle-cs" + citeIDNum);
	$(toggle).attr("aria-expanded","false");
	$(toggle).attr("title","Show " + $(toggle).attr("title").slice(5));
	$(toggle).attr("aria-label",$(toggle).attr("title"));
});
/* ================
   {{pullout}}
   Accesability
   tweaks
   ================ */
$(document).ready(function(){
	$('.pullout-content').each(function(i, obj) {
	    $(obj).attr("aria-hidden","false");
	    var toggle = $(".pullout-handle");
	    $(toggle).attr("aria-controls","mw-customcollapsible-pullout");
		$(toggle).attr("title","Hide editor notices");
		$(toggle).attr("aria-label","Hide editor notices");
	});
}); 
$(".pullout-content").on("afterExpand.mw-collapsible", function() {
	$(this).attr("aria-hidden","false");
	var toggle = $(".pullout-handle");
	$(toggle).attr("aria-expanded","true");
	$(toggle).attr("title","Hide editor notices");
	$(toggle).attr("aria-label","Hide editor notices");
});
$(".pullout-content").on("afterCollapse.mw-collapsible", function() {
	$(this).attr("aria-hidden","true");
	var toggle = $(".pullout-handle");
	$(toggle).attr("aria-expanded","false");
	$(toggle).attr("title","Show editor notices");
	$(toggle).attr("aria-label","Show editor notices");
});

/* ================
   {{nwlh}}
   ================ */
$(document).ready(function(){
	$('NWLH').children("a").each(function(i, obj) {
		$(obj).removeAttr("target");
	});
});