2013-08-03 14:17:16 +00:00
|
|
|
/*!
|
|
|
|
* 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
|
2013-10-04 17:51:44 +00:00
|
|
|
* @extends ve.ui.SurfaceInspector
|
2013-08-03 14:17:16 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-10-09 19:59:03 +00:00
|
|
|
* @param {ve.ui.SurfaceWindowSet} windowSet Window set this inspector is part of
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-08-03 14:17:16 +00:00
|
|
|
*/
|
2013-10-09 19:59:03 +00:00
|
|
|
ve.ui.MWExtensionInspector = function VeUiMWExtensionInspector( windowSet, config ) {
|
2013-08-03 14:17:16 +00:00
|
|
|
// Parent constructor
|
2013-10-09 19:59:03 +00:00
|
|
|
ve.ui.SurfaceInspector.call( this, windowSet, config );
|
2013-08-03 14:17:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-04 17:51:44 +00:00
|
|
|
ve.inheritClass( ve.ui.MWExtensionInspector, ve.ui.SurfaceInspector );
|
2013-08-03 14:17:16 +00:00
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
|
|
|
ve.ui.MWExtensionInspector.static.nodeView = null;
|
|
|
|
|
|
|
|
ve.ui.MWExtensionInspector.static.nodeModel = null;
|
|
|
|
|
2013-08-14 14:39:56 +00:00
|
|
|
ve.ui.MWExtensionInspector.static.removeable = false;
|
|
|
|
|
2013-08-03 14:17:16 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle frame ready events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionInspector.prototype.initialize = function () {
|
|
|
|
// Parent method
|
2013-10-04 17:51:44 +00:00
|
|
|
ve.ui.SurfaceInspector.prototype.initialize.call( this );
|
2013-08-03 14:17:16 +00:00
|
|
|
|
|
|
|
this.input = new ve.ui.TextInputWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'overlay': this.surface.$localOverlay,
|
|
|
|
'multiline': true
|
|
|
|
} );
|
|
|
|
this.input.$.addClass( 've-ui-mwExtensionInspector-input' );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$form.append( this.input.$ );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the inspector being opened.
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionInspector.prototype.onOpen = function () {
|
|
|
|
var extsrc = '';
|
|
|
|
|
|
|
|
// Parent method
|
2013-10-04 17:51:44 +00:00
|
|
|
ve.ui.SurfaceInspector.prototype.onOpen.call( this );
|
2013-08-03 14:17:16 +00:00
|
|
|
|
|
|
|
this.node = this.surface.getView().getFocusedNode();
|
|
|
|
|
|
|
|
if ( this.node ) {
|
|
|
|
extsrc = this.node.getModel().getAttribute( 'mw' ).body.extsrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for animation to complete
|
|
|
|
setTimeout( ve.bind( function () {
|
|
|
|
// Setup input text
|
|
|
|
this.input.setValue( extsrc );
|
|
|
|
this.input.$input.focus().select();
|
|
|
|
}, this ), 200 );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the inspector being closed.
|
|
|
|
*
|
|
|
|
* @param {string} action Action that caused the window to be closed
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionInspector.prototype.onClose = function ( action ) {
|
2013-09-24 23:55:41 +00:00
|
|
|
var mwData,
|
2013-08-03 14:17:16 +00:00
|
|
|
surfaceModel = this.surface.getModel();
|
|
|
|
|
|
|
|
// Parent method
|
2013-10-04 17:51:44 +00:00
|
|
|
ve.ui.SurfaceInspector.prototype.onClose.call( this, action );
|
2013-08-03 14:17:16 +00:00
|
|
|
|
|
|
|
if ( this.node instanceof this.constructor.static.nodeView ) {
|
2013-09-24 23:55:41 +00:00
|
|
|
mwData = ve.copy( this.node.getModel().getAttribute( 'mw' ) );
|
|
|
|
mwData.body.extsrc = this.input.getValue();
|
2013-08-03 14:17:16 +00:00
|
|
|
surfaceModel.change(
|
|
|
|
ve.dm.Transaction.newFromAttributeChanges(
|
2013-09-24 23:55:41 +00:00
|
|
|
surfaceModel.getDocument(), this.node.getOuterRange().start, { 'mw': mwData }
|
2013-08-03 14:17:16 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
2013-09-24 23:55:41 +00:00
|
|
|
mwData = {
|
2013-08-03 14:17:16 +00:00
|
|
|
'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': {
|
2013-09-24 23:55:41 +00:00
|
|
|
'mw': mwData
|
2013-08-03 14:17:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{ 'type': '/' + this.constructor.static.nodeModel.static.name }
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
};
|