MediaWiki:Common.js: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
(Undo revision 584495 by CzechOut (talk) restoring previous version briefly to see if loading archive tool remotely is visible in monobook)
 
(207 intermediate revisions by 6 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");
importScriptPage('ShowHide/code.js', 'dev');
/* ================
importScriptPage('EditIntroButton/code.js', 'dev' );
  TABLE stuff
importScriptPage('AjaxBatchDelete/code.js', 'dev');
  ================ */
importScriptPage('DisableArchiveEdit/code.js', 'dev');
importScriptPage('DupImageList/code.js', 'dev');
// importScriptPage('AdvancedOasisUI/code.js', 'dev'); violates Wikia TOU but is okay for individual users to use
importScriptPage('PurgeButton/code.js', 'dev');
importScriptPage('ShowAdsButton/code.js', 'dev');
importScriptPage('WikiSwitch/code.js', 'dev');


wikiaDomainList = new Array(
//$("tr:odd").addClass("zebra-stripe"); (adversely affects TOCs for a reason I've not yet determined)
{ id: 'central', domain: 'www.wikia.com', name: 'Central', title: 'Central Wikia', interwiki: 'w:' }
);


var ArchiveToolConfig = {
$("table").delegate('td','mouseover mouseleave', function(e) {
  archiveListTemplate: 'Archives',
    if (e.type == 'mouseover') {
  archivePageTemplate: 'Archivepage',
       $(this).parent().addClass("hover");
  archiveSubpage: 'Archive',
       $("colgroup").eq($(this).index()).addClass("hover2");
  userLang: true
    }
};
    else {
var ArchiveToolConfig = {
       $(this).parent().removeClass("hover");
  en: {
       $("colgroup").eq($(this).index()).removeClass("hover2");
       buttonArchiveTool: "Archive",
    }
      buttonArchiveToolTooltip: "Archive this page",
});
      buttonSelectAll: "Select all",
/* ================
       buttonDeselectAll: "Deselect all",
  ROTATING PICS
      buttonSaveArchive: "Save archive",
   helps with infobox
      buttonAbort: "Abort",
   images of characters
      labelLines: "Lines",
  with mulitple
       labelSections: "Sections",
  actors, principally
       summaryArchiveFrom: "ArchiveTool: Archiving from",
  [[The Doctor]] and
      summaryArchiveTo: "ArchiveTool: Archiving to"
   [[The Master]].
  }
 
}
  Also has some helper
importScriptPage('ArchiveTool/code.js', 'dev');
  CSS elsewhere.
 
  ================
/* Turning this off for now
 
var OasisToolbarButtonsConfig = {
  globals defaults:true, window:false, $:false
   purgeOnly: false,
   userLang: true
};
importScriptPage('OasisToolbarButtons/code.js', 'dev');
var OasisToolbarButtonsConfig = {
   en: {
      addTopic: "Add topic",
      editwithform: "form",
      deleteThis: "Del",
      history: "Hist",
      move: "Move",
      protect: "Pro",
      undelete: "Undel",
      unprotect: "Unpro",
      viewsource: "Src",
      whatlinkshere: "Link"
  }
}
***** END ARCHIVE */
 
/*This comes from [[starwars:User:Sikon/preload.js]] and implements the preloadable template system at bottom of input page*/


document.write('<script type="text/javascript" src="'
  First of all we need to detect whether browser
    + '/index.php?title=MediaWiki:Functions.js&action=raw&ctype=text/javascript"></script>');
  supports animation natively or it needs a javascript
  polyfill.


function fillPreloads()
  The detection code by the courtesy of Christian Heilmann
{
  http://hacks.mozilla.org/2011/09/detecting-and-generating-css-animations-in-javascript/ */
    var div = document.getElementById("lf-preload");


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


    div.style.display = 'block';
    var span = document.getElementById('lf-preload-cbox');


    var comboString = "<select id='stdPreloads' onchange='onPreloadChange()'>";
if( elm.style.animationName ) { animation = true; }
    comboString += "</select>";
    span.innerHTML = comboString;
   
    span = document.getElementById('lf-preload-pagename');
    span.innerHTML = '<input type="text" class="textbox" />';
    span = document.getElementById('lf-preload-button');
    span.innerHTML = '<input type="button" class="button" value="Insert" onclick="doCustomPreload()" />';


     requestComboFill('stdPreloads', "Template:Stdpreloads");
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 doCustomPreload()
(function ($) {
{
    $.slowEach = function (array, interval, callback) {
     doPreload(document.getElementById('lf-preload-pagename').getElementsByTagName('input')[0].value);
        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 onPreloadChange()
$(function () {
{
     if( animation === false ) {
     var combo = document.getElementById("stdPreloads");
        $('.dissolve .item').dissolve({
    var value = combo.options[combo.selectedIndex].value;
            // TUNE YOUR CAROUSEL HERE


    if(value == "")
            // duration of an item being visible in miliseconds
        return;
            visibleItemDuration: 4000,


    value = "Template:" + value + "/preload";
            // duration of a transition between items in miliseconds
    value = value.replace(" ", "_");
            transitionDuration: 1000
     doPreload(value);
        });
}
     }
});


addOnloadHook(fillPreloads);
/* ================
 
   ARCHIVE TOOL
/* Preload system ends */
   customisation
 
   ================ */
/* The following Facebook box builder comes from Improvaganza Wiki.  It's sort of cool, but it may not be something
var ArchiveToolConfig = {
we keep around.  It creates a little box allowing you to like whatever thing appears after "id="
   archiveListTemplate: 'ArchCat',
   below.  At present, it's using the id for Doctor Who on Facebook.  You can see an example of what it
   archivePageTemplate: 'ArchPage',
   does at [[user:CzechOut/Sandbox10]].  Might be an idea to rotate it every once in a while, putting up the id of
   archiveSubpage: 'Archive',
   whatever's the "hottest" thing in the DWU at the moment.
   userLang: true
 
};
   The IDs of some other shows:
    
  Torchwood: 113521238658450
   The Sarah Jane Adventures: 109282012424173
   Doctor Who: 127031120644257
  Big Finish: 109833429043462 */


function fBox() {
/* ================
$('#fbox').append('<iframe marginheight="0" marginwidth="0" src="http://www.facebook.com/connect/connect.php?id=127031120644257&amp;connections=10" align="top" frameborder="0" width="300" height="90" scrolling="no" />');
  {{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");
});


$(fBox);
/* ================
  {{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");
});
}); */

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");
	});
}); */