User:Animal-Jumping-2/Gadget-TwinkleMobile.js

(function ($, mw, OO) { if (mw.config.get( 'wgMFAmc' ) === true){   function loadCSS(resources) {        resources.forEach(function (resource) { mw.loader.load('/w/index.php?title=MediaWiki:Gadget-' + resource + '&action=raw&ctype=text/css', 'text/css'); });   }

function createBasketItems(resources) { var basketItems = []; resources.forEach(function (resource) {           basketItems.push({ url: '/w/index.php?title=MediaWiki:Gadget-' + resource + '&action=raw&ctype=text/javascript', key: resource, expire: 168 // Cache for 7 days });       });        return basketItems; }

function utils { // Don't zoom-in when focusing input $('head').append(''); // CSS for better Twinkle dialog on mobile mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Animal-Jumping-2/Gadget-TwinkleMobile.css&action=raw&ctype=text/css', 'text/css'); }

function main { var twinkleDependencies = ['morebits.js', 'select2.min.js', 'Twinkle.js'], twinkleModules = [ 'twinkleconfig.js', 'twinkleprod.js', 'twinkleimage.js', 'twinklewarn.js', 'twinkleblock.js', 'twinklespeedy.js', 'friendlyshared.js', 'twinklediff.js', 'twinkleunlink.js', 'friendlytag.js', 'twinkledeprod.js', 'friendlywelcome.js', 'twinklexfd.js', 'twinklebatchdelete.js', 'twinklebatchundelete.js', 'twinklebatchprotect.js', 'twinkleprotect.js', 'twinklearv.js', 'friendlytalkback.js' ],           twinkleModulePortletLinks = [];

utils; loadCSS(['morebits.css', 'select2.min.css']);

basket.require.apply(basket, createBasketItems(twinkleDependencies)).then(function {            // Override Twinkle.addPortletLink function            Twinkle.addPortletLink = function (task, text, id, tooltip) {                twinkleModulePortletLinks.push({ task: task, text: text, id: id, tooltip: tooltip });           };

// Fix bug on Minerva (it doesn't have this) mw.config.set('wgCategories', []);

// Fix bug on Special:MobileDiff pages if (mw.config.get('wgCanonicalSpecialPageName') === 'MobileDiff') { mw.config.set('wgNamespaceNumber', mw.Title.newFromText(mw.config.get('wgRelevantPageName')).getNamespaceId); mw.config.set('wgArticleId', mw.config.get('wgRelevantArticleId')); mw.config.set('wgPageName', mw.config.get('wgRelevantPageName')); mw.config.set('wgCurRevisionId', mw.config.get('wgDiffNewId')); Morebits.pageNameNorm = mw.config.get('wgRelevantPageName').replace(/_/g, ' '); window.history.replaceState(null, null, '?diff=' + mw.config.get('wgDiffNewId')); }

return basket.require.apply(basket, createBasketItems(twinkleModules)); }).then(function { setTimeout(function {                // Create TwinkleMobile portlet link and dialog                function TwinkleMobileDialog(config) {                    TwinkleMobileDialog.super.call(this, config);                }                OO.inheritClass(TwinkleMobileDialog, OO.ui.ProcessDialog);

TwinkleMobileDialog.static.name = 'TwinkleMobileDialog'; TwinkleMobileDialog.static.title = 'TwinkleMobile'; TwinkleMobileDialog.static.actions = [ {                       action: 'save', label: mw.message('ooui-popup-widget-close-button-aria-label').text, flags: ['primary', 'progressive'] }               ];

TwinkleMobileDialog.prototype.initialize = function { var dialog = this;

TwinkleMobileDialog.super.prototype.initialize.apply(this, arguments); this.panel = new OO.ui.PanelLayout({                       padded: true,                        expanded: false                    }); this.content = new OO.ui.FieldsetLayout;

var fields = []; twinkleModulePortletLinks.forEach(function (link) {                       var button;

if (typeof link.task === 'string') { button = new OO.ui.ButtonWidget({                               href: link.task,                                label: link.text,                                id: link.id,                                title: link.tooltip                            }); }

if (typeof link.task === 'function') { button = new OO.ui.ButtonWidget({                               label: link.text,                                id: link.id,                                title: link.tooltip                            }); button.on('click', function (e) {                               link.task;                                // Only close TwinkleMobile dialog when Twinkle dialog is opened                                if ($('.morebits-dialog').length !== 0) {                                    dialog.close;                                }                            }); }

fields.push(new OO.ui.FieldLayout(button)); });

if (fields.length === 0) { fields.push(new OO.ui.LabelWidget({ label: 'None' }));                   }

this.content.addItems(fields); this.panel.$element.append(this.content.$element); this.$body.append(this.panel.$element); };

TwinkleMobileDialog.prototype.getActionProcess = function (action) { var dialog = this; if (action) { return new OO.ui.Process(function {                            dialog.close({ action: action });                       });                    }                    return TwinkleMobileDialog.super.prototype.getActionProcess.call(this, action); };

TwinkleMobileDialog.prototype.getBodyHeight = function { return this.panel.$element.outerHeight(true); };

var windowManager = new OO.ui.WindowManager; $(document.body).append(windowManager.$element);

windowManager.addWindows([new TwinkleMobileDialog({ size: 'small' })]);

var twmbLink = mw.util.addPortletLink('p-navigation', '#', 'TwinkleMobile', 'twmb', 'TwinkleMobile'); $(twmbLink).click(function (e) {                   windowManager.openWindow('TwinkleMobileDialog');                    e.preventDefault;                }); }, 1000); // Execute this after all Twinkle modules is executed       }).catch(function (e) {            mw.log.error(e.message);        }); }

mw.loader.using([       'mediawiki.user', 'mediawiki.util', 'mediawiki.Title',        'mediawiki.api', 'mediawiki.language', 'jquery.ui',        'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'    ]).then(function  {        if (mw.config.get('wgUserGroups').includes('autoconfirmed') && mw.config.get('skin') === 'minerva') {           return new mw.Api.loadMessagesIfMissing([ 'ooui-popup-widget-close-button-aria-label' ]);       } else {            console.log('TwinkleMobile only works with Minerva skin and autoconfirmed users');        }    }).then(function  {        return mw.loader.getScript('https://tools-static.wmflabs.org/cdnjs/ajax/libs/basket.js/0.5.2/basket.full.min.js');    }).then(main).catch(function (e) {        mw.log.error(e.message);    }); } })(jQuery, mediaWiki, OO);