From 4fc52b7ba3c114fc394b6d0ab8853d195a726064 Mon Sep 17 00:00:00 2001 From: Kaldari Date: Mon, 10 Jul 2017 14:16:36 -0700 Subject: [PATCH] Make sure enhanced editing toolbar is loaded before adding button Bug: T169943 Change-Id: Id8828b0d49ecec5124430d15445739d73795d164 --- resources/ext.CodeMirror.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/resources/ext.CodeMirror.js b/resources/ext.CodeMirror.js index 81c75060..eb7c7be9 100644 --- a/resources/ext.CodeMirror.js +++ b/resources/ext.CodeMirror.js @@ -434,15 +434,20 @@ } } - /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */ + // If view is in edit mode, add the button to the toolbar. if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) { + // Check if the user is using the enhanced editing toolbar (supplied by the + // WikiEditor extension) or the default editing toolbar (supplied by core). if ( wikiEditorToolbarEnabled ) { - // Add our button - $( addCodeMirrorToWikiEditor ); + // They are using the enhanced editing toolbar. + mw.loader.using( 'ext.wikiEditor.toolbar', function () { + // Add CodeMirror button to the enhanced editing toolbar. + $( addCodeMirrorToWikiEditor ); + } ); } else { - // Load wikiEditor's toolbar and add our button + // They are using the default editing toolbar. mw.loader.using( 'mediawiki.toolbar', function () { - // If WikiEditor isn't enabled, add CodeMirror button to the default wiki editor toolbar + // Add CodeMirror button to the default editing toolbar. mw.toolbar.addButton( { speedTip: mw.msg( 'codemirror-toggle-label' ), imageId: 'mw-editbutton-codemirror',