mediawiki-extensions-Visual.../modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js
Trevor Parscal b3281bd87a Spell removable and movable using modern English
Also...

* Update OOjs UI to v0.1.0-pre (5ffe63d088)
* Make template parameter text boxes shorter (3em down from 10em)
* Reorder extendObject calls to not modify incoming config objects
* Allow level option to default to 0, rather than specifically defining it
* Use icon button widgets with remove icons for parameter, placeholder,
  template and content removal buttons

Change-Id: I29db9d814fab5cf4debd0fc7bab6f51475cb0f94
2013-12-06 12:24:36 -08:00

125 lines
3 KiB
JavaScript

/*!
* VisualEditor UserInterface MWExtensionInspector class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki extension inspector.
*
* @class
* @abstract
* @extends ve.ui.Inspector
*
* @constructor
* @param {ve.ui.WindowSet} windowSet Window set this inspector is part of
* @param {Object} [config] Configuration options
*/
ve.ui.MWExtensionInspector = function VeUiMWExtensionInspector( windowSet, config ) {
// Parent constructor
ve.ui.Inspector.call( this, windowSet, config );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWExtensionInspector, ve.ui.Inspector );
/* Static properties */
ve.ui.MWExtensionInspector.static.nodeView = null;
ve.ui.MWExtensionInspector.static.nodeModel = null;
ve.ui.MWExtensionInspector.static.removable = false;
/* Methods */
/**
* Handle frame ready events.
*
* @method
*/
ve.ui.MWExtensionInspector.prototype.initialize = function () {
// Parent method
ve.ui.Inspector.prototype.initialize.call( this );
this.input = new OO.ui.TextInputWidget( {
'$': this.$,
'overlay': this.surface.$localOverlay,
'multiline': true
} );
this.input.$element.addClass( 've-ui-mwExtensionInspector-input' );
// Initialization
this.$form.append( this.input.$element );
};
/**
* @inheritdoc
*/
ve.ui.MWExtensionInspector.prototype.setup = function ( data ) {
// Parent method
ve.ui.Inspector.prototype.setup.call( this, data );
// Initialization
this.node = this.surface.getView().getFocusedNode();
this.input.setValue( this.node ? this.node.getModel().getAttribute( 'mw' ).body.extsrc : '' );
if ( this.node ) {
// Direction of the input textarea should correspond to the
// direction of the surrounding content of the node itself
// rather than the GUI direction:
this.input.setRTL( this.node.$element.css( 'direction' ) === 'rtl' );
}
};
/**
* @inheritdoc
*/
ve.ui.MWExtensionInspector.prototype.ready = function () {
// Parent method
ve.ui.Inspector.prototype.ready.call( this );
// Focus the input
this.input.$input.focus().select();
};
/**
* @inheritdoc
*/
ve.ui.MWExtensionInspector.prototype.teardown = function ( data ) {
var mwData,
surfaceModel = this.surface.getModel();
if ( this.node instanceof this.constructor.static.nodeView ) {
mwData = ve.copy( this.node.getModel().getAttribute( 'mw' ) );
mwData.body.extsrc = this.input.getValue();
surfaceModel.change(
ve.dm.Transaction.newFromAttributeChanges(
surfaceModel.getDocument(), this.node.getOuterRange().start, { 'mw': mwData }
)
);
} else {
mwData = {
'name': this.constructor.static.nodeModel.static.extensionName,
'attrs': {},
'body': {
'extsrc': this.input.getValue()
}
};
surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
{
'type': this.constructor.static.nodeModel.static.name,
'attributes': {
'mw': mwData
}
},
{ 'type': '/' + this.constructor.static.nodeModel.static.name }
] );
}
// Parent method
ve.ui.Inspector.prototype.teardown.call( this, data );
};