MediaWiki:UserStatus/dropdown/demo.js

/** * * @submodule              UserStatus/dropdown/demo * @description            Dropdown menu to quickly change one's status. * @author                 Americhino * @version                0.8.3 * @license                CC-BY-SA 3.0 * @notes                  Only a demo for User:SapphireSonata. *                         Please see the documentation for UserStatus. **/ var $user = mw.config.get('wgTitle').split('/'); // if (($user[1] ? $user[1] : $user[0]) === 'SapphireSonata') { mw.hook('dev.i18n').add(function (i18n) {       i18n.loadMessages('UserStatus').done(function (i18n) { var $statusLink = $(' ') .attr('id', 'StatusChangeWrapper').append(               $(' ')                    .addClass('wds-dropdown')                    .attr('id', 'StatusChange').append ( $('').attr( 'title', 'Change your status (demo)' ) .attr('style', 'cursor: pointer; margin-top: 10px;' ).text('Status') .attr('id', 'StatusToggle') .addClass('wds-button wds-is-secondary wds-dropdown__toggle').append(                               $('  ')                        ) .after(                       $(' ')                        .addClass('wds-is-not-scrollable wds-dropdown__content wds-is-left-aligned').append( $(' ')                               .addClass('wds-list wds-is-linked') .attr('id', 'StatusMenu') .append(                               $('').append( $('') .attr('target', '_blank') .attr('style', 'cursor: pointer;') .attr('id', 'StatusMenu-online') .text(i18n.msg('online').plain) ).after( $('').append(                                   $('')                                    .attr('target', '_blank')                                    .attr('style', 'cursor: pointer;')                                    .attr('id', 'StatusMenu-away')                                    .text(i18n.msg('away').plain)                                )).after( $('').append(                                   $('')                                    .attr('target', '_blank')                                    .attr('style', 'cursor: pointer;')                                    .attr('id', 'StatusMenu-dnd')                                    .text(i18n.msg('dnd').plain)                                )).after( $('').append(                                   $('')                                    .attr('target', '_blank')                                    .attr('style', 'cursor: pointer;')                                    .attr('id', 'StatusMenu-unknown')                                    .text(i18n.msg('offline').plain)                                ))                            ) )                   )                )            );             $('.UserProfileMasthead .masthead-info > .details').append($statusLink); $('body').on('click', 'a[id^="StatusMenu-"]', function(e) {               e.preventDefault;                switch ($(e.target).attr('id')) {                    case 'StatusMenu-online':                    $.ajax({ type: 'POST', url: mw.util.wikiScript('api'), dataType: 'json', data: { action: 'edit', title: wgFormattedNamespaces[2] + ':SapphireSonata/status', summary: i18n.msg('edit-status').plain + ' (demo)', text: 'online', format: 'json', token: mw.user.tokens.get('editToken') }                       }).done(function (data) { if (data.edit.result === 'Success') { new BannerNotification (i18n.msg('success').plain, 'confirm').show; } else { new BannerNotification (i18n.msg('error').plain, 'error').show; }                       }).fail(function (data) { new BannerNotification (i18n.msg('error').plain, 'error').show; });                       break;                    case 'StatusMenu-away':                    $.ajax({ type: 'POST', url: mw.util.wikiScript('api'), dataType: 'json', data: { action: 'edit', title: wgFormattedNamespaces[2] + ':SapphireSonata/status', summary: i18n.msg('edit-status').plain + ' (demo)', text: 'away', format: 'json', token: mw.user.tokens.get('editToken') }                       }).done(function (data) { if (data.edit.result === 'Success') { new BannerNotification (i18n.msg('success').plain, 'confirm').show; } else { new BannerNotification (i18n.msg('error').plain, 'error').show; }                       }).fail(function (data) { new BannerNotification (i18n.msg('error').plain, 'error').show; });                       break;                    case 'StatusMenu-dnd':                        $.ajax({ type: 'POST', url: mw.util.wikiScript('api'), dataType: 'json', data: { action: 'edit', title: wgFormattedNamespaces[2] + ':SapphireSonata/status', summary: i18n.msg('edit-status').plain + ' (demo)', text: 'dnd', format: 'json', token: mw.user.tokens.get('editToken') }                           }).done(function (data) { if (data.edit.result === 'Success') { new BannerNotification (i18n.msg('success').plain, 'confirm').show; } else { new BannerNotification (i18n.msg('error').plain, 'error').show; }                           }).fail(function (data) { new BannerNotification (i18n.msg('error').plain, 'error').show; });                       break;                    case 'StatusMenu-offline':                        $.ajax({ type: 'POST', url: mw.util.wikiScript('api'), dataType: 'json', data: { action: 'edit', title: wgFormattedNamespaces[2] + ':SapphireSonata/status', summary: i18n.msg('edit-status').plain + ' (demo)', text: 'offline', format: 'json', token: mw.user.tokens.get('editToken') }                           }).done(function (data) { if (data.edit.result === 'Success') { new BannerNotification (i18n.msg('success').plain, 'confirm').show; } else { new BannerNotification (i18n.msg('error').plain, 'error').show; }                           }).fail(function (data) { new BannerNotification (i18n.msg('error').plain, 'error').show; });                       break;                }            }); });   });    var buttonColor = mw.config.get('wgSassParams')['color-buttons']; mw.util.addCSS('#StatusToggle { color:' + buttonColor + '; border-color:' + buttonColor + '}') // } importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:i18n-js/code.js',		'u:dev:MediaWiki:UserStatus.js',    ],    type: 'style',    articles: [        'u:dev:MediaWiki:UserStatus.css',    ] });