MediaWiki:Gadget-Preload.js

/** * Template Preloads * Replaces Wikia's template preloads with something more useful * * @author       Grunny (Wookieepedia) * @author      A proofreader * @author      Ryan PM * @author       Cqm * @dependencies insertAtCursor * @todo        Rewrite and implement as default gadget */

// define global objects this.mwConfig = this.mwConfig || this.mediaWiki.config.values; this.rswiki = this.rswiki || {}; this.rswiki.gadgets = this.rswiki.gadgets || {};

(function (document, $, mwConfig) {

'use strict';

function customPreloadTemplates {

if ((mwConfig.wgAction !== 'edit' && mwConfig.wgCanonicalSpecialPageName !== 'CreatePage') || !$('div.module_content').length) { return; }

var preloadOptionsHtml = '', $preloadOptionsList, preloadBaseHtml = ' Standard preloads: Custom preload pagename: ';

$('span.cke_buttons.cke_toolbar_templates').replaceWith(preloadBaseHtml);

$.get(           mwConfig.wgScript,            {                title: 'Template:Stdpreloads',                action: 'raw',                ctype: 'text/plain'            },            function (data) {

var lines = data.split('\n'), i,                   value;

for (i = 0; i < lines.length; i += 1) { value = (lines[i].indexOf('-- ') === 0) ? lines[i].substring(3) : ''; preloadOptionsHtml += '' + lines[i] + ' '; }

// @todo change id to #stdPreloads // need to check there's no dependencies anywhere else $preloadOptionsList = $(' ') .attr({                       'id': 'stdSummaries'                    }) .html(preloadOptionsHtml) .change(function {                        var page = $(this).val;

if (page !== '') {

value = 'Template:' + page + '/preload'; page = page.replace(/ /g, '_');

$.get(                               mwConfig.get('wgScript'),                                {                                    title: page,                                    action: 'raw',                                    ctype: 'text/plain'                                },                                function (data) {                                    insertAtCursor(document.getElementById('wpTextbox1'), data);                                }                            ); }                   });

$('div#lf-preload').append($preloadOptionsList); }       );

$('#lf-preload-pagename-w').html(''); $('#lf-preload-button-w').html('');

}

$(customPreloadTemplates);

function doCustomPreloadOasis { var value = $('#lf-preload-pagename-w > input').val.replace(/ /g, '_'); $.get(           mwConfig.wgScript,            {                title: value,                action: 'raw',                ctype: 'text/plain'            },            function (data) {                insertAtCursor(document.getElementById('wpTextbox1'), data);            }        ); }

}(this.document, this.jQuery, this.mwConfig));

/* */