MediaWiki:Common.js: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
(changing ajax text)
Tags: sourceedit rollback
 
(48 intermediate revisions by 5 users not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
console.log("Common.js is running");
 
 
// This contains the April 2012 code,
// found at [[starwars:MediaWiki:Common.js]].  Grunny no longer
// keeps this code in a separate file, but it seems to be
// working just as well to have it separately as to have it
// imbedded in THIS file.  Since it's fairly arcane, mundane code
// it may be better to have it out of the way in its own file.
 
/* =================
  BEGIN PRELOADS
  ================= */
 
/* =================
  Edit summaries
  from runescape.wikia.com
  =================
$(function() {
        if (skin == 'oasis'){
            var $label = $('#edit_enhancements_toolbar #wpSummaryLabel');
    if (!$label.size()) {
        return;
    }
        }
        if (skin == 'monobook'){
    var $label = $('.editOptions #wpSummaryLabel');
    if (!$label.size()) {
        return;
    }
        }
$combo = $('<select />').attr('id', 'stdSummaries').change(function() {
var val = $(this).val();
if (val != '') {
$('#wpSummaryEnhanced,#wpSummary').val(val);
}
});
        $label.prepend('<br />').prepend($combo).prepend('Summaries: ');
$.ajax({
'dataType': 'text',
'data': {
'title': 'Template:Stdsummaries',
'action': 'raw',
'ctype': 'text/plain'
},
'url': wgScript,
'success': function(data) {
var lines = data.split("\n");
for (var i in lines) {
var val = (lines[i].indexOf('-- ') == 0) ? lines[i].substring(3) : '';
var text = (lines[i].indexOf('-- ') == 0) ? '&nbsp;&nbsp;' + lines[i].substring(3) : lines[i];
var disable = (lines[i].indexOf('-- ') == 0 || lines[i].indexOf('(') == 0) ? '' : 'disabled';
var $opt = '<option value="' + val + '" ' + disable + '>' + text + '</option>';
$combo.append($opt);
}
}
});
})
 
*/
/* =================
* jQuery version of fillPreloads
* by Grunny at starwars.wikia.com
* ================= */
 
function fillPreloads() {
if( !$( '#lf-preload' ).length ) {
return;
}
var preloadOptionsHtml = '',
$preloadOptionsList;
$( '#lf-preload' ).attr( 'style', 'display: block' );
$.get( wgScript, { title: 'Template:Stdpreloads', action: 'raw', ctype: 'text/plain' }, function( data ) {
var lines = data.split( '\n' );
for( var i = 0; i < lines.length; i++ ) {
var value = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : "";
preloadOptionsHtml += '<option value="' + value + '">' + lines[i] + '</option>';
}
$preloadOptionsList = $( '<select />' ).attr( 'id', 'stdSummaries' ).html( preloadOptionsHtml ).change( function() {
var value = $( this ).val();
if ( value !== '' ) {
value = 'Template:' + value + '/preload';
value = value.replace( ' ', '_' );
$.get( wgScript, { title: value, action: 'raw', ctype: 'text/plain' }, function( data ) {
insertAtCursor( document.getElementById( 'wpTextbox1' ), data );
} );
}
} );
$( '#lf-preload-cbox' ).html( $preloadOptionsList );
} );
$( '#lf-preload-pagename' ).html( '<input type="text" class="textbox" />' );
$( '#lf-preload-button' ).html( '<input type="button" class="button" value="Insert" onclick="doCustomPreload()" />' );
}
function doCustomPreload() {
var value = $( '#lf-preload-pagename > input' ).val();
value = value.replace( ' ', '_' );
$.get( wgScript, { title: value, action: 'raw', ctype: 'text/plain' }, function( data ) {
insertAtCursor( document.getElementById( 'wpTextbox1' ), data );
} );
}
 
/* =============
  Title rewrite
  jQuery version and new wikia skin fixes by Grunny
  ==============
  This is what powers
  [[template:title]],
  principally allowing
  for italic page titles
  ============== */
function rewriteTitle() {
if( typeof( window.SKIP_TITLE_REWRITE ) != 'undefined' && window.SKIP_TITLE_REWRITE ) {
return;
}
if( $('#title-meta').length == 0 ) {
return;
}
var newTitle = $('#title-meta').html();
if( skin == "oasis" ) {
$('header.WikiaPageHeader > h1').html('<div id="title-meta" style="display: inline;">' + newTitle + '</div>');
$('header.WikiaPageHeader > h1').attr('style','text-align:' + $('#title-align').html() + ';');
} else {
$('.firstHeading').html('<div id="title-meta" style="display: inline;">' + newTitle + '</div>');
$('.firstHeading').attr('style','text-align:' + $('#title-align').html() + ';');
}
}
 
var ArchiveToolConfig = {
  archiveListTemplate: 'ArchCat',
  archivePageTemplate: 'ArchPage',
  archiveSubpage: 'Archive',
  userLang: true
};
importScriptPage('ArchiveTool/code.js', 'dev');
 
 
/* =============
  MOS box
  from Brickipedia
  ==============
  This is the little box underneath the
  search bar and article tally, which has the
  Seal of Rassilon in it.
  ===============
  Keep at end of common.js, but before
  any addOnloadHooks.
  ================ */
 
importScript('MediaWiki:Common.js/mosbox.js');
 
/* ================
/* ================
   TABLE stuff  
   TABLE stuff  
Line 179: Line 16:
     }
     }
});
});
/* ================
  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


/*globals defaults:true, window:false, $:false */
  First of all we need to detect whether browser
  supports animation natively or it needs a javascript
  polyfill.


// First of all we need to detect whether browser
  The detection code by the courtesy of Christian Heilmann
// supports animation natively or it needs a javascript
  http://hacks.mozilla.org/2011/09/detecting-and-generating-css-animations-in-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,
var animation = false,
Line 269: Line 119:
});
});


/**
/* ================
* SpoilerAlert
  ARCHIVE TOOL
* documentation at: http://dev.wikia.com/wiki/SpoilerAlert
  customisation
* © Peter Coester, 2012
  ================ */
*
var ArchiveToolConfig = {  
* __NOWYSIWYG__
  archiveListTemplate: 'ArchCat',
*/
  archivePageTemplate: 'ArchPage',
 
  archiveSubpage: 'Archive',
SpoilerAlert = {
  userLang: true
            question: 'This page 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',
    isSpoiler: function () {
        return -1 !== wgCategories.indexOf('Contains spoilers');
    },
    back:true
};
};


/* ================
/* ================
   Video "stretchiness"
   {{pullout}}
  Accesability
  tweaks
   ================ */
   ================ */
 
$(document).ready(function(){
jQuery(function($){
$('.pullout-content').each(function(i, obj) {
    var videoSelectors = [
    $(obj).attr("aria-hidden","false");
        "iframe[src^='http://player.vimeo.com']",  
    var toggle = $(".pullout-handle");
        "iframe[src^='http://www.youtube.com']",  
    $(toggle).attr("aria-controls","mw-customcollapsible-pullout");
        "iframe[src^='http://www.kickstarter.com']",
$(toggle).attr("title","Hide editor notices");
        "iframe[src^='http://www.screenr.com']",
$(toggle).attr("aria-label","Hide editor notices");
        "iframe[src^='http://www.blip.tv']",
});
        "iframe[src^='http://www.dailymotion.com']",
});
        "iframe[src^='http://www.viddler.com']",
$(".pullout-content").on("afterExpand.mw-collapsible", function() {
        "iframe[src^='http://www.qik.com']",
$(this).attr("aria-hidden","false");
        "iframe[src^='http://www.revision3.com']",
var toggle = $(".pullout-handle");
        "iframe[src^='http://www.hulu.com']",
$(toggle).attr("aria-expanded","true");
        "iframe[src^='http://www.funnyordie.com']",
$(toggle).attr("title","Hide editor notices");
        "embed[src^='http://v.wordpress.com']"
$(toggle).attr("aria-label","Hide editor notices");
        // add more selectors here
    ];
    var allVideos = videoSelectors.join(',');
    $( allVideos ).wrap('<div class="wikia-video-thumb" />'); // wrap them all!
});
});
 
$(".pullout-content").on("afterCollapse.mw-collapsible", function() {
 
$(this).attr("aria-hidden","true");
 
var toggle = $(".pullout-handle");
/* ================
$(toggle).attr("aria-expanded","false");
  Other imports
$(toggle).attr("title","Show editor notices");
  ================ */
$(toggle).attr("aria-label","Show editor notices");
 
importArticles({
    type: "script",
    articles: [
        "w:dev:FixWantedFiles/code.js",
        "w:dev:Countdown/code.js",
        "w:dev:SpoilerAlert/code.js",
        "MediaWiki:Functions.js",
        "w:dev:ListFiles/code.js",
        "w:dev:ShowHide/code.js",
        "w:dev:EditIntroButton/code.js",
        "w:dev:DupImageList/code.js",
        "w:dev:RevealAnonIP/code.js",
        "u:dev:AjaxRC/code.js",
        "w:dev:Category_Sorter/code.js",
        "w:dev:Standard_Edit_Summary/code.js",
        "MediaWiki:Common.js/forumnote.js",
        "w:dev:TopEditors/code.js"
        /* "u:dev:Code/code.js" No thank you, ugly. */
    ]
});
});


/* ================
/* ================
   AJAX customisation
   {{nwlh}}
   ================ */
   ================
window.ajaxPages = ["Special:RecentChanges","Special:WikiActivity","Special:Watchlist","Special:Log","Special:Contributions"];
  re-instate if external links are set to open in new tabs
window.ajaxRefresh = 30000
$(document).ready(function(){
AjaxRCRefreshText = 'Auto-refresh via AJAX';
$('NWLH').children("a").each(function(i, obj) {
AjaxRCRefreshHoverText = 'Automatically refreshes the page';
$(obj).removeAttr("target");
 
});
 
}); */
 
/*  ================
    addOnloadHook area
    ================
    Necessary for calling to life functions
    specified elsewhere in this document.
    ================= */
 
addOnloadHook( rewriteTitle );

Latest revision as of 21:10, 9 April 2024

console.log("Common.js is running");
/* ================
   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
        });
    }
});

/* ================
   ARCHIVE TOOL
   customisation 
   ================ */
var ArchiveToolConfig = { 
   archiveListTemplate: 'ArchCat',
   archivePageTemplate: 'ArchPage',
   archiveSubpage: 'Archive',
   userLang: true
};

/* ================
   {{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}}
   ================
   re-instate if external links are set to open in new tabs
$(document).ready(function(){
	$('NWLH').children("a").each(function(i, obj) {
		$(obj).removeAttr("target");
	});
}); */