MediaWiki:Common.js: Difference between revisions
From Tardis Wiki, the free Doctor Who reference
(moving forumnote.js to MediaWiki:ImportJS; likely don't need functions.js at all) |
(some mostly cosmetic changes) |
||
Line 1: | Line 1: | ||
/* ================= | /* ================= | ||
BEGIN PRELOADS | BEGIN PRELOADS | ||
================= */ | ================= */ | ||
/* ================= | /* ================= | ||
jQuery version of fillPreloads | jQuery version of fillPreloads | ||
by Grunny at starwars.wikia.com | by Grunny at starwars.wikia.com | ||
================= */ | ================= | ||
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. */ | |||
function fillPreloads() { | function fillPreloads() { | ||
Line 61: | Line 56: | ||
} ); | } ); | ||
} | } | ||
/* ================ | /* ================ | ||
TABLE stuff | TABLE stuff | ||
Line 78: | Line 72: | ||
} | } | ||
}); | }); | ||
/* ================ | |||
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, | var animation = false, | ||
Line 167: | Line 174: | ||
} | } | ||
}); | }); | ||
/* ================ | /* ================ | ||
AJAX | AJAX | ||
Line 177: | Line 182: | ||
AjaxRCRefreshText = 'Auto-refresh via AJAX'; | AjaxRCRefreshText = 'Auto-refresh via AJAX'; | ||
AjaxRCRefreshHoverText = 'Automatically refreshes the page'; | AjaxRCRefreshHoverText = 'Automatically refreshes the page'; | ||
/* ================ | /* ================ | ||
ARCHIVE TOOL | ARCHIVE TOOL | ||
Line 188: | Line 192: | ||
userLang: true | userLang: true | ||
}; | }; | ||
/* ================ | /* ================ | ||
SPOILER ALERT | SPOILER ALERT |
Revision as of 19:02, 29 August 2018
/* =================
BEGIN PRELOADS
================= */
/* =================
jQuery version of fillPreloads
by Grunny at starwars.wikia.com
=================
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. */
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 );
} );
}
/* ================
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 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',
fadeDelay : 1000
};