2014-01-06 09:07:24 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWMathInspector class.
|
|
|
|
*
|
2015-01-16 12:06:38 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2014-01-06 09:07:24 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*global ve, OO */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki math inspector.
|
|
|
|
*
|
|
|
|
* @class
|
2014-04-17 02:39:10 +00:00
|
|
|
* @extends ve.ui.MWLiveExtensionInspector
|
2014-01-06 09:07:24 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2014-04-15 01:52:09 +00:00
|
|
|
ve.ui.MWMathInspector = function VeUiMWMathInspector( config ) {
|
2014-01-06 09:07:24 +00:00
|
|
|
// Parent constructor
|
2014-04-17 02:39:10 +00:00
|
|
|
ve.ui.MWLiveExtensionInspector.call( this, config );
|
2014-01-06 09:07:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-04-17 02:39:10 +00:00
|
|
|
OO.inheritClass( ve.ui.MWMathInspector, ve.ui.MWLiveExtensionInspector );
|
2014-01-06 09:07:24 +00:00
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
|
|
|
ve.ui.MWMathInspector.static.name = 'math';
|
|
|
|
|
|
|
|
ve.ui.MWMathInspector.static.icon = 'math';
|
|
|
|
|
2014-07-09 20:19:58 +00:00
|
|
|
ve.ui.MWMathInspector.static.size = 'large';
|
|
|
|
|
2014-03-25 18:35:22 +00:00
|
|
|
ve.ui.MWMathInspector.static.title = OO.ui.deferMsg( 'math-visualeditor-mwmathinspector-title' );
|
2014-01-06 09:07:24 +00:00
|
|
|
|
2015-03-23 15:12:49 +00:00
|
|
|
ve.ui.MWMathInspector.static.modelClasses = [ ve.dm.MWMathNode ];
|
2014-01-06 09:07:24 +00:00
|
|
|
|
2014-04-17 02:39:10 +00:00
|
|
|
ve.ui.MWMathInspector.static.dir = 'ltr';
|
2014-01-06 09:07:24 +00:00
|
|
|
|
2014-11-12 15:28:57 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWMathInspector.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Position
|
|
|
|
this.displaySelect = new OO.ui.ButtonSelectWidget( {
|
|
|
|
items: [
|
|
|
|
new OO.ui.ButtonOptionWidget( {
|
|
|
|
data: 'default',
|
|
|
|
icon: 'math-display-default',
|
|
|
|
label: ve.msg( 'math-visualeditor-mwmathinspector-display-default' )
|
|
|
|
} ),
|
|
|
|
new OO.ui.ButtonOptionWidget( {
|
|
|
|
data: 'inline',
|
|
|
|
icon: 'math-display-inline',
|
|
|
|
label: ve.msg( 'math-visualeditor-mwmathinspector-display-inline' )
|
|
|
|
} ),
|
|
|
|
new OO.ui.ButtonOptionWidget( {
|
|
|
|
data: 'block',
|
|
|
|
icon: 'math-display-block',
|
|
|
|
label: ve.msg( 'math-visualeditor-mwmathinspector-display-block' )
|
|
|
|
} )
|
|
|
|
]
|
|
|
|
} );
|
|
|
|
|
2015-05-09 10:52:57 +00:00
|
|
|
this.idInput = new OO.ui.TextInputWidget();
|
2014-11-12 15:28:57 +00:00
|
|
|
|
|
|
|
var inputField = new OO.ui.FieldLayout( this.input, {
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'math-visualeditor-mwmathinspector-title' )
|
|
|
|
} ),
|
|
|
|
displayField = new OO.ui.FieldLayout( this.displaySelect, {
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'math-visualeditor-mwmathinspector-display' )
|
|
|
|
} ),
|
|
|
|
idField = new OO.ui.FieldLayout( this.idInput, {
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'math-visualeditor-mwmathinspector-id' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$content.addClass( 've-ui-mwMathInspector-content' );
|
|
|
|
this.form.$element.append( inputField.$element, displayField.$element, idField.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWMathInspector.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
2015-03-23 15:12:49 +00:00
|
|
|
var display = this.selectedNode.getAttribute( 'mw' ).attrs.display || 'default';
|
2014-11-12 15:28:57 +00:00
|
|
|
this.displaySelect.selectItem( this.displaySelect.getItemFromData( display ) );
|
|
|
|
this.displaySelect.on( 'choose', this.onChangeHandler );
|
|
|
|
this.idInput.on( 'change', this.onChangeHandler );
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWMathInspector.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.first( function () {
|
|
|
|
this.displaySelect.off( 'choose', this.onChangeHandler );
|
|
|
|
this.idInput.off( 'change', this.onChangeHandler );
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.updatePreview = function () {
|
2015-03-23 15:12:49 +00:00
|
|
|
var mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) ),
|
2014-11-12 15:28:57 +00:00
|
|
|
display = this.displaySelect.getSelectedItem().getData(),
|
|
|
|
id = this.idInput.getValue();
|
|
|
|
|
|
|
|
mwData.body.extsrc = this.input.getValue();
|
|
|
|
mwData.attrs.display = display !== 'default' ? display : undefined;
|
|
|
|
mwData.attrs.id = id || undefined;
|
|
|
|
|
|
|
|
if ( this.visible ) {
|
|
|
|
this.getFragment().changeAttributes( { mw: mwData } );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-06 09:07:24 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2014-04-15 23:22:03 +00:00
|
|
|
ve.ui.windowFactory.register( ve.ui.MWMathInspector );
|