Wikipedia/assets/codemirror/resources/ext.CodeMirror.js
/**
	 * Replaces the default textarea with CodeMirror
	 */
Replaces the default textarea with CodeMirror
Replaces the default textarea with CodeMirror
function enableCodeMirror() {
		var config = mw.config.get( 'extCodeMirrorConfig' );
		mw.loader.using( config.pluginModules, function () {
			var $codeMirror,
				$textbox1 = $( '#wpTextbox1' ),
				selectionStart = $textbox1.prop( 'selectionStart' ),
				selectionEnd = $textbox1.prop( 'selectionEnd' ),
				scrollTop = $textbox1.scrollTop();
			if ( codeMirror || mw.user.options.get( 'gadget-wikEd' ) > 0 ) {
				return;
			}
			codeMirror = CodeMirror.fromTextArea( $textbox1[ 0 ], {
				mwConfig: config,
				lineWrapping: true,
				readOnly: $textbox1[ 0 ].readOnly,
				mode: 'text/mediawiki',
				extraKeys: {
					Tab: false,
					'Shift-Tab': false,
					Home: 'goLineLeft',
					End: 'goLineRight'
				},
				inputStyle: enableContentEditable ? 'contenteditable' : 'textarea',
				spellcheck: enableContentEditable,
				viewportMargin: Infinity
			} );
			$codeMirror = $( codeMirror.getWrapperElement() );
			$codeMirror.textSelection( 'register', cmTextSelection );
			$textbox1.textSelection( 'register', cmTextSelection );
			$codeMirror.resizable( {
				handles: 'se',
				resize: function ( event, ui ) {
					ui.size.width = ui.originalSize.width;
				}
			} );
			codeMirror.doc.setSelection( codeMirror.doc.posFromIndex( selectionEnd ), codeMirror.doc.posFromIndex( selectionStart ) );
			codeMirror.scrollTo( null, scrollTop );
			$codeMirror.css( {
				'font-size': $textbox1.css( 'font-size' ),
				'line-height': $textbox1.css( 'line-height' )
			} );
			$codeMirror.attr( {
				dir: $textbox1.attr( 'dir' ),
				lang: $textbox1.attr( 'lang' )
			} );
			$( codeMirror.getInputField() ).addClass( 'noime' );
			codeMirror.setSize( null, $textbox1.height() );
		} );
	}
function enableCodeMirror ( ) { var config = mw . config . get ( 'extCodeMirrorConfig' ) ; mw . loader . using ( config . pluginModules , function ( ) { var $codeMirror , $textbox1 = $ ( '#wpTextbox1' ) , selectionStart = $textbox1 . prop ( 'selectionStart' ) , selectionEnd = $textbox1 . prop ( 'selectionEnd' ) , scrollTop = $textbox1 . scrollTop ( ) ; if ( codeMirror || mw . user . options . get ( 'gadget-wikEd' ) > 0 ) { return ; } codeMirror = CodeMirror . fromTextArea ( $textbox1 [ 0 ] , { mwConfig : config , lineWrapping : true , readOnly : $textbox1 [ 0 ] . readOnly , mode : 'text/mediawiki' , extraKeys : { Tab : false , 'Shift-Tab' : false , Home : 'goLineLeft' , End : 'goLineRight' } , inputStyle : enableContentEditable ? 'contenteditable' : 'textarea' , spellcheck : enableContentEditable , viewportMargin : Infinity } ) ; $codeMirror = $ ( codeMirror . getWrapperElement ( ) ) ; $codeMirror . textSelection ( 'register' , cmTextSelection ) ; $textbox1 . textSelection ( 'register' , cmTextSelection ) ; $codeMirror . resizable ( { handles : 'se' , resize : function ( event , ui ) { ui . size . width = ui . originalSize . width ; } } ) ; codeMirror . doc . setSelection ( codeMirror . doc . posFromIndex ( selectionEnd ) , codeMirror . doc . posFromIndex ( selectionStart ) ) ; codeMirror . scrollTo ( null , scrollTop ) ; $codeMirror . css ( { 'font-size' : $textbox1 . css ( 'font-size' ) , 'line-height' : $textbox1 . css ( 'line-height' ) } ) ; $codeMirror . attr ( { dir : $textbox1 . attr ( 'dir' ) , lang : $textbox1 . attr ( 'lang' ) } ) ; $ ( codeMirror . getInputField ( ) ) . addClass ( 'noime' ) ; codeMirror . setSize ( null , $textbox1 . height ( ) ) ; } ) ; }
Replaces the default textarea with CodeMirror
Replaces the default textarea with CodeMirror
// If CodeMirror is already loaded or wikEd gadget is enabled, abort. See T178348. // FIXME: Would be good to replace the wikEd check with something more generic. // styleActiveLine: true, // disabled since Bug: T162204, maybe should be optional // select mediawiki as text input mode // T174514: Move the cursor at the beginning/end of the current wrapped line // Allow textSelection() functions to work with CodeMirror editing field. // Also override textSelection() functions for the "real" hidden textarea to route to // CodeMirror. We unregister this when switching to normal textarea mode. // HACK: <textarea> font size varies by browser (chrome/FF/IE) // use direction and language of the original textbox // T194102: UniversalLanguageSelector integration is buggy, disabling it completely // set the height of the textarea