MediaWiki:Applications.js

/* jshint jquery:true */

if (App.noop || App.DoNotLoad) return; var mwConfig = mw.config.get([           'wgPageName',            'wgUserName',            'skin'        ]), RequestForRights = $.extend(App, {           name: 'Request For Rights',            version: '0.1.0 alpha',            char_min: 200,            page: 'Project:Request For Rights/New requests',            defaultItem: 'Select a right that you want to apply for.',            getAllURLQueries: function{                var json_obj = '{',                    parts = window.location.href.split(/[?&]/g),                    no_path = parts.filter(function(part){ return !(/http(?:s|):\/\/(.*)/).test(part); }),                   var_obj = no_path.map(function(part){ var _parts = part.split('='); _parts[0] = '"' + _parts[0] + '"'; _parts[1] = '"' + _parts[1] + '"'; return _parts.join(':'); }),                   _obj = var_obj.join(', ');                json_obj = json_obj.concat(_obj);                json_obj = json_obj.concat('}');                return JSON.parse(json_obj);            },            rights: {                'Main Rights': ['Rollback', 'Chat Moderator', 'Discussion Moderator', 'Administrator', 'Bureaucrat'],                'Other': ['Code Editor', 'Patroller']            }        }); RequestForRights.createHTML = function{ var $html = $(''), $form = $(''), $form_html = $(' '), $rfa_button = $('').text('Submit Application'); $form_html.html(function{           var $username = $(' ')                    .html([ $(' ')                           .html('Username: '), $(' ')                           .html([                                $(' '),                                $(' ')                                    .html(mwConfig.wgUserName)                            ]) ]),               $rights = $(' ')                    .html([ $(' ')                           .html('Position: ') .on('click', function(event){                               if (!event.target.nexSibling) return;                                var $dropdown = $(event.target.nextSibling);                                $dropdown.show(500);                            }), $('') .html([                               $(' ')                                    .text(RequestForRights.defaultItem),                                $(' ')                                    .html(function{ var $default = $('').text(RequestForRights.defaultItem).on('click', function(event){                                               event.preventDefault;                                                var $box_selected = $(event.target.hash).find('.rfa-selected');                                                $box_selected.text(event.target.innerText);                                                $(event.target.parentElement).hide(500);                                            }), items = RequestForRights.rights, $items = null, $_html = [$default]; $items = Object.keys(items).map(function(name, index){                                           var $h = $('').text(name),                                                $u = $(''),                                                $g = $(' '),                                                _items = items[name];                                            $u.html(_items.map(function(_item, _i){                                                var $item = $('');                                                $item.html( $('').text(_item).on('click', function(event){                                                       event.preventDefault;                                                        var $box_selected = $(event.target.hash).find('.rfa-selected');                                                        $box_selected.text(event.target.innerText);                                                        $(event.target.hash).hide(500);                                                    }) );                                               return $item;                                            }));                                            $g.html([$h, $u]);                                            return $g;                                        }); $items.forEach(function(_item_){                                           $_html[$_html.length] = _item_;                                        }); return $_html; })                           ])                    ]),                $reason = $(' ')                        .html([ $(' ')                               .text('Reason: '), $(' ')                               .html(                                    $('')                                    .attr('rows', '5')                                    .on('keypress change', function(event){ var $textarea = $(event.target), value = $textarea.val; $('#rfa-description-count').text(value.length - RequestForRights.char_min); }),                                   $(' ')                                    .text($('#rfa-description').val.length - RequestForRights.char_min)                                ), ]);           $.ajax({ method: 'GET', dataType: 'json', url: mw.util.wikiScript('wikia'), data: { controller: 'UserProfilePageController', method: 'renderUserIdentityBox', title: 'User:' + mwConfig.wgUserName.replace('_', ' '), format: 'json' }           }).done(function(data){ var avatar = data.user.avatar; $username.find('.avatar').attr('src', avatar.replace(/\/scale-to-width\/(?:.*)/g, '/scale-to-width-down/60')); });           return [$username, $rights, $reason];        }); $rfa_button.on('click', function validate(event){           // To make sure that the button does not go to a new page            event.preventDefault;            var $u = $('#rfa-username .username'),                $r = $('#rfa-rights .rfa-selected'),                $d = $('#rfa-description'),                url = event.target.href,                now = new Date,                months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],                ampm = now.getHours > 12 ? 'PM' : 'AM';            if ($r.text == RequestForRights.defaultText){                $(event.target).before( $('').text('Please select a position to apply for.') .animate({                       'opacity': '0'                     }, 1000).promise.done(function{                        $(this).remove;                    }) );               return;            }            if ($d.val === ''){                $(event.target).before( $('').text('The description cannot be empty. Please try again after you have typed out the description.') .animate({                       'opacity': '0'                     }, 1000).promise.done(function{                        $(this).remove;                    }) );               return;            }            if ($d.val.length < RequestForRights.char_min){                $(event.target).before( $('').text('The description must have at least 200 characters in order for you to continue.') .animate({                       'opacity': '0'                     }, 1000).promise.done(function{                        $(this).remove;                    }) );               return;            }            function pad(n){                if (n < 10) n = "0" + n;                return n;            }            var template =                 '== ' +                     $u.text + ' (' + months[now.getMonth] + ' ' + now.getDate + ', ' + now.getFullYear + ' ' + pad(now.getHours) + ':' + pad(now.getMinutes) + ':' + pad(now.getSeconds) + ' ' + ampm + ')' +               '==';            template +=                '*\'\'\'Position:\'\'\' ' + $r.text +                '*\'\'\'Description:\'\'\' ' + $d.val;            $.ajax({ method: 'POST', url: mw.util.wikiScript('api'), data: { action: 'edit', text: template, title: url.replace('/wiki/', '').replace('_', ' '), section: 'new', token: mw.user.tokens.values.editToken }           }).done(function(data){ window.open(url, '_self'); });       });        $form.append([$form_html, $rfa_button]); $html.append($form); return $html; };   if (        Array.prototype.some.call(['oasis', 'wikia'], function(_skin){ return _skin == mwConfig.skin; }) ||       (RequestForRights.getAllURLQueries.blankspecial == 'rfr-apps' && mwConfig.wgPageName == 'Special:BlankPage')   ){ $('.mw-content-text').html(RequestForRights.createHTML); } })(this.mediaWiki, this.jQuery, this.RFR = this.RFR || {});
 * (function(mw, $, App){