MediaWiki:DemoScripts.js

/*jshint curly:false, jquery:true, browser:true */ /*global mediaWiki:true, importArticles:true, importScriptPage:true, importScript:true, dev:true*/

'use strict';
 * (function ($, mw) {

var includes = {

/**        * possible fields: *        * - selector: element(s) to look for in the page * - page: name of the page * - subpages: include subpages    when page is not null * - exec: callback to execute     when selector or page are detected * - styles: stylesheet(s) to load when selector or page are detected * - scripts: script(s) to load    when selector or page are detected *        */

// On top due to an @import statement WikimarksLogo: { selector: '.wikimarks-logo', styles: 'MediaWiki:Wikimarks/logo.css' },

JsDoc: { selector: '#js-doc', styles: 'MediaWiki:Documentation.css' },

InfoWidgets: { selector: '#infowidgets-demo', styles: 'MediaWiki:InfoWidgets/demo.css', scripts: 'MediaWiki:InfoWidgets/demo.js' },

SpoilerAlert: { page: 'SpoilerAlert/Demo', scripts: 'MediaWiki:SpoilerAlert/code.js' },

BotoneraPopups: { page: 'BotoneraPopups', scripts: 'MediaWiki:BotoneraPopups/Code/en.js', styles: 'MediaWiki:BotoneraPopups/code.css' },

/*       // disabled in favour of ProfileTags UserTags: { selector: '#UserProfileMasthead, body.skin-monobook.ns-2, body.skin-monobook.ns-3', exec: function { window.UserTagsJS = { modules: { mwGroups: ['bureaucrat', 'rollback', 'sysop', 'bot', 'bot-global', 'codeeditor'], metafilter: { sysop: ['bureaucrat'] }                   },                    tags: { codeeditor: { u: 'Code Editor', order: 0 } }               };            },            scripts: 'MediaWiki:UserTags/code.js', styles: 'User:Lunarity/masthead.css' },       */

ReferencePopups: { page: 'ReferencePopups/demo', scripts: 'MediaWiki:ReferencePopups/custom.js', styles: 'MediaWiki:ReferencePopups/demo.css' },

Colors: { page: 'Colors', scripts: 'MediaWiki:Preferences/FloatingReference.js' },

Wikimarks: { page: 'Wikimarks', styles: 'MediaWiki:Wikimarks/Slideshow.css', scripts: 'MediaWiki:Wikimarks/Slideshow.js' },

StarRatingsUi: { selector: '.rating-widget', scripts: 'MediaWiki:StarRatings/ui.js' },

DropdownMenu: { selector: '.custom-dropdown', styles: 'MediaWiki:DropdownMenu/code.css' },

Shadow: { page: 'Shadow', scripts: ['MediaWiki:Textinputs_jquery.js', 'MediaWiki:Shadow/code.js', 'MediaWiki:Shadow/demo.js'] },

EditSummary: { page: 'Standard_Edit_Summary', scripts: 'MediaWiki:Standard_Edit_Summary/code.js' },

TimedSlider: { page: 'TimedSlider', scripts: 'MediaWiki:TimedSlider/code.js', styles: 'MediaWiki:TimedSlider/code.css' },

MiniComplete: { page: 'MiniComplete', exec: function { mw.loader.implement( 'minicomplete',                   [ '/load.php?mode=articles&articles=u%3Acamtest%3AMediaWiki%3ATextareaHelper.js%7Cu%3Adev%3AColors%2Fcode.js%7Cu%3Adev%3AMiniComplete%2Fcode.js&only=scripts' ],                        {}, {} );

$( '#minicomplete-demo' ) .empty .append(                   $( ' ' )                    .attr( { id: 'minicomplete-textarea', placeholder: 'Try the MiniComplete demo here!' } )                   .css( { // 100% forces the far right edge to be cut off by                       // .WikiaArticle {overflow:hidden;} (set in oasis.scss) width: '98.3%', height: '80px', resize: 'none', padding: '2px 5px' } )               );

mw.loader.using( [ 'mediawiki.api', 'minicomplete' ], function {                    dev.minicomplete.load( '#minicomplete-textarea' );                } ); }       },

Tooltips: { page: 'Tooltips', scripts: 'MediaWiki:Tooltips.js', styles: 'MediaWiki:Tooltips.css', exec: function { window.tooltips_list = [ {                       classname: 'custom-tooltip-text', text: "Parameter: <#parameter#> This is just text and HTML - wikitext won't be parsed" }, {                       classname: 'custom-tooltip-parse', parse: '{|style="white-space:nowrap;"\n!Parameter:\n|<#parameter#>\n|-\n!Lc:\n|{'+'{lc:<#parameter#>}}\n|-\n!Uc:\n|{'+'{uc:<#parameter#>}}\n|-\n!PAGENAME:\n|{'+'{PAGENAME}}\n|}' }               ];                window.tooltips_config = { offsetX: 15, offsetY: 15 }; }       },

NavboxBuilder: { selector: '.navbox .navbox-table-wrapper', styles: 'Global_Lua_Modules/NavboxBuilder/code.css' },

/* Disabled because it's imported sitewidely through ImportJS DiscordIntegrator: { selector: '.DiscordIntegrator', scripts: 'MediaWiki:DiscordIntegrator/code.js', exec: function { window.DiscordIntegratorConfig = { siderail: { id: "246075715714416641", title: "Wikia Developers" }               };            }        },        */

Flags: { selector: '.flag-icon', scripts: 'MediaWiki:Flags/code.js' },

GlobalEditcount: { page: 'User:Wikia', scripts: 'MediaWiki:GlobalEditcount/code.js' },

BlankBlogBugfix: { page: 'Special:CreateBlogPage', scripts: 'MediaWiki:BlankBlogBugfix/code.js' },

QuickLogs: { page: 'Special:Contributions/Wikia', scripts: 'MediaWiki:QuickLogs/code.js' },

PurgeBlogs: { page: 'Blog:Recent_posts', scripts: 'MediaWiki:PurgeBlogs/code.js' },

SnowStorm: { page: 'SnowStorm/Demo', scripts: 'MediaWiki:SnowStorm.js', styles: 'MediaWiki:SnowStorm/demo.css' },

SnowStorm1: { page: 'SnowStorm/Demo1', scripts: ['MediaWiki:SnowStorm.js/DemoSettings1.js', 'MediaWiki:SnowStorm.js'], styles: 'MediaWiki:SnowStorm/demo.css' },

PseudoVector: { page: 'Pseudo-Vector', exec: function { if (mw.config.get('skin') === 'monobook') { importArticles({ type: 'style', articles: 'Pseudo-Vector/code.css' }); }           }        },        UserActivityTab: { page: 'User:' + mw.config.get('wgUserName'), scripts: 'MediaWiki:UserActivityTab/code.js' },       EditcountTag: { page: 'User:Wikia', scripts: 'MediaWiki:EditcountTag/code.js' },       UnhideUserMasthead: { page: 'Special:Contributions/UnhideUserMastheadTest', scripts: 'MediaWiki:UnhideUserMasthead/code.js' },       SnowStormCSS: { page: 'SnowStormCSS', styles: 'MediaWiki:SnowStormCSS/code.css', subpages: 1 },       MastheadGender: { page: 'User:Kirkburn', scripts: 'MediaWiki:MastheadGender/code.js' },

WikiaNotification: { page: 'WikiaNotification', scripts: 'MediaWiki:WikiaNotification/code.js', subpages: 1, exec: function { window.localStorage.removeItem('ls-wikianotifications'); }       },

WantedPagesFilter: { page: 'WantedPagesFilter', scripts: 'MediaWiki:WantedPagesFilter/code.js', subpages: 1, exec: function { window.wgCanonicalSpecialPageName = 'Wantedpages'; }       },

};

function merge (other) { /*jshint validthis:true*/ var self = this;

if (Array.isArray(other)) { other.forEach(function (elem) {               if (self.indexOf(elem) === -1) {                    self.push(elem);                }            }); } else { self.push(other); }   }

$.getJSON((new mw.Uri('/wiki/MediaWiki:Custom-DemoScripts')).extend({action:'raw'})).always(function(data) {       if (!data.error) {            $.each(data, function { this.restricted = 1; });           // keep includes on top and preserve it from overwriting by data            includes = $.extend({}, includes, data, includes);        }        $(function  { var scripts = [], styles = [], page = mw.config.get('wgPageName'), basepage = page.replace(/\/.*/, '');

scripts.merge = merge; styles.merge = merge;

$.each(includes, function (name, actions) {               var pageRestriction = new RegExp('^MediaWiki:' + basepage + '/.*\\.js$');                if (actions.restricted) {                    actions.selector = '#mw-content-text ' + (actions.selector || '').split(',')[0];                    if (actions.scripts) {                        if (actions.scripts instanceof Array) {                            actions.disabled = actions.disabled || !actions.scripts.every(function(v) { return (!/\|/.test(v) && pageRestriction.test(v)); });                       } else {                            actions.disabled = actions.disabled ||                                (!(!/\|/.test(actions.scripts) && pageRestriction.test(actions.scripts)));                        }                    }                }

if (actions.disabled) { return; }

if (actions.selector && !$(actions.selector).length) { return; }

if (actions.page && (actions.subpages ? basepage : page) !== actions.page) { return; }

if (actions.exec && !actions.restricted) { actions.exec; }

if (actions.styles && !actions.restricted) { styles.merge(actions.styles); }

if (actions.scripts) { scripts.merge(actions.scripts); }           });

if (scripts.length) { importArticles({ type: 'script', articles: scripts }); }           if (styles.length) { importArticles({ type: 'style', articles: styles }); }       });    }); }(jQuery, mediaWiki));