MediaWiki:ToggleTestMode/code.js

/* * Toggle JS testmode using a link in the toolbar * * @author Cqm  * @version 0.1 * * @todo support monobook */

/*global jQuery, mediaWiki */

/*jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, es3:false, forin:true, immed:true, indent:4, latedef:true, newcap:true, noarg:true, noempty:true, nonew:true, plusplus:true, quotmark:single, undef:true, unused:true, strict:true, trailing:true, browser:true, devel:false, jquery:true, onevar:true

'use strict';
 * (function ($, mw) {

/*        *         */    var conf = mw.config.get([            'wgContentReviewTestModeEnabled'        ]),

/*        *         */        testmode = { /*            *             */            enable: function (e) { e.preventDefault;

if (conf.wgContentReviewTestModeEnabled) { location.reload; }

var data = { editToken: mw.user.tokens.get('editToken') };

$.nirvana.postJson('ContentReviewApi', 'enableTestMode', data) .done(function {                        location.reload(true);                    }); },

/*            *             */            disable: function (e) { e.preventDefault;

if (!conf.wgContentReviewTestModeEnabled) { location.reload; }

var data = { editToken: mw.user.tokens.get('editToken') };

$.nirvana.postJson('ContentReviewApi', 'disableTestMode', data) .done(function {                        location.reload(true);                    }); }       };

/*    *     */    function init { $('#WikiaBarWrapper .tools').append(           $('')                .addClass('dev-testmode')                .append( $('') .attr({                           href: '#',                            id: 'dev-testmode-toggle'                        }) .css('cursor', 'pointer') .text(                           conf.wgContentReviewTestModeEnabled ?                                 'Disable JS testmode' :                                'Enable JS testmode'                        ) )       );

var $toggle = $('#dev-testmode-toggle');

if (conf.wgContentReviewTestModeEnabled) { $toggle.click(testmode.disable); } else { $toggle.click(testmode.enable); }   }

window.dev = window.dev || {}; window.dev.testmode = testmode;

$(init);

}(jQuery, mediaWiki));