mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-27 15:40:00 +00:00
Remove some outdated code
Since WikiEditor uses wikiEditor-toolbar-doneInitialSections event we don't need to add it to ResourceLoader dependencies. Bug: T161475 Change-Id: I7c7c3ba495c0292d2df052145e7930c86fcb48f5
This commit is contained in:
parent
e2383eb772
commit
b7bc84d783
|
@ -39,11 +39,6 @@ class CodeMirrorHooks {
|
|||
'dependencies' => [ 'ext.CodeMirror.lib' => true ],
|
||||
];
|
||||
|
||||
// Check if WikiEditor is installed and add it as a dependency
|
||||
if ( \ExtensionRegistry::getInstance()->isLoaded( 'WikiEditor' ) ) {
|
||||
$extResources['dependencies']['ext.wikiEditor'] = true;
|
||||
}
|
||||
|
||||
// enable other extensions to add additional resources and modes
|
||||
Hooks::run( 'CodeMirrorGetAdditionalResources', [ &$extResources, &self::$extModes ] );
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
"dependencies": [
|
||||
"ext.CodeMirror.lib",
|
||||
"ext.CodeMirror.other",
|
||||
"mediawiki.api",
|
||||
"jquery.textSelection",
|
||||
"user.options",
|
||||
"mediawiki.api.options"
|
||||
"mediawiki.api",
|
||||
"mediawiki.api.options",
|
||||
"user.options"
|
||||
],
|
||||
"scripts": [
|
||||
"ext.CodeMirror.js"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
( function ( mw, $ ) {
|
||||
var origTextSelection, useCodeMirror, codeMirror, api, originHooksTextarea;
|
||||
var origTextSelection, useCodeMirror, codeMirror, api, originHooksTextarea, wikiEditorToolbarEnabled = false;
|
||||
|
||||
if ( mw.config.get( 'wgCodeEditorCurrentLanguage' ) ) { // If the CodeEditor is used then just exit;
|
||||
return;
|
||||
|
@ -12,6 +12,13 @@
|
|||
api = new mw.Api();
|
||||
originHooksTextarea = $.valHooks.textarea;
|
||||
|
||||
if ( mw.loader.getState( 'ext.wikiEditor' ) ) { // The WikiEditor extension exists
|
||||
// This can be the string "0" if the user disabled the preference - Bug T54542#555387
|
||||
if ( mw.user.options.get( 'usebetatoolbar' ) > 0 ) { // And the WikiEditor beta toolbar is used by the user
|
||||
wikiEditorToolbarEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// function for a textselection function for CodeMirror
|
||||
function cmTextSelection( command, options ) {
|
||||
var fn, retval;
|
||||
|
@ -345,7 +352,7 @@
|
|||
|
||||
} else {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
enableCodeMirror( !!wikiEditor );
|
||||
enableCodeMirror();
|
||||
setCodeEditorPreference( true );
|
||||
}
|
||||
updateToolbarButton( wikiEditor );
|
||||
|
@ -353,10 +360,8 @@
|
|||
|
||||
/**
|
||||
* Replaces the default textarea with CodeMirror
|
||||
*
|
||||
* @param {boolean} [useWikiEditor]
|
||||
*/
|
||||
function enableCodeMirror( useWikiEditor ) {
|
||||
function enableCodeMirror() {
|
||||
var $codeMirror,
|
||||
$textbox1 = $( '#wpTextbox1' );
|
||||
|
||||
|
@ -386,7 +391,7 @@
|
|||
'line-height': $textbox1.css( 'line-height' )
|
||||
} );
|
||||
|
||||
if ( !useWikiEditor ) {
|
||||
if ( !wikiEditorToolbarEnabled ) {
|
||||
$codeMirror.addClass( 'mw-codeMirror-classicToolbar' );
|
||||
}
|
||||
|
||||
|
@ -398,10 +403,7 @@
|
|||
|
||||
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
|
||||
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
|
||||
// This function shouldn't be called without user.options is loaded, but it's not guaranteed
|
||||
mw.loader.using( 'user.options', function () {
|
||||
// This can be the string "0" if the user disabled the preference - Bug T54542#555387
|
||||
if ( mw.loader.getState( 'ext.wikiEditor' ) && mw.user.options.get( 'usebetatoolbar' ) > 0 ) {
|
||||
if ( wikiEditorToolbarEnabled ) {
|
||||
// load wikiEditor's toolbar (if not already) and add our button
|
||||
$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', addCodeMirrorToWikiEditor );
|
||||
} else {
|
||||
|
@ -419,15 +421,14 @@
|
|||
$( function () { updateToolbarButton(); } );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
// enable CodeMirror
|
||||
if ( useCodeMirror ) {
|
||||
if ( mw.loader.getState( 'ext.wikiEditor' ) ) {
|
||||
$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', enableCodeMirror.bind( this, true ) );
|
||||
if ( wikiEditorToolbarEnabled ) {
|
||||
$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', enableCodeMirror.bind( this ) );
|
||||
} else {
|
||||
enableCodeMirror( false );
|
||||
enableCodeMirror();
|
||||
}
|
||||
}
|
||||
}( mediaWiki, jQuery ) );
|
||||
|
|
Loading…
Reference in a new issue