MediaWiki:Gadget-PreloadTemplates.js: Difference between revisions
From Tardis Wiki, the free Doctor Who reference
MediaWiki:Gadget-PreloadTemplates.js (view source)
Revision as of 21:41, 17 October 2017
, 17 October 2017display name, case-by-case preload page
(Undo revision 63404 by Radagast l'animal (talk)) |
(display name, case-by-case preload page) |
||
Line 23: | Line 23: | ||
return; | return; | ||
} | } | ||
console.log('[PreloadTemplates]: version 1. | console.log('[PreloadTemplates]: version 1.02 - 17/10/2017.'); | ||
// ================= | // ================= | ||
Line 237: | Line 237: | ||
var namespace = mw.config.get('wgFormattedNamespaces')['10']; | var namespace = mw.config.get('wgFormattedNamespaces')['10']; | ||
var $preloadOptionsHtml; | var $preloadOptionsHtml; | ||
var preloadOptionsList; | var $preloadOptionsList; | ||
var defaultOption = '<option selected disabled>' + i18n.choose + '</option>'; | var defaultOption = '<option selected disabled>' + i18n.choose + '</option>'; | ||
var preloadHelp = '<span style="display:inline-block; vertical-align:middle; cursor:help; margin-left:5px;" class="sprite question"><a href="http://dev.wikia.com/wiki/PreloadTemplates" target="_blank" title="' + i18n.devWiki + '" style="display:inline-block; width:12px; height:12px;"></a></span>'; | var preloadHelp = '<span style="display:inline-block; vertical-align:middle; cursor:help; margin-left:5px;" class="sprite question"><a href="http://dev.wikia.com/wiki/PreloadTemplates" target="_blank" title="' + i18n.devWiki + '" style="display:inline-block; width:12px; height:12px;"></a></span>'; | ||
Line 267: | Line 267: | ||
for (var i in lines) { | for (var i in lines) { | ||
var title; | var title; | ||
// Ignore empty lines | // Ignore empty lines | ||
Line 276: | Line 275: | ||
if (lines[i].indexOf('*') === 0) { | if (lines[i].indexOf('*') === 0) { | ||
title = lines[i].substring(1).trim(); | title = lines[i].substring(1).trim(); | ||
$preloadOptionsHtml += '<option value="' + title + '">' + title + '</option>'; | |||
// Text after pipe is display name | |||
if (title.indexOf('|') !== -1) { | |||
var parts = title.split('|'); | |||
$preloadOptionsHtml += '<option value="' + parts[0].trim() + '">' + parts[1].trim() + '</option>'; | |||
} else { | |||
// No display name | |||
$preloadOptionsHtml += '<option value="' + title + '">' + title + '</option>'; | |||
} | |||
} else { | } else { | ||
// Rest are normal strings | // Rest are normal strings | ||
title = lines[i].trim(); | |||
$preloadOptionsHtml += '<option disabled>' + | $preloadOptionsHtml += '<option disabled>' + title + '</option>'; | ||
} | } | ||
} | } | ||
// Build list HTML | // Build list HTML | ||
preloadOptionsList = $('<select />').attr('id', 'pt-list').attr('title', i18n.help).css('max-width' , '220px').html(defaultOption + $preloadOptionsHtml).change(function() { | $preloadOptionsList = $('<select />').attr('id', 'pt-list').attr('title', i18n.help).css('max-width' , '220px').html(defaultOption + $preloadOptionsHtml).change(function() { | ||
var templateTitle = $(this).val(); | var templateTitle = $(this).val(); | ||
Line 296: | Line 304: | ||
// Append template list and messageges | // Append template list and messageges | ||
$('div#preload-templates').append(preloadOptionsList).append(preloadHelp); | $('div#preload-templates').append($preloadOptionsList).append(preloadHelp); | ||
// Import required CSS for monobook | // Import required CSS for monobook | ||
Line 321: | Line 329: | ||
// Get preload text and add it to the text area | // Get preload text and add it to the text area | ||
function getPreloadPage(title) { | function getPreloadPage(title) { | ||
var page = namespace + ':' + title + '/' + config.subpage; | // check if subpage is standard or is case by case | ||
var page = ( config.subpage === 'case-by-case' ) ? namespace + ':' + title : namespace + ':' + title + '/' + config.subpage; | |||
$.get(wgScript, { | $.get(wgScript, { |