MediaWiki:NewUserIdentityBox/code.2.js

(function(mw, $, factory){   var hasMasthead = !($('#UserProfileMasthead').length === 0);    if (!hasMasthead) return;    else {        if (typeof window.UserIdentityBox !== 'undefined') return;        factory(mw, $);    } }(this.mediaWiki, this.jQuery, function(mw, $){ var identityBox = {}, slice = [].slice, hasOwn = ({}).hasOwnProperty; identityBox.exists = function(property, callback, args){ var exists = hasOwn.call(this, property); if (typeof callback === 'function' && exists){ callback.apply(this, (typeof args === 'object' && args instanceof Array) ? args : []); } else { return exists; }   };

identityBox.importResources = function{ var uibResources = Object.keys(typeof window.UIBResources == 'object' ? window.UIBResources : {}), scripts = [], styles = [], resources = $.merge([               'u:dev:MediaWiki:WDSIcons/code.js',                'u:dev:MediaWiki:ModernProfile/Masthead.css',                'u:dev:MediaWiki:ModernProfile/Wall.css'            ], uibResources); $.each(resources, function(index, resource){           if (resource.endsWith('.css')){                styles[styles.length] = resource;            } else if (resource.endsWith('.js')){                scripts[scripts.length] = resource;            }        }); importArticles(           { type: 'style', articles: styles },            { type: 'script', articles: scripts }        ); };   identityBox.createEditButton = function{ var actions = mw.config.get('wgWikiaPageActions'), buttonGroup = $(' ', {               'class': 'page-header__contribution-buttons',                html: $(' ', { 'class': 'wds-button-group' })           }),            dropdown = $(' ', {                'class': 'wds-dropdown',                html: '\                \                     \                \                '            }), allowedActions = ['Edit', 'History', 'Move', 'Protect', 'Delete']; actions.filter(function(action){           var allowed = allowedActions.map(function(a){ return 'page:' + a });            return allowed.indexOf(action.id) > -1;        }).forEach(function(action){            var currAction = null, button = null, actionName = action.id.replace('page:', '').toLowerCase;            if (action.id === 'page:Edit'){                currAction = action;                if (currAction){                    button = $('', { 'href': currAction.href, 'class': 'wds-is-squished wds-is-secondary wds-button', 'id': 'ca-' + actionName, 'data-tracking': 'ca-' + actionName });                   $;                }            }        });    }; }));