2013-06-06 23:14:11 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MediaInsertDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*global mw */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @extends ve.ui.Dialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Surface} surface
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaInsertDialog = function VeUiMWMediaInsertDialog( surface, config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.Dialog.call( this, surface, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.item = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.MWMediaInsertDialog, ve.ui.Dialog );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWMediaInsertDialog.static.titleMessage = 'visualeditor-dialog-media-insert-title';
|
|
|
|
|
|
|
|
ve.ui.MWMediaInsertDialog.static.icon = 'picture';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ve.ui.MWMediaInsertDialog.prototype.onSelect = function ( item ) {
|
|
|
|
this.item = item;
|
|
|
|
this.applyButton.setDisabled( item === null );
|
|
|
|
};
|
|
|
|
|
2013-06-25 22:11:41 +00:00
|
|
|
ve.ui.MWMediaInsertDialog.prototype.onOpen = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.Dialog.prototype.onOpen.call( this );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.search.getQuery().$input.focus().select();
|
|
|
|
};
|
|
|
|
|
2013-06-19 15:21:38 +00:00
|
|
|
ve.ui.MWMediaInsertDialog.prototype.onClose = function ( action ) {
|
|
|
|
var info;
|
2013-06-06 23:14:11 +00:00
|
|
|
|
|
|
|
// Parent method
|
2013-06-19 15:21:38 +00:00
|
|
|
ve.ui.Dialog.prototype.onClose.call( this );
|
|
|
|
|
|
|
|
if ( action === 'apply' ) {
|
|
|
|
info = this.item.imageinfo[0];
|
|
|
|
this.surface.getModel().getFragment().insertContent( [
|
|
|
|
{
|
|
|
|
'type': 'mwBlockImage',
|
|
|
|
'attributes': {
|
2013-06-21 19:36:14 +00:00
|
|
|
'type': 'thumb',
|
2013-06-19 15:21:38 +00:00
|
|
|
'align': 'right',
|
2013-06-25 22:09:09 +00:00
|
|
|
//'href': info.descriptionurl,
|
|
|
|
'href': './' + this.item.title,
|
2013-06-19 15:21:38 +00:00
|
|
|
'src': info.thumburl,
|
|
|
|
'width': info.thumbwidth,
|
2013-06-19 20:43:30 +00:00
|
|
|
'height': info.thumbheight,
|
|
|
|
'resource': './' + this.item.title
|
2013-06-19 15:21:38 +00:00
|
|
|
}
|
|
|
|
},
|
2013-06-21 19:36:14 +00:00
|
|
|
{ 'type': 'mwImageCaption' },
|
|
|
|
{ 'type': '/mwImageCaption' },
|
2013-06-19 15:21:38 +00:00
|
|
|
{ 'type': '/mwBlockImage' }
|
|
|
|
] );
|
|
|
|
}
|
2013-06-06 23:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWMediaInsertDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.Dialog.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
2013-06-25 22:11:41 +00:00
|
|
|
this.search = new ve.ui.MWMediaSearchWidget( { '$$': this.frame.$$ } );
|
2013-06-06 23:14:11 +00:00
|
|
|
|
|
|
|
// Events
|
2013-06-25 22:11:41 +00:00
|
|
|
this.search.connect( this, { 'select': 'onSelect' } );
|
2013-06-06 23:14:11 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.applyButton.setDisabled( true ).setLabel(
|
|
|
|
mw.msg( 'visualeditor-dialog-media-insert-button' )
|
|
|
|
);
|
2013-06-25 22:11:41 +00:00
|
|
|
this.search.$.addClass( 've-ui-mwMediaInsertDialog-select' );
|
|
|
|
this.$body.append( this.search.$ );
|
2013-06-06 23:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.dialogFactory.register( 'mwMediaInsert', ve.ui.MWMediaInsertDialog );
|