mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SyntaxHighlight_GeSHi
synced 2024-11-24 14:34:20 +00:00
0f10206cf2
Maintain the inspector for inline snippets (which are editable but still not creatable). Bug: T112617 Bug: T57934 Change-Id: I76e36590363d36c0d3db4ec28ce81c4860d9b467
129 lines
3.5 KiB
JavaScript
129 lines
3.5 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface MWSyntaxHighlightWindow class.
|
|
*
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* MediaWiki syntax highlight window.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
*
|
|
* @constructor
|
|
*/
|
|
ve.ui.MWSyntaxHighlightWindow = function VeUiMWSyntaxHighlightWindow() {
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.initClass( ve.ui.MWSyntaxHighlightWindow );
|
|
|
|
/* Static properties */
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.static.icon = 'alienextension';
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.static.title = OO.ui.deferMsg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title' );
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.static.dir = 'ltr';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.initialize = function () {
|
|
var noneMsg = ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-none' );
|
|
|
|
this.language = new OO.ui.ComboBoxWidget( {
|
|
menu: {
|
|
filterFromInput: true,
|
|
items: $.map( ve.dm.MWSyntaxHighlightNode.static.getLanguages(), function ( lang ) {
|
|
return new OO.ui.MenuOptionWidget( { data: lang, label: lang || noneMsg } );
|
|
} )
|
|
},
|
|
input: { validate: function ( input ) {
|
|
return ve.dm.MWSyntaxHighlightNode.static.isLanguageSupported( input );
|
|
} }
|
|
} );
|
|
this.language.getInput().connect( this, { change: 'onLanguageInputChange' } );
|
|
|
|
this.showLinesCheckbox = new OO.ui.CheckboxInputWidget();
|
|
|
|
this.languageField = new OO.ui.FieldLayout( this.language, {
|
|
classes: [ 've-ui-mwSyntaxHighlightWindow-languageField' ],
|
|
align: 'top',
|
|
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language' )
|
|
} );
|
|
this.codeField = new OO.ui.FieldLayout( this.input, {
|
|
align: 'top',
|
|
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code' )
|
|
} );
|
|
this.showLinesField = new OO.ui.FieldLayout( this.showLinesCheckbox, {
|
|
align: 'inline',
|
|
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines' )
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* Handle input change events
|
|
*
|
|
* @param {string} value New value
|
|
*/
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.onLanguageInputChange = function () {
|
|
var inspector = this;
|
|
this.language.getInput().isValid().done( function ( valid ) {
|
|
inspector.getActions().setAbilities( { done: valid } );
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc OO.ui.Window
|
|
*/
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.getReadyProcess = function ( data, process ) {
|
|
return process.next( function () {
|
|
this.language.getMenu().toggle( false );
|
|
if ( !this.language.getInput().getValue() ) {
|
|
this.language.getInput().focus();
|
|
} else {
|
|
this.input.focus();
|
|
}
|
|
}, this );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc OO.ui.Window
|
|
*/
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.getSetupProcess = function ( data, process ) {
|
|
return process.next( function () {
|
|
var attrs = this.selectedNode ? this.selectedNode.getAttribute( 'mw' ).attrs : {},
|
|
language = attrs.lang || '',
|
|
showLines = attrs.line !== undefined;
|
|
|
|
this.language.input.setValue( language );
|
|
|
|
this.showLinesCheckbox.setSelected( showLines );
|
|
}, this );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc OO.ui.Window
|
|
*/
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.getTeardownProcess = function ( data, process ) {
|
|
return process;
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc ve.ui.MWExtensionWindow
|
|
*/
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.updateMwData = function ( mwData ) {
|
|
var language, showLines;
|
|
|
|
language = this.language.input.getValue();
|
|
showLines = this.showLinesCheckbox.isSelected();
|
|
|
|
mwData.attrs.lang = language || undefined;
|
|
mwData.attrs.line = showLines ? '1' : undefined;
|
|
};
|