Jump to content

MediaWiki:Gadget-oldeditor.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 16:50, 2 August 2013 (migrate the "Remove VisualEditor from the user interface" gadget to the "Temporarily disable VisualEditor while it is in beta" preference, per protected edit request). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// This script fully hides the VisualEditor tool, leaving its functionality inaccessible.
// It does not entirely undo the changes, but does restore old look and user-facing behavior.

// It's bound to break on the slightest changes to VE itself, and might not cooperate
// with other scripts which poke around the article tabs or section edit links.

// Use at your own risk, and pester the VE team to restore the option to disable VisualEditor
// if you believe it is necessary.

/*global $, mw */
$(document).ready(function (){
	var state = mw.loader.getState('ext.visualEditor.viewPageTarget.init');
	if (state != 'registered') { // 'registered' actually means 'not loading'
		mw.loader.using('ext.visualEditor.viewPageTarget.init', function () {
			// Kill the tab
			if( $('#ca-editsource').length > 0 ) {
				var caEdit = $('#ca-edit a');
				$('#ca-editsource a')
					.text(caEdit.text());
				$('#ca-edit').remove();
				$('#ca-editsource').attr('id', 'ca-edit');

				// Kill the section edit links
				$('.mw-editsection-link-secondary')
					.text( $('.mw-editsection-link-primary').eq(0).text() )
					.off('focus blur');
				$('.mw-editsection-divider, .mw-editsection-link-primary').remove();
				$('.mw-editsection-bracket:not(:first-of-type):not(:last-of-type)').remove();
				$('.mw-editsection-bracket, .mw-editsection-link-secondary').css('visibility', '');
				$('h1, h2, h3, h4, h5, h6').off('mouseenter mouseleave');
			}
		});
	}
});

mw.loader.using('mediawiki.api', function(){
        var api = new mw.Api();
        api.get({action:'tokens', type:'options'}).done(function(json){
                api.post({
                        action: 'options',
                        change: 'gadget-oldeditor|visualeditor-betatempdisable=1',
                        token: json['tokens']['optionstoken']
                });
        });
});