mediawiki-extensions-Visual.../modules/ve/ui/dialogs/ve.ui.MWMediaInsertDialog.js
Trevor Parscal 1fd7e85846 Image insertion
Objective:

* Allow inserting images from local wiki and commons

Changes:

ve.init.mw.ViewPageTarget.js
* Add media insert button to toolbar

ve.init.mw.Platform.js
* Add getMediaSources method - defaults to local wiki and commons

ve.ui.MWMediaInsertDialog.js
* New dialog for inserting media
* Uses a media select widget and inserts block images

ve.ui.Dialog.css
* Added styling for media select widget in media insert dialog

ve.ui.Widget.css
* Added styles for media select widget and media select item widget

ve.ui.MWMediaInsertButtonTool.js
* New tool for inserting media

ve.ui.MediaSelectItemWidget.js
* New item widget for media select widgets

ve.ui.MediaSelectWidget.js
* New widget for searching for and selecting media items

ve.ui.TextInputWidget.js
* Added isPending method

VisualEditor.i18n.php
* New messages for media insert dialog

VisualEditor.php
* Added links to new files and messages

PhantomJS--

Change-Id: Ia803ff3ef518782ce76802d2dab7559686a1bb0a
2013-06-06 17:36:55 -07:00

104 lines
2.2 KiB
JavaScript

/*!
* 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 */
/**
* Document dialog.
*
* @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 */
/**
* Handle media select events.
*
* @method
* @param {string} item Selected item
*/
ve.ui.MWMediaInsertDialog.prototype.onSelect = function ( item ) {
this.item = item;
this.applyButton.setDisabled( item === null );
};
/**
* Handle apply button click events.
*
* @method
*/
ve.ui.MWMediaInsertDialog.prototype.onApplyButtonClick = function () {
var info = this.item.imageinfo[0];
this.surface.getModel().getFragment().insertContent( [
{
'type': 'mwBlockImage',
'attributes': {
'align': 'right',
'href': info.descriptionurl,
'src': info.thumburl,
'width': info.thumbwidth,
'height': info.thumbheight
}
},
{ 'type': '/mwBlockImage' }
] );
// Parent method
ve.ui.Dialog.prototype.onApplyButtonClick.call( this );
};
/**
* Initialize frame contents.
*
* @method
*/
ve.ui.MWMediaInsertDialog.prototype.initialize = function () {
// Parent method
ve.ui.Dialog.prototype.initialize.call( this );
// Properties
this.media = new ve.ui.MWMediaSelectWidget( { '$$': this.frame.$$ } );
// Events
this.media.connect( this, { 'select': 'onSelect' } );
// Initialization
this.applyButton.setDisabled( true ).setLabel(
mw.msg( 'visualeditor-dialog-media-insert-button' )
);
this.media.$.addClass( 've-ui-mwMediaInsertDialog-select' );
this.$body.append( this.media.$ );
};
/* Registration */
ve.ui.dialogFactory.register( 'mwMediaInsert', ve.ui.MWMediaInsertDialog );