MediaWiki:DemoScripts.js

/*jshint curly:false, jquery:true, browser:true */ /*global mediaWiki:true, importArticles:true, importArticle: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: exclude subpages    when set to false * - 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' },

BotoneraPopups: { page: 'BotoneraPopups', scripts: 'MediaWiki:BotoneraPopups/Code/en.js', styles: 'MediaWiki:BotoneraPopups.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.css' },

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: 'MediaWiki:Global_Lua_Modules/NavboxBuilder.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' },

QuickLogs: { page: 'Special:Contributions/Wikia', scripts: 'MediaWiki:QuickLogs/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' },

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' },

MastheadGender: { page: 'User:Kirkburn', scripts: 'MediaWiki:MastheadGender/code.js' },

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

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

Wikificator: { page: 'Wikificator', scripts: 'MediaWiki:Wikificator.js', exec: function { if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) return; mw.loader.load('jquery.textSelection'); window.wikificator.forced = true; var t = $('#wpTextbox1').text; $('#wpTextbox1').replaceWith($(' ', {id: 'wpTextbox1', value: t, style: 'width:inherit;min-width:50%;height:inherit;min-height:100px;'})); }       },        ModernRail: { page: 'ModernRail', styles: 'MediaWiki:ModernRail.css' },

EasyUserTags: { page: 'User:WikiaBot', scripts: 'MediaWiki:EasyUserTags/code.js' },

CSSForTheColorBlind: { page: 'CSSForTheColorBlind', styles: 'MediaWiki:CSSForTheColorBlind.css' },

FandomIcons: { page: 'FandomIcons', styles: 'MediaWiki:FandomIcons.css' },

Contextlink: { selector: '.context-link', styles: 'MediaWiki:Global_Lua_Modules/Context-link.css' },

Mbox: { selector: '.mbox', styles: 'MediaWiki:Global_Lua_Modules/Mbox.css' },

Less: { selector: 'body.page-MediaWiki_Custom-Less_test_less, body.page-MediaWiki_Custom-Less_test_css', scripts: 'MediaWiki:Less/code.2.js', exec: function { // example config used for testing window.lessOpts = [{ target: 'MediaWiki:Custom-Less/test.css', source: 'MediaWiki:Custom-Less/test.less', load: [ 'MediaWiki:Custom-Less/test.css', 'MediaWiki:Custom-Less/test.less' ],                   header: 'MediaWiki:Custom-less-header' }];               window.lessConfig = { allowed: ['user'] };           }        },

LightGlobalNav: { page: 'LightGlobalNav', styles: 'MediaWiki:LightGlobalNav.css' },

Katsuragi: { page: 'Katsuragi', styles: 'MediaWiki:Katsuragi.css' },

BackToTopButton: { page: 'BackToTopButton', scripts: 'MediaWiki:BackToTopButton/code.js', exec: function { window.BackToTopModern = true; }       },        BlendGlobalNav: { page: 'BlendGlobalNav', styles: 'MediaWiki:BlendGlobalNav.css' },       UpgradedToolbar: { page: 'UpgradedToolbar', styles: 'MediaWiki:UpgradedToolbar.css' },

GlobalNavigationIcons: { page: 'GlobalNavigationIcons', styles: 'MediaWiki:GlobalNavigationIcons.css' },

SearchSuggest: { page: 'Special:Search', scripts: 'MediaWiki:SearchSuggest/code.js' },       UserCheck: { page: 'Special:Contributions/Klopsik600', scripts: 'MediaWiki:UserCheck/code.js' },

DisambiguationManagement: { page: 'Special:Disambiguations', scripts: 'MediaWiki:DisambiguationManagement/code.js' },

FileLogs: { page: 'File:QQX_Oasis.png', scripts: 'MediaWiki:FileLogs.js' },       MastheadRightsBadge: { page: 'User:Railfail536', scripts: 'MediaWiki:MastheadRightsBadge.js' },

TZclock: { page: 'TZclock', scripts: 'MediaWiki:TZclock.js', styles: 'MediaWiki:TZclock.css' },       UserStatus: { page: 'User:SapphireSonata', scripts: 'MediaWiki:UserStatus.js' },   };

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); }   }

$.get(mw.util.wikiScript('load'), {       mode: 'articles',        articles: 'MediaWiki:Custom-DemoScripts',        only: 'styles',        cb: Date.now    }).always(function(data) {        if (data && !data.error) {            data = JSON.parse(data.replace(/\/\*.*\*\//g, ''));            $.each(data, function { this.restricted = 1; });           // keep includes on top and preserve it from overwriting by data            includes = $.extend(true, {}, 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 === false ? page : basepage) !== 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));