2013-06-18 22:58:10 +00:00
|
|
|
/*!
|
2014-06-19 15:44:05 +00:00
|
|
|
* VisualEditor user interface MWMediaDialog class.
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
2019-01-01 13:24:23 +00:00
|
|
|
* @copyright 2011-2019 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-18 22:58:10 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-07-14 21:32:49 +00:00
|
|
|
* Dialog for inserting and editing MediaWiki media.
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
|
|
|
* @class
|
2014-04-24 00:22:45 +00:00
|
|
|
* @extends ve.ui.NodeDialog
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-18 22:58:10 +00:00
|
|
|
*/
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWMediaDialog = function VeUiMWMediaDialog( config ) {
|
2013-06-18 22:58:10 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWMediaDialog.super.call( this, config );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-03-25 16:01:04 +00:00
|
|
|
this.imageModel = null;
|
2014-07-02 19:23:25 +00:00
|
|
|
this.pageTitle = '';
|
2014-08-07 17:02:52 +00:00
|
|
|
this.isSettingUpModel = false;
|
|
|
|
this.isInsertion = false;
|
2014-09-18 19:49:22 +00:00
|
|
|
this.selectedImageInfo = null;
|
2015-01-15 18:50:30 +00:00
|
|
|
this.searchCache = {};
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
this.$element.addClass( 've-ui-mwMediaDialog' );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
OO.inheritClass( ve.ui.MWMediaDialog, ve.ui.NodeDialog );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.name = 'media';
|
2013-08-27 23:28:29 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.title =
|
2014-02-12 21:45:37 +00:00
|
|
|
OO.ui.deferMsg( 'visualeditor-dialog-media-title' );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2018-09-17 16:50:28 +00:00
|
|
|
ve.ui.MWMediaDialog.static.size = 'medium';
|
2014-07-14 21:32:49 +00:00
|
|
|
|
|
|
|
ve.ui.MWMediaDialog.static.actions = [
|
|
|
|
{
|
2019-02-19 17:08:38 +00:00
|
|
|
action: 'done',
|
2014-08-22 20:50:48 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-apply' ),
|
2014-12-11 22:49:51 +00:00
|
|
|
flags: [ 'progressive', 'primary' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
modes: 'edit'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'insert',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-insert' ),
|
2017-09-26 18:59:38 +00:00
|
|
|
flags: [ 'primary', 'progressive' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
modes: 'insert'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'change',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-media-change-image' ),
|
|
|
|
modes: [ 'edit', 'insert' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
2014-09-18 19:49:22 +00:00
|
|
|
{
|
|
|
|
action: 'choose',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-media-choose-image' ),
|
|
|
|
flags: [ 'primary', 'progressive' ],
|
|
|
|
modes: [ 'info' ]
|
|
|
|
},
|
2015-09-22 15:55:01 +00:00
|
|
|
{
|
|
|
|
action: 'upload',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-media-upload' ),
|
|
|
|
flags: [ 'primary', 'progressive' ],
|
|
|
|
modes: [ 'upload-upload' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'save',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-media-save' ),
|
|
|
|
flags: [ 'primary', 'progressive' ],
|
|
|
|
modes: [ 'upload-info' ]
|
|
|
|
},
|
2014-09-18 19:49:22 +00:00
|
|
|
{
|
|
|
|
action: 'cancelchoose',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-media-goback' ),
|
2015-08-06 13:34:32 +00:00
|
|
|
flags: [ 'safe', 'back' ],
|
2014-09-18 19:49:22 +00:00
|
|
|
modes: [ 'info' ]
|
|
|
|
},
|
2016-09-22 14:12:55 +00:00
|
|
|
{
|
|
|
|
action: 'cancelupload',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-media-goback' ),
|
|
|
|
flags: [ 'safe', 'back' ],
|
|
|
|
modes: [ 'upload-info' ]
|
|
|
|
},
|
2014-07-14 21:32:49 +00:00
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
|
2015-08-06 13:34:32 +00:00
|
|
|
flags: [ 'safe', 'back' ],
|
2019-02-08 19:18:22 +00:00
|
|
|
modes: [ 'readonly', 'edit', 'insert', 'select', 'search', 'upload-upload' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'back',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-media-goback' ),
|
2015-08-06 13:34:32 +00:00
|
|
|
flags: [ 'safe', 'back' ],
|
2014-09-18 19:49:22 +00:00
|
|
|
modes: [ 'change' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
];
|
2014-04-24 00:22:45 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.modelClasses = [ ve.dm.MWBlockImageNode, ve.dm.MWInlineImageNode ];
|
2014-04-24 00:22:45 +00:00
|
|
|
|
2015-07-18 21:44:47 +00:00
|
|
|
ve.ui.MWMediaDialog.static.includeCommands = null;
|
|
|
|
|
2014-11-24 17:43:16 +00:00
|
|
|
ve.ui.MWMediaDialog.static.excludeCommands = [
|
2013-12-12 19:04:15 +00:00
|
|
|
// No formatting
|
2014-11-24 17:43:16 +00:00
|
|
|
'paragraph',
|
|
|
|
'heading1',
|
|
|
|
'heading2',
|
|
|
|
'heading3',
|
|
|
|
'heading4',
|
|
|
|
'heading5',
|
|
|
|
'heading6',
|
|
|
|
'preformatted',
|
2014-11-26 02:57:26 +00:00
|
|
|
'blockquote',
|
2014-11-24 17:43:16 +00:00
|
|
|
// TODO: Decide if tables tools should be allowed
|
|
|
|
'tableCellHeader',
|
|
|
|
'tableCellData',
|
2014-03-25 00:13:59 +00:00
|
|
|
// No structure
|
2014-11-24 17:43:16 +00:00
|
|
|
'bullet',
|
2016-01-26 23:44:49 +00:00
|
|
|
'bulletWrapOnce',
|
2014-11-24 17:43:16 +00:00
|
|
|
'number',
|
2016-01-26 23:44:49 +00:00
|
|
|
'numberWrapOnce',
|
2014-11-24 17:43:16 +00:00
|
|
|
'indent',
|
|
|
|
'outdent'
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
|
2014-05-23 09:57:58 +00:00
|
|
|
/**
|
2014-11-24 11:27:25 +00:00
|
|
|
* Get the import rules for the surface widget in the dialog
|
2014-05-23 09:57:58 +00:00
|
|
|
*
|
|
|
|
* @see ve.dm.ElementLinearData#sanitize
|
2014-11-24 11:27:25 +00:00
|
|
|
* @return {Object} Import rules
|
2014-05-23 09:57:58 +00:00
|
|
|
*/
|
2014-11-24 11:27:25 +00:00
|
|
|
ve.ui.MWMediaDialog.static.getImportRules = function () {
|
2019-04-09 17:46:19 +00:00
|
|
|
var rules = ve.copy( ve.init.target.constructor.static.importRules );
|
2014-05-23 09:57:58 +00:00
|
|
|
return ve.extendObject(
|
2019-04-09 17:46:19 +00:00
|
|
|
rules,
|
2014-05-23 09:57:58 +00:00
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
all: {
|
2019-04-09 17:46:19 +00:00
|
|
|
blacklist: ve.extendObject(
|
|
|
|
{
|
2014-05-23 09:57:58 +00:00
|
|
|
// Tables (but not lists) are possible in wikitext with a leading
|
|
|
|
// line break but we prevent creating these with the UI
|
2019-04-09 17:46:19 +00:00
|
|
|
list: true,
|
|
|
|
listItem: true,
|
|
|
|
definitionList: true,
|
|
|
|
definitionListItem: true,
|
|
|
|
table: true,
|
|
|
|
tableCaption: true,
|
|
|
|
tableSection: true,
|
|
|
|
tableRow: true,
|
|
|
|
tableCell: true,
|
|
|
|
mwTable: true,
|
|
|
|
mwTransclusionTableCell: true
|
|
|
|
},
|
|
|
|
ve.getProp( rules, 'all', 'blacklist' )
|
2014-05-23 09:57:58 +00:00
|
|
|
),
|
|
|
|
// Headings are also possible, but discouraged
|
2019-04-09 17:46:19 +00:00
|
|
|
conversions: ve.extendObject(
|
|
|
|
{
|
|
|
|
mwHeading: 'paragraph'
|
|
|
|
},
|
|
|
|
ve.getProp( rules, 'all', 'conversions' )
|
|
|
|
)
|
2014-02-03 15:08:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 09:57:58 +00:00
|
|
|
);
|
|
|
|
};
|
2014-02-03 15:08:52 +00:00
|
|
|
|
2013-06-18 22:58:10 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.getBodyHeight = function () {
|
2015-01-17 00:01:59 +00:00
|
|
|
// FIXME: This should vary on panel.
|
2015-12-14 19:53:10 +00:00
|
|
|
return 600;
|
2014-07-14 21:32:49 +00:00
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.initialize = function () {
|
2018-10-03 20:37:55 +00:00
|
|
|
var captionField, altTextField, altTextFieldset,
|
|
|
|
positionSelectField, positionCheckboxField,
|
|
|
|
positionFieldset, typeSelectField, borderField,
|
|
|
|
sizeWidgetField, searchPanel, uploadPanel;
|
2014-04-24 00:22:45 +00:00
|
|
|
|
2013-06-21 02:47:10 +00:00
|
|
|
// Parent method
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.super.prototype.initialize.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2018-10-03 19:50:36 +00:00
|
|
|
// Main layout
|
2015-04-09 23:47:15 +00:00
|
|
|
this.panels = new OO.ui.StackLayout();
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2018-10-03 19:50:36 +00:00
|
|
|
// Settings panels
|
2018-09-17 16:50:28 +00:00
|
|
|
this.mediaSettingsLayout = new OO.ui.IndexLayout( {
|
|
|
|
classes: [ 've-ui-mwMediaDialog-panel-settings' ]
|
2013-12-21 22:37:54 +00:00
|
|
|
} );
|
2018-10-03 19:50:36 +00:00
|
|
|
this.generalSettingsPanel = new OO.ui.TabPanelLayout( 'general', {
|
2018-09-17 16:50:28 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-page-general' )
|
|
|
|
} );
|
2018-10-03 19:50:36 +00:00
|
|
|
this.advancedSettingsPanel = new OO.ui.TabPanelLayout( 'advanced', {
|
2018-09-17 16:50:28 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-page-advanced' )
|
|
|
|
} );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2018-10-03 19:50:36 +00:00
|
|
|
// General settings panel
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2015-01-08 23:40:12 +00:00
|
|
|
// Filename
|
|
|
|
this.filenameFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-content-filename' ),
|
2015-11-11 20:18:18 +00:00
|
|
|
icon: 'image'
|
2015-01-08 23:40:12 +00:00
|
|
|
} );
|
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// Caption
|
2016-11-20 22:53:34 +00:00
|
|
|
this.captionTarget = ve.init.target.createTargetWidget( {
|
|
|
|
tools: ve.init.target.constructor.static.toolbarGroups,
|
|
|
|
includeCommands: this.constructor.static.includeCommands,
|
|
|
|
excludeCommands: this.constructor.static.excludeCommands,
|
2017-03-28 16:43:59 +00:00
|
|
|
importRules: this.constructor.static.getImportRules(),
|
2018-03-12 12:49:13 +00:00
|
|
|
inDialog: this.constructor.static.name,
|
|
|
|
multiline: false
|
2016-11-20 22:53:34 +00:00
|
|
|
} );
|
2018-10-03 20:37:55 +00:00
|
|
|
captionField = new OO.ui.FieldLayout( this.captionTarget, {
|
|
|
|
align: 'top'
|
|
|
|
} );
|
2014-01-26 14:26:57 +00:00
|
|
|
this.captionFieldset = new OO.ui.FieldsetLayout( {
|
2017-02-16 01:56:03 +00:00
|
|
|
$overlay: this.$overlay,
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-content-section' ),
|
2015-01-20 23:53:31 +00:00
|
|
|
help: ve.msg( 'visualeditor-dialog-media-content-section-help' ),
|
2015-12-09 16:47:13 +00:00
|
|
|
classes: [ 've-ui-mwMediaDialog-caption-fieldset' ]
|
2013-06-18 22:58:10 +00:00
|
|
|
} );
|
2018-10-03 20:37:55 +00:00
|
|
|
this.captionFieldset.addItems( captionField );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2013-12-28 10:29:35 +00:00
|
|
|
// Alt text
|
2018-10-03 19:50:36 +00:00
|
|
|
this.altTextInput = new OO.ui.TextInputWidget( {
|
|
|
|
spellcheck: true,
|
|
|
|
classes: [ 've-ui-mwMediaDialog-altText' ]
|
|
|
|
} );
|
2018-10-03 20:37:55 +00:00
|
|
|
altTextField = new OO.ui.FieldLayout( this.altTextInput, {
|
|
|
|
align: 'top'
|
|
|
|
} );
|
2013-12-28 10:29:35 +00:00
|
|
|
altTextFieldset = new OO.ui.FieldsetLayout( {
|
2017-02-16 01:56:03 +00:00
|
|
|
$overlay: this.$overlay,
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-alttext-section' ),
|
2018-09-17 16:50:28 +00:00
|
|
|
help: ve.msg( 'visualeditor-dialog-media-alttext-section-help' )
|
2013-12-28 10:29:35 +00:00
|
|
|
} );
|
2018-10-03 20:37:55 +00:00
|
|
|
altTextFieldset.addItems( altTextField );
|
2013-12-28 10:29:35 +00:00
|
|
|
|
2018-10-03 19:50:36 +00:00
|
|
|
// Advanced settings
|
|
|
|
|
2013-12-29 03:49:06 +00:00
|
|
|
// Position
|
2015-02-10 10:49:53 +00:00
|
|
|
this.positionSelect = new ve.ui.AlignWidget( {
|
|
|
|
dir: this.getDir()
|
2014-08-06 12:29:41 +00:00
|
|
|
} );
|
2018-09-17 16:50:28 +00:00
|
|
|
positionSelectField = new OO.ui.FieldLayout( this.positionSelect );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.positionCheckbox = new OO.ui.CheckboxInputWidget();
|
2018-10-03 20:37:55 +00:00
|
|
|
positionCheckboxField = new OO.ui.FieldLayout( this.positionCheckbox, {
|
2017-02-16 01:56:03 +00:00
|
|
|
$overlay: this.$overlay,
|
2014-08-22 20:50:48 +00:00
|
|
|
align: 'inline',
|
2015-01-20 23:53:31 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-position-checkbox' ),
|
|
|
|
help: ve.msg( 'visualeditor-dialog-media-position-checkbox-help' )
|
2014-01-21 18:05:50 +00:00
|
|
|
} );
|
|
|
|
positionFieldset = new OO.ui.FieldsetLayout( {
|
2017-02-16 01:56:03 +00:00
|
|
|
$overlay: this.$overlay,
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-position-section' ),
|
2018-09-17 16:50:28 +00:00
|
|
|
help: ve.msg( 'visualeditor-dialog-media-position-section-help' )
|
2014-01-21 18:05:50 +00:00
|
|
|
} );
|
2018-10-03 20:37:55 +00:00
|
|
|
positionFieldset.addItems( [
|
|
|
|
positionCheckboxField,
|
|
|
|
positionSelectField
|
|
|
|
] );
|
2013-12-29 03:49:06 +00:00
|
|
|
|
2013-12-29 05:49:56 +00:00
|
|
|
// Type
|
2018-03-27 12:37:43 +00:00
|
|
|
this.typeSelectDropdown = new OO.ui.DropdownWidget( { $overlay: this.$overlay } );
|
|
|
|
this.typeSelect = this.typeSelectDropdown.getMenu();
|
2014-11-12 19:09:52 +00:00
|
|
|
this.typeSelect.addItems( [
|
2013-12-29 05:49:56 +00:00
|
|
|
// TODO: Inline images require a bit of further work, will be coming soon
|
2018-03-27 12:37:43 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'thumb',
|
2019-04-29 16:42:19 +00:00
|
|
|
icon: 'imageLayoutThumbnail',
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-thumb' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} ),
|
2018-03-27 12:37:43 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'frameless',
|
2019-04-29 16:42:19 +00:00
|
|
|
icon: 'imageLayoutFrameless',
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-frameless' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} ),
|
2018-03-27 12:37:43 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'frame',
|
2019-04-29 16:42:19 +00:00
|
|
|
icon: 'imageLayoutFrame',
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-frame' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} ),
|
2018-03-27 12:37:43 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'none',
|
2019-04-29 16:42:19 +00:00
|
|
|
icon: 'imageLayoutBasic',
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-none' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} )
|
|
|
|
] );
|
2018-10-03 20:37:55 +00:00
|
|
|
typeSelectField = new OO.ui.FieldLayout( this.typeSelectDropdown, {
|
|
|
|
align: 'top'
|
|
|
|
} );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.borderCheckbox = new OO.ui.CheckboxInputWidget();
|
2014-02-27 17:39:19 +00:00
|
|
|
borderField = new OO.ui.FieldLayout( this.borderCheckbox, {
|
2014-08-22 20:50:48 +00:00
|
|
|
align: 'inline',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-border' )
|
2014-02-27 17:39:19 +00:00
|
|
|
} );
|
2018-10-03 20:37:55 +00:00
|
|
|
this.typeFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
$overlay: this.$overlay,
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-section' ),
|
|
|
|
help: ve.msg( 'visualeditor-dialog-media-type-section-help' )
|
|
|
|
} );
|
|
|
|
this.typeFieldset.addItems( [
|
|
|
|
typeSelectField,
|
|
|
|
borderField
|
|
|
|
] );
|
2013-12-29 05:49:56 +00:00
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// Size
|
2018-10-03 20:37:55 +00:00
|
|
|
this.sizeWidget = new ve.ui.MediaSizeWidget( undefined, {
|
|
|
|
dimensionsAlign: 'top'
|
|
|
|
} );
|
|
|
|
sizeWidgetField = new OO.ui.FieldLayout( this.sizeWidget );
|
2014-01-26 14:26:57 +00:00
|
|
|
this.sizeFieldset = new OO.ui.FieldsetLayout( {
|
2017-02-16 01:56:03 +00:00
|
|
|
$overlay: this.$overlay,
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-media-size-section' ),
|
2015-01-20 23:53:31 +00:00
|
|
|
help: ve.msg( 'visualeditor-dialog-media-size-section-help' )
|
2013-12-21 22:37:54 +00:00
|
|
|
} );
|
2018-10-03 20:37:55 +00:00
|
|
|
this.sizeFieldset.addItems( [
|
|
|
|
sizeWidgetField
|
|
|
|
] );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2018-10-03 19:50:36 +00:00
|
|
|
// Search, upload and info layouts
|
|
|
|
this.mediaSearchPanel = new OO.ui.TabPanelLayout( {
|
|
|
|
classes: [ 've-ui-mwMediaDialog-panel-search' ],
|
|
|
|
scrollable: true
|
|
|
|
} );
|
|
|
|
if ( mw.ForeignStructuredUpload && mw.ForeignStructuredUpload.BookletLayout ) {
|
|
|
|
this.mediaUploadBooklet = new mw.ForeignStructuredUpload.BookletLayout( {
|
|
|
|
$overlay: this.$overlay
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
this.mediaImageInfoPanel = new OO.ui.TabPanelLayout( {
|
|
|
|
classes: [ 've-ui-mwMediaDialog-panel-imageinfo' ],
|
|
|
|
scrollable: false
|
|
|
|
} );
|
|
|
|
this.$infoPanelWrapper = $( '<div>' ).addClass( 've-ui-mwMediaDialog-panel-imageinfo-wrapper' );
|
|
|
|
|
|
|
|
// Search and upload panels
|
|
|
|
this.searchTabs = new OO.ui.IndexLayout();
|
|
|
|
searchPanel = new OO.ui.TabPanelLayout( 'search', {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-search-tab-search' )
|
|
|
|
} );
|
|
|
|
if ( this.mediaUploadBooklet ) {
|
|
|
|
uploadPanel = new OO.ui.TabPanelLayout( 'upload', {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-search-tab-upload' ),
|
|
|
|
content: [ this.mediaUploadBooklet ]
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search widget
|
|
|
|
this.search = new mw.widgets.MediaSearchWidget( {
|
|
|
|
rowHeight: OO.ui.isMobile() ? 120 : 200
|
|
|
|
} );
|
|
|
|
|
Single-click insertion
Objectives:
* Reduce the number of clicks and mouse maneuvers required to insert
media, references or template parameters
* Make use of highlighting with mouse movement or arrow key presses,
similar to menus, to suggest action when clicked
* Improve the way media search results look and feel
Changes:
ve.ui.SelectWidget.js
* Add mouseleave handler to un-highlight when the mouse exits the widget
* Document highlight events (already being emitted)
ve.ui.SearchWidget.js
* Propagate both select and highlight events from results widget
* Make arrow keys change highlight instead of selection
* Get rid of enter event, make enter key select highlighted item instead
* Provide direct access to results widget through getResults method
ve.ui.MenuWidget.js
* Use the selected item as a starting point if nothing is currently
highlighted when adjusting the highlight position
ve.ui.Dialog.js
* Add footless option to hide the foot element and make the body extend
all the way down to the bottom
* Remove applyButton, which only some dialogs need, and should be creating
themselves, along with other buttons as needed
ve.ui.Widget.css
* Change highlight and selected colors of option widgets to match other
selection colors used elsewhere
* Leave selected and highlighted widget looking selected
ve.ui.Frame.css
* Add background color to combat any color that might have been applied to
the frame body in the imported CSS from the parent frame
ve.ui.Dialog.css
* Add rules for footless mode
ve.ui.MWReferenceResultWidget.js,
ve.ui.MWParameterResultWidget.js,
ve.ui.MWMediaResultWidget.js
* Allow highlighting
ve.ui.MWParamterSearchWidget.js
* Switch from selecting the first item when filtering to highlighting
ve-mw/ve.ui.Widget.js
* Adjust media result widget styling to better match other elements
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceListDialog.js,
ve.ui.MWReferenceEditDialog.js,
ve.ui.MWMetaDialog.js
ve.ui.MWMediaEditDialog.js
* Add apply button, as per it being removed from parent class
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceInsertDialog.js,
ve.ui.MWMediaInsertDialog.js
* Insert parameter/reference/media on select, instead of clicking an
insert button
* Use 'insert' instead of 'apply' as argument for close method
Bug: 50774
Bug: 51143
Change-Id: Ia18e79f1f8df2540f465468edb01f5ce989bf843
2013-07-15 21:07:53 +00:00
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.positionCheckbox.connect( this, { change: 'onPositionCheckboxChange' } );
|
|
|
|
this.borderCheckbox.connect( this, { change: 'onBorderCheckboxChange' } );
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect.connect( this, { choose: 'onPositionSelectChoose' } );
|
|
|
|
this.typeSelect.connect( this, { choose: 'onTypeSelectChoose' } );
|
2015-03-27 10:51:06 +00:00
|
|
|
this.search.getResults().connect( this, { choose: 'onSearchResultsChoose' } );
|
2016-11-20 22:53:34 +00:00
|
|
|
this.captionTarget.connect( this, { change: 'checkChanged' } );
|
2014-08-07 17:02:52 +00:00
|
|
|
this.altTextInput.connect( this, { change: 'onAlternateTextChange' } );
|
2018-10-03 19:50:36 +00:00
|
|
|
this.searchTabs.connect( this, { set: 'onSearchTabsSet' } );
|
2018-09-17 16:50:28 +00:00
|
|
|
if ( this.mediaUploadBooklet ) {
|
|
|
|
this.mediaUploadBooklet.connect( this, {
|
|
|
|
set: 'onMediaUploadBookletSet',
|
|
|
|
uploadValid: 'onUploadValid',
|
|
|
|
infoValid: 'onInfoValid'
|
|
|
|
} );
|
|
|
|
}
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2018-10-03 19:50:36 +00:00
|
|
|
// Append panels
|
|
|
|
searchPanel.$element.append( this.search.$element );
|
|
|
|
this.searchTabs.addTabPanels( [ searchPanel ] );
|
|
|
|
if ( this.mediaUploadBooklet ) {
|
|
|
|
this.searchTabs.addTabPanels( [ uploadPanel ] );
|
|
|
|
}
|
|
|
|
this.mediaSearchPanel.$element.append(
|
|
|
|
this.searchTabs.$element
|
|
|
|
);
|
|
|
|
this.generalSettingsPanel.$element.append(
|
2015-01-08 23:40:12 +00:00
|
|
|
this.filenameFieldset.$element,
|
2013-12-28 10:29:35 +00:00
|
|
|
this.captionFieldset.$element,
|
|
|
|
altTextFieldset.$element
|
2014-08-12 13:57:07 +00:00
|
|
|
);
|
2018-10-03 19:50:36 +00:00
|
|
|
this.advancedSettingsPanel.$element.append(
|
2013-12-29 03:49:06 +00:00
|
|
|
positionFieldset.$element,
|
2013-12-29 05:49:56 +00:00
|
|
|
this.typeFieldset.$element,
|
2013-12-29 03:49:06 +00:00
|
|
|
this.sizeFieldset.$element
|
2014-08-12 13:57:07 +00:00
|
|
|
);
|
2018-10-03 19:50:36 +00:00
|
|
|
this.mediaSettingsLayout.addTabPanels( [
|
|
|
|
this.generalSettingsPanel,
|
|
|
|
this.advancedSettingsPanel
|
|
|
|
] );
|
2014-09-18 19:49:22 +00:00
|
|
|
this.panels.addItems( [
|
|
|
|
this.mediaSearchPanel,
|
|
|
|
this.mediaImageInfoPanel,
|
2018-09-17 16:50:28 +00:00
|
|
|
this.mediaSettingsLayout
|
2014-09-18 19:49:22 +00:00
|
|
|
] );
|
|
|
|
this.$body.append( this.panels.$element );
|
2014-06-19 15:44:05 +00:00
|
|
|
};
|
|
|
|
|
2015-09-22 15:55:01 +00:00
|
|
|
/**
|
|
|
|
* Handle set events from the search tabs
|
|
|
|
*
|
2017-05-10 18:46:49 +00:00
|
|
|
* @param {OO.ui.TabPanelLayout} tabPanel Current tabPanel
|
2015-09-22 15:55:01 +00:00
|
|
|
*/
|
2017-05-10 18:46:49 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onSearchTabsSet = function ( tabPanel ) {
|
|
|
|
var name = tabPanel.getName();
|
2015-09-22 15:55:01 +00:00
|
|
|
|
|
|
|
this.actions.setMode( name );
|
|
|
|
|
|
|
|
switch ( name ) {
|
|
|
|
case 'search':
|
|
|
|
this.setSize( 'larger' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'upload':
|
|
|
|
this.setSize( 'medium' );
|
|
|
|
this.uploadPageNameSet( 'upload' );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle panelNameSet events from the upload stack
|
|
|
|
*
|
|
|
|
* @param {OO.ui.PageLayout} page Current page
|
|
|
|
*/
|
2015-10-22 18:18:43 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onMediaUploadBookletSet = function ( page ) {
|
2015-09-22 15:55:01 +00:00
|
|
|
this.uploadPageNameSet( page.getName() );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The upload booklet's page name has changed
|
|
|
|
*
|
|
|
|
* @param {string} pageName Page name
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.uploadPageNameSet = function ( pageName ) {
|
2015-10-22 18:22:43 +00:00
|
|
|
var imageInfo;
|
2015-09-22 15:55:01 +00:00
|
|
|
if ( pageName === 'insert' ) {
|
2015-10-22 18:22:43 +00:00
|
|
|
imageInfo = this.mediaUploadBooklet.upload.getImageInfo();
|
|
|
|
this.chooseImageInfo( imageInfo );
|
2015-09-22 15:55:01 +00:00
|
|
|
} else {
|
2015-10-10 15:40:39 +00:00
|
|
|
// Hide the tabs after the first page
|
|
|
|
this.searchTabs.toggleMenu( pageName === 'upload' );
|
2015-10-22 18:00:36 +00:00
|
|
|
|
2015-09-22 15:55:01 +00:00
|
|
|
this.actions.setMode( 'upload-' + pageName );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle uploadValid events
|
|
|
|
*
|
|
|
|
* @param {boolean} isValid The panel is complete and valid
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.onUploadValid = function ( isValid ) {
|
|
|
|
this.actions.setAbilities( { upload: isValid } );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle infoValid events
|
|
|
|
*
|
|
|
|
* @param {boolean} isValid The panel is complete and valid
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.onInfoValid = function ( isValid ) {
|
|
|
|
this.actions.setAbilities( { save: isValid } );
|
|
|
|
};
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
/**
|
2014-09-18 19:49:22 +00:00
|
|
|
* Build the image info panel from the information in the API.
|
|
|
|
* Use the metadata info if it exists.
|
|
|
|
* Note: Some information in the metadata object needs to be safely
|
|
|
|
* stripped from its html wrappers.
|
2014-06-19 15:44:05 +00:00
|
|
|
*
|
2015-02-04 00:32:46 +00:00
|
|
|
* @param {Object} imageinfo Image info
|
2014-06-19 15:44:05 +00:00
|
|
|
*/
|
2015-02-04 00:32:46 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.buildMediaInfoPanel = function ( imageinfo ) {
|
2015-01-15 18:50:30 +00:00
|
|
|
var i, newDimensions, field, isPortrait, $info, $section, windowWidth,
|
2014-09-18 19:49:22 +00:00
|
|
|
contentDirection = this.getFragment().getDocument().getDir(),
|
2015-09-22 15:55:01 +00:00
|
|
|
imageTitleText = imageinfo.title || imageinfo.canonicaltitle,
|
2014-09-18 19:49:22 +00:00
|
|
|
imageTitle = new OO.ui.LabelWidget( {
|
2015-09-22 15:55:01 +00:00
|
|
|
label: mw.Title.newFromText( imageTitleText ).getNameText()
|
2014-09-18 19:49:22 +00:00
|
|
|
} ),
|
|
|
|
metadata = imageinfo.extmetadata,
|
|
|
|
// Field configuration (in order)
|
|
|
|
apiDataKeysConfig = [
|
|
|
|
{
|
|
|
|
name: 'ImageDescription',
|
|
|
|
value: ve.getProp( metadata, 'ImageDescription', 'value' ),
|
|
|
|
data: {
|
|
|
|
keepOriginal: true
|
|
|
|
},
|
|
|
|
view: {
|
|
|
|
type: 'description',
|
|
|
|
primary: true,
|
|
|
|
descriptionHeight: '5em'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'fileDetails',
|
|
|
|
data: { skipProcessing: true },
|
2015-11-11 20:18:18 +00:00
|
|
|
view: { icon: 'image' }
|
2014-09-18 19:49:22 +00:00
|
|
|
},
|
2015-02-11 19:14:43 +00:00
|
|
|
{
|
|
|
|
name: 'LicenseShortName',
|
|
|
|
value: ve.getProp( metadata, 'LicenseShortName', 'value' ),
|
|
|
|
data: {},
|
|
|
|
view: {
|
2015-02-16 22:49:12 +00:00
|
|
|
href: ve.getProp( metadata, 'LicenseUrl', 'value' ),
|
2015-02-11 19:14:43 +00:00
|
|
|
icon: this.getLicenseIcon( ve.getProp( metadata, 'LicenseShortName', 'value' ) )
|
|
|
|
}
|
|
|
|
},
|
2014-09-18 19:49:22 +00:00
|
|
|
{
|
|
|
|
name: 'Artist',
|
|
|
|
value: ve.getProp( metadata, 'Artist', 'value' ),
|
|
|
|
data: {},
|
|
|
|
view: {
|
2015-02-11 19:14:43 +00:00
|
|
|
// "Artist" label
|
|
|
|
label: 'visualeditor-dialog-media-info-meta-artist',
|
2018-10-11 01:34:27 +00:00
|
|
|
icon: 'userAvatar'
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Credit',
|
|
|
|
value: ve.getProp( metadata, 'Credit', 'value' ),
|
|
|
|
data: {},
|
2018-10-11 01:34:27 +00:00
|
|
|
view: { icon: 'userAvatar' }
|
2014-09-18 19:49:22 +00:00
|
|
|
},
|
|
|
|
{
|
2015-02-11 19:14:43 +00:00
|
|
|
name: 'user',
|
|
|
|
value: imageinfo.user,
|
|
|
|
data: { skipProcessing: true },
|
2014-09-18 19:49:22 +00:00
|
|
|
view: {
|
2018-10-11 01:34:27 +00:00
|
|
|
icon: 'userAvatar',
|
2015-02-11 19:14:43 +00:00
|
|
|
// This is 'uploaded by'
|
|
|
|
label: 'visualeditor-dialog-media-info-artist'
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'timestamp',
|
|
|
|
value: imageinfo.timestamp,
|
|
|
|
data: {
|
|
|
|
ignoreCharLimit: true
|
|
|
|
},
|
|
|
|
view: {
|
2015-11-21 03:26:39 +00:00
|
|
|
icon: 'clock',
|
2014-09-18 19:49:22 +00:00
|
|
|
label: 'visualeditor-dialog-media-info-uploaded',
|
|
|
|
isDate: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DateTimeOriginal',
|
|
|
|
value: ve.getProp( metadata, 'DateTimeOriginal', 'value' ),
|
|
|
|
data: {},
|
|
|
|
view: {
|
2015-11-21 03:26:39 +00:00
|
|
|
icon: 'clock',
|
2014-09-18 19:49:22 +00:00
|
|
|
label: 'visualeditor-dialog-media-info-created'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'moreinfo',
|
|
|
|
value: ve.msg( 'visualeditor-dialog-media-info-moreinfo' ),
|
|
|
|
data: {},
|
|
|
|
view: {
|
|
|
|
icon: 'info',
|
|
|
|
href: imageinfo.descriptionurl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
fields = {},
|
|
|
|
// Store clean API data
|
|
|
|
apiData = {},
|
|
|
|
fileType = this.getFileType( imageinfo.url ),
|
2015-04-09 23:47:15 +00:00
|
|
|
$thumbContainer = $( '<div>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.addClass( 've-ui-mwMediaDialog-panel-imageinfo-thumb' ),
|
2015-04-09 23:47:15 +00:00
|
|
|
$main = $( '<div>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.addClass( 've-ui-mwMediaDialog-panel-imageinfo-main' ),
|
2015-04-09 23:47:15 +00:00
|
|
|
$details = $( '<div>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.addClass( 've-ui-mwMediaDialog-panel-imageinfo-details' ),
|
2015-04-09 23:47:15 +00:00
|
|
|
$image = $( '<img>' );
|
2014-09-18 19:49:22 +00:00
|
|
|
|
|
|
|
// Main section - title
|
|
|
|
$main.append(
|
|
|
|
imageTitle.$element
|
|
|
|
.addClass( 've-ui-mwMediaDialog-panel-imageinfo-title' )
|
|
|
|
);
|
|
|
|
|
|
|
|
// Clean data from the API responses
|
|
|
|
for ( i = 0; i < apiDataKeysConfig.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
field = apiDataKeysConfig[ i ].name;
|
2014-09-18 19:49:22 +00:00
|
|
|
// Skip empty fields and those that are specifically configured to be skipped
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( apiDataKeysConfig[ i ].data.skipProcessing ) {
|
|
|
|
apiData[ field ] = apiDataKeysConfig[ i ].value;
|
2014-09-18 19:49:22 +00:00
|
|
|
} else {
|
|
|
|
// Store a clean information from the API.
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( apiDataKeysConfig[ i ].value ) {
|
|
|
|
apiData[ field ] = this.cleanAPIresponse( apiDataKeysConfig[ i ].value, apiDataKeysConfig[ i ].data );
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add sizing info for non-audio images
|
|
|
|
if ( imageinfo.mediatype === 'AUDIO' ) {
|
|
|
|
// Label this file as an audio
|
2016-10-28 00:22:30 +00:00
|
|
|
apiData.fileDetails = $( '<span>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.append( ve.msg( 'visualeditor-dialog-media-info-audiofile' ) );
|
|
|
|
} else {
|
|
|
|
// Build the display for image size and type
|
2015-04-09 23:47:15 +00:00
|
|
|
apiData.fileDetails = $( '<div>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<span>' ).text(
|
2014-09-18 19:49:22 +00:00
|
|
|
imageinfo.width +
|
2015-07-03 11:59:29 +00:00
|
|
|
'\u00a0' +
|
|
|
|
ve.msg( 'visualeditor-dimensionswidget-times' ) +
|
|
|
|
'\u00a0' +
|
2014-09-18 19:49:22 +00:00
|
|
|
imageinfo.height +
|
|
|
|
ve.msg( 'visualeditor-dimensionswidget-px' )
|
|
|
|
),
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<span>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.addClass( 've-ui-mwMediaDialog-panel-imageinfo-separator' )
|
|
|
|
.text( mw.msg( 'visualeditor-dialog-media-info-separator' ) ),
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<span>' ).text( fileType )
|
2014-09-18 19:49:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach all fields in order
|
|
|
|
for ( i = 0; i < apiDataKeysConfig.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
field = apiDataKeysConfig[ i ].name;
|
|
|
|
if ( apiData[ field ] ) {
|
|
|
|
$section = apiDataKeysConfig[ i ].view.primary ? $main : $details;
|
2014-09-18 19:49:22 +00:00
|
|
|
|
2015-08-19 17:33:02 +00:00
|
|
|
fields[ field ] = new ve.ui.MWMediaInfoFieldWidget( apiData[ field ], apiDataKeysConfig[ i ].view );
|
|
|
|
$section.append( fields[ field ].$element );
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the info panel
|
2015-04-09 23:47:15 +00:00
|
|
|
$info = $( '<div>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.addClass( 've-ui-mwMediaDialog-panel-imageinfo-info' )
|
|
|
|
.append(
|
2015-01-15 18:50:30 +00:00
|
|
|
$main.prop( 'dir', contentDirection ),
|
2014-09-18 19:49:22 +00:00
|
|
|
$details
|
|
|
|
);
|
2018-11-28 22:42:19 +00:00
|
|
|
ve.targetLinksToNewWindow( $info[ 0 ] );
|
2015-01-15 18:50:30 +00:00
|
|
|
|
|
|
|
// Initialize thumb container
|
|
|
|
$thumbContainer
|
|
|
|
.append( $image.prop( 'src', imageinfo.thumburl ) );
|
|
|
|
|
|
|
|
this.$infoPanelWrapper.append(
|
|
|
|
$thumbContainer,
|
|
|
|
$info
|
|
|
|
);
|
|
|
|
|
|
|
|
// Force a scrollbar to the screen before we measure it
|
|
|
|
this.mediaImageInfoPanel.$element.css( 'overflow-y', 'scroll' );
|
|
|
|
windowWidth = this.mediaImageInfoPanel.$element.width();
|
2014-09-18 19:49:22 +00:00
|
|
|
|
|
|
|
// Define thumbnail size
|
|
|
|
if ( imageinfo.mediatype === 'AUDIO' ) {
|
|
|
|
// HACK: We are getting the wrong information from the
|
|
|
|
// API about audio files. Set their thumbnail to square
|
|
|
|
newDimensions = {
|
|
|
|
width: imageinfo.thumbwidth,
|
|
|
|
height: imageinfo.thumbwidth
|
|
|
|
};
|
|
|
|
} else {
|
2015-01-15 18:50:30 +00:00
|
|
|
// For regular images, calculate a bigger image dimensions
|
|
|
|
newDimensions = ve.dm.MWImageNode.static.resizeToBoundingBox(
|
|
|
|
// Original image dimensions
|
|
|
|
{
|
|
|
|
width: imageinfo.width,
|
|
|
|
height: imageinfo.height
|
|
|
|
},
|
|
|
|
// Bounding box -- the size of the dialog, minus padding
|
|
|
|
{
|
|
|
|
width: windowWidth,
|
|
|
|
height: this.getBodyHeight() - 120
|
|
|
|
}
|
|
|
|
);
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
2015-01-15 18:50:30 +00:00
|
|
|
// Resize the image
|
|
|
|
$image.css( {
|
2014-09-18 19:49:22 +00:00
|
|
|
width: newDimensions.width,
|
|
|
|
height: newDimensions.height
|
2015-01-15 18:50:30 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Call for a bigger image
|
2015-09-22 15:55:01 +00:00
|
|
|
this.fetchThumbnail( imageTitleText, newDimensions )
|
2015-01-15 18:50:30 +00:00
|
|
|
.done( function ( thumburl ) {
|
|
|
|
if ( thumburl ) {
|
|
|
|
$image.prop( 'src', thumburl );
|
|
|
|
}
|
|
|
|
} );
|
2014-09-18 19:49:22 +00:00
|
|
|
|
2015-01-15 18:50:30 +00:00
|
|
|
isPortrait = newDimensions.width < ( windowWidth * 3 / 5 );
|
2014-09-18 19:49:22 +00:00
|
|
|
this.mediaImageInfoPanel.$element.toggleClass( 've-ui-mwMediaDialog-panel-imageinfo-portrait', isPortrait );
|
|
|
|
this.mediaImageInfoPanel.$element.append( this.$infoPanelWrapper );
|
|
|
|
if ( isPortrait ) {
|
2015-01-15 18:50:30 +00:00
|
|
|
$info.outerWidth( Math.floor( windowWidth - $thumbContainer.outerWidth( true ) - 15 ) );
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 23:40:26 +00:00
|
|
|
// Initialize fields
|
2014-09-18 19:49:22 +00:00
|
|
|
for ( field in fields ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
fields[ field ].initialize();
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
2015-01-15 18:50:30 +00:00
|
|
|
// Let the scrollbar appear naturally if it should
|
|
|
|
this.mediaImageInfoPanel.$element.css( 'overflow', '' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a bigger image thumbnail from the API.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2015-01-15 18:50:30 +00:00
|
|
|
* @param {string} imageName Image source
|
|
|
|
* @param {Object} dimensions Image dimensions
|
|
|
|
* @return {jQuery.Promise} Thumbnail promise that resolves with new thumb url
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.fetchThumbnail = function ( imageName, dimensions ) {
|
|
|
|
var dialog = this,
|
|
|
|
apiObj = {
|
|
|
|
action: 'query',
|
|
|
|
prop: 'imageinfo',
|
|
|
|
indexpageids: '1',
|
|
|
|
iiprop: 'url',
|
|
|
|
titles: imageName
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check cache first
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( this.searchCache[ imageName ] ) {
|
|
|
|
return $.Deferred().resolve( this.searchCache[ imageName ] );
|
2015-01-15 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( dimensions.width ) {
|
|
|
|
apiObj.iiurlwidth = dimensions.width;
|
|
|
|
}
|
|
|
|
if ( dimensions.height ) {
|
|
|
|
apiObj.iiurlheight = dimensions.height;
|
|
|
|
}
|
2018-05-04 13:30:10 +00:00
|
|
|
return ve.init.target.getContentApi( this.getFragment().getDocument() ).get( apiObj )
|
2015-01-15 18:50:30 +00:00
|
|
|
.then( function ( response ) {
|
2015-01-24 00:22:17 +00:00
|
|
|
var thumburl = ve.getProp(
|
2015-08-19 17:33:02 +00:00
|
|
|
response.query.pages[ response.query.pageids[ 0 ] ],
|
2015-01-15 18:50:30 +00:00
|
|
|
'imageinfo',
|
|
|
|
0,
|
|
|
|
'thumburl'
|
|
|
|
);
|
|
|
|
// Cache
|
2015-08-19 17:33:02 +00:00
|
|
|
dialog.searchCache[ imageName ] = thumburl;
|
2015-01-15 18:50:30 +00:00
|
|
|
return thumburl;
|
|
|
|
} );
|
2014-09-18 19:49:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean the API responses and return it in plaintext. If needed, truncate.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-09-18 19:49:22 +00:00
|
|
|
* @param {string} rawResponse Raw response from the API
|
|
|
|
* @param {Object} config Configuration options
|
|
|
|
* @return {string} Plaintext clean response
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.cleanAPIresponse = function ( rawResponse, config ) {
|
|
|
|
var isTruncated, charLimit,
|
|
|
|
html = $.parseHTML( rawResponse ),
|
|
|
|
ellipsis = ve.msg( 'visualeditor-dialog-media-info-ellipsis' ),
|
2015-04-09 23:47:15 +00:00
|
|
|
originalText = $( '<div>' ).append( html ).text();
|
2014-09-18 19:49:22 +00:00
|
|
|
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
charLimit = config.charLimit || 50;
|
|
|
|
isTruncated = originalText.length > charLimit;
|
|
|
|
|
|
|
|
if ( config.keepOriginal ) {
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the string should be truncated
|
|
|
|
return isTruncated && !config.ignoreCharLimit ?
|
|
|
|
originalText.substring( 0, charLimit ) + ellipsis :
|
|
|
|
originalText;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the file type from the suffix of the url
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-09-18 19:49:22 +00:00
|
|
|
* @param {string} url Full file url
|
|
|
|
* @return {string} File type
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.getFileType = function ( url ) {
|
|
|
|
// TODO: Validate these types, and work with icons
|
|
|
|
// SVG, PNG, JPEG, GIF, TIFF, XCF;
|
|
|
|
// OGA, OGG, MIDI, WAV;
|
|
|
|
// WEBM, OGV, OGX;
|
|
|
|
// APNG;
|
|
|
|
// PDF, DJVU
|
|
|
|
return url.split( '.' ).pop().toUpperCase();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the proper icon for the license if it is recognized
|
|
|
|
* or general info icon if it is not recognized.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-09-18 19:49:22 +00:00
|
|
|
* @param {string} license License short name
|
|
|
|
* @return {string} Icon name
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.getLicenseIcon = function ( license ) {
|
|
|
|
var normalized;
|
|
|
|
|
|
|
|
if ( !license ) {
|
|
|
|
return 'info';
|
|
|
|
}
|
|
|
|
|
|
|
|
normalized = license.toLowerCase().replace( /[-_]/g, ' ' );
|
|
|
|
|
|
|
|
// FIXME: Structured data from Commons will make this properly
|
|
|
|
// multilingual. For now, this is the limit of what is sensible.
|
|
|
|
if ( normalized.match( /^((cc )?pd|public domain)/ ) ) {
|
|
|
|
return 'public-domain';
|
|
|
|
} else if ( normalized.match( /^cc (by|sa)?/ ) ) {
|
2016-02-21 18:20:30 +00:00
|
|
|
return 'logoCC';
|
2014-09-18 19:49:22 +00:00
|
|
|
} else {
|
|
|
|
return 'info';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-07-13 15:06:01 +00:00
|
|
|
* Handle search results choose event.
|
2014-09-18 19:49:22 +00:00
|
|
|
*
|
2016-11-16 18:21:22 +00:00
|
|
|
* @param {mw.widgets.MediaResultWidget} item Chosen item
|
2014-09-18 19:49:22 +00:00
|
|
|
*/
|
2015-03-27 10:51:06 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onSearchResultsChoose = function ( item ) {
|
2015-10-07 18:34:21 +00:00
|
|
|
this.chooseImageInfo( item.getData() );
|
2015-09-22 15:55:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Choose image info for editing
|
|
|
|
*
|
|
|
|
* @param {Object} info Image info
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.chooseImageInfo = function ( info ) {
|
2015-03-27 10:51:06 +00:00
|
|
|
this.$infoPanelWrapper.empty();
|
|
|
|
// Switch panels
|
|
|
|
this.selectedImageInfo = info;
|
|
|
|
this.switchPanels( 'imageInfo' );
|
|
|
|
// Build info panel
|
|
|
|
this.buildMediaInfoPanel( info );
|
2014-09-18 19:49:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle new image being chosen.
|
|
|
|
*
|
2016-11-16 18:21:22 +00:00
|
|
|
* @param {mw.widgets.MediaResultWidget|null} item Selected item
|
2014-09-18 19:49:22 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.confirmSelectedImage = function () {
|
2015-09-22 15:55:01 +00:00
|
|
|
var title, imageTitleText,
|
2015-08-25 16:17:49 +00:00
|
|
|
obj = {},
|
2015-02-04 00:32:46 +00:00
|
|
|
info = this.selectedImageInfo;
|
2014-06-19 15:44:05 +00:00
|
|
|
|
2015-02-04 00:32:46 +00:00
|
|
|
if ( info ) {
|
2015-09-22 15:55:01 +00:00
|
|
|
imageTitleText = info.title || info.canonicaltitle;
|
2015-08-25 16:17:49 +00:00
|
|
|
// Run title through mw.Title so the File: prefix is localised
|
2015-09-22 15:55:01 +00:00
|
|
|
title = mw.Title.newFromText( imageTitleText ).getPrefixedText();
|
2014-06-19 15:44:05 +00:00
|
|
|
if ( !this.imageModel ) {
|
2014-07-25 02:28:07 +00:00
|
|
|
// Create a new image model based on default attributes
|
|
|
|
this.imageModel = ve.dm.MWImageModel.static.newFromImageAttributes(
|
|
|
|
{
|
|
|
|
// Per https://www.mediawiki.org/w/?diff=931265&oldid=prev
|
2015-08-25 16:17:49 +00:00
|
|
|
href: './' + title,
|
2014-08-07 17:02:52 +00:00
|
|
|
src: info.url,
|
2015-08-25 16:17:49 +00:00
|
|
|
resource: './' + title,
|
2014-07-25 02:28:07 +00:00
|
|
|
width: info.thumbwidth,
|
|
|
|
height: info.thumbheight,
|
|
|
|
mediaType: info.mediatype,
|
|
|
|
type: 'thumb',
|
|
|
|
align: 'default',
|
|
|
|
defaultSize: true
|
|
|
|
},
|
2015-08-27 06:49:26 +00:00
|
|
|
this.getFragment().getDocument()
|
2014-07-25 02:28:07 +00:00
|
|
|
);
|
|
|
|
this.attachImageModel();
|
2014-09-18 19:49:22 +00:00
|
|
|
this.resetCaption();
|
2014-06-19 15:44:05 +00:00
|
|
|
} else {
|
2014-07-25 02:28:07 +00:00
|
|
|
// Update the current image model with the new image source
|
|
|
|
this.imageModel.changeImageSource(
|
|
|
|
{
|
|
|
|
mediaType: info.mediatype,
|
2015-08-25 16:17:49 +00:00
|
|
|
href: './' + title,
|
2014-08-07 17:02:52 +00:00
|
|
|
src: info.url,
|
2015-08-25 16:17:49 +00:00
|
|
|
resource: './' + title
|
2014-07-25 02:28:07 +00:00
|
|
|
},
|
2015-01-17 01:27:35 +00:00
|
|
|
info
|
|
|
|
);
|
2018-07-03 16:59:43 +00:00
|
|
|
this.updateFilenameFieldset();
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
|
|
|
|
2015-01-31 00:58:14 +00:00
|
|
|
// Cache
|
2016-02-29 16:16:34 +00:00
|
|
|
// We're trimming the stored data down to be consistent with what
|
|
|
|
// ImageInfoCache.getRequestPromise fetches.
|
|
|
|
obj[ imageTitleText ] = {
|
|
|
|
size: info.size,
|
|
|
|
width: info.width,
|
|
|
|
height: info.height,
|
|
|
|
mediatype: info.mediatype
|
|
|
|
};
|
2015-01-31 00:58:14 +00:00
|
|
|
ve.init.platform.imageInfoCache.set( obj );
|
|
|
|
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-06-19 15:44:05 +00:00
|
|
|
this.switchPanels( 'edit' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-03 16:59:43 +00:00
|
|
|
/**
|
|
|
|
* Update the filename fieldset (link to media page)
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.updateFilenameFieldset = function () {
|
|
|
|
this.filenameFieldset.setLabel(
|
|
|
|
$( '<span>' ).append(
|
|
|
|
document.createTextNode( this.imageModel.getFilename() + ' ' ),
|
|
|
|
$( '<a>' )
|
2019-01-13 00:21:33 +00:00
|
|
|
.addClass( 've-ui-mwMediaDialog-description-link' )
|
2018-07-03 16:59:43 +00:00
|
|
|
.attr( 'href', ve.resolveUrl( this.imageModel.getResourceName(), this.getFragment().getDocument().getHtmlDocument() ) )
|
|
|
|
.attr( 'target', '_blank' )
|
|
|
|
.attr( 'rel', 'noopener' )
|
|
|
|
.text( ve.msg( 'visualeditor-dialog-media-content-description-link' ) )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-02-20 05:11:04 +00:00
|
|
|
/**
|
2014-03-25 16:01:04 +00:00
|
|
|
* Handle image model alignment change
|
2015-05-08 15:15:16 +00:00
|
|
|
*
|
2014-03-25 16:01:04 +00:00
|
|
|
* @param {string} alignment Image alignment
|
2014-02-20 05:11:04 +00:00
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onImageModelAlignmentChange = function ( alignment ) {
|
2014-05-24 02:42:14 +00:00
|
|
|
alignment = alignment || 'none';
|
|
|
|
|
|
|
|
// Select the item without triggering the 'choose' event
|
2015-05-08 15:15:16 +00:00
|
|
|
this.positionSelect.selectItemByData( alignment !== 'none' ? alignment : undefined );
|
2014-05-24 02:42:14 +00:00
|
|
|
|
2014-12-09 20:58:08 +00:00
|
|
|
this.positionCheckbox.setSelected( alignment !== 'none' );
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-02-20 05:11:04 +00:00
|
|
|
};
|
|
|
|
|
2014-02-24 21:56:24 +00:00
|
|
|
/**
|
2014-03-25 16:01:04 +00:00
|
|
|
* Handle image model type change
|
2015-05-08 15:15:16 +00:00
|
|
|
*
|
2015-08-19 18:33:59 +00:00
|
|
|
* @param {string} type Image type
|
2014-02-24 21:56:24 +00:00
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onImageModelTypeChange = function ( type ) {
|
2015-05-08 15:15:16 +00:00
|
|
|
this.typeSelect.selectItemByData( type );
|
2014-03-25 16:01:04 +00:00
|
|
|
|
|
|
|
this.borderCheckbox.setDisabled(
|
|
|
|
!this.imageModel.isBorderable()
|
|
|
|
);
|
2014-03-05 19:31:45 +00:00
|
|
|
|
2014-12-09 20:58:08 +00:00
|
|
|
this.borderCheckbox.setSelected(
|
2014-03-25 16:01:04 +00:00
|
|
|
this.imageModel.isBorderable() && this.imageModel.hasBorder()
|
|
|
|
);
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-02-24 21:56:24 +00:00
|
|
|
};
|
|
|
|
|
2014-01-21 18:05:50 +00:00
|
|
|
/**
|
2014-03-25 16:01:04 +00:00
|
|
|
* Handle change event on the positionCheckbox element.
|
|
|
|
*
|
2014-12-09 21:01:13 +00:00
|
|
|
* @param {boolean} isSelected Checkbox status
|
2014-01-21 18:05:50 +00:00
|
|
|
*/
|
2014-12-09 21:01:13 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onPositionCheckboxChange = function ( isSelected ) {
|
2014-06-05 02:15:42 +00:00
|
|
|
var newPositionValue,
|
|
|
|
currentModelAlignment = this.imageModel.getAlignment();
|
|
|
|
|
2014-12-09 21:01:13 +00:00
|
|
|
this.positionSelect.setDisabled( !isSelected );
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-06-10 19:18:36 +00:00
|
|
|
// Only update the model if the current value is different than that
|
|
|
|
// of the image model
|
2014-06-05 02:15:42 +00:00
|
|
|
if (
|
2014-12-09 21:01:13 +00:00
|
|
|
( currentModelAlignment === 'none' && isSelected ) ||
|
|
|
|
( currentModelAlignment !== 'none' && !isSelected )
|
2014-06-05 02:15:42 +00:00
|
|
|
) {
|
2014-12-09 21:01:13 +00:00
|
|
|
if ( isSelected ) {
|
2014-06-05 02:15:42 +00:00
|
|
|
// Picking a floating alignment value will create a block image
|
|
|
|
// no matter what the type is, so in here we want to calculate
|
|
|
|
// the default alignment of a block to set as our initial alignment
|
|
|
|
// in case the checkbox is clicked but there was no alignment set
|
|
|
|
// previously.
|
|
|
|
newPositionValue = this.imageModel.getDefaultDir( 'mwBlockImage' );
|
2014-06-03 04:20:57 +00:00
|
|
|
this.imageModel.setAlignment( newPositionValue );
|
2014-06-05 02:15:42 +00:00
|
|
|
} else {
|
|
|
|
// If we're unchecking the box, always set alignment to none and unselect the position widget
|
|
|
|
this.imageModel.setAlignment( 'none' );
|
2014-05-24 02:42:14 +00:00
|
|
|
}
|
2014-01-21 18:05:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-25 16:01:04 +00:00
|
|
|
/**
|
|
|
|
* Handle change event on the positionCheckbox element.
|
|
|
|
*
|
2014-12-09 21:01:13 +00:00
|
|
|
* @param {boolean} isSelected Checkbox status
|
2014-03-25 16:01:04 +00:00
|
|
|
*/
|
2014-12-09 21:01:13 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onBorderCheckboxChange = function ( isSelected ) {
|
2014-06-05 02:15:42 +00:00
|
|
|
// Only update if the value is different than the model
|
2014-12-09 21:01:13 +00:00
|
|
|
if ( this.imageModel.hasBorder() !== isSelected ) {
|
2014-06-05 02:15:42 +00:00
|
|
|
// Update the image model
|
2014-12-09 21:01:13 +00:00
|
|
|
this.imageModel.toggleBorder( isSelected );
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-06-05 02:15:42 +00:00
|
|
|
}
|
2014-03-25 16:01:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-11-12 19:09:52 +00:00
|
|
|
* Handle change event on the positionSelect element.
|
2014-03-25 16:01:04 +00:00
|
|
|
*
|
|
|
|
* @param {OO.ui.ButtonOptionWidget} item Selected item
|
|
|
|
*/
|
2014-11-12 19:09:52 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onPositionSelectChoose = function ( item ) {
|
2015-03-27 10:51:06 +00:00
|
|
|
var position = item.getData();
|
2014-03-25 16:01:04 +00:00
|
|
|
|
2014-06-05 02:15:42 +00:00
|
|
|
// Only update if the value is different than the model
|
|
|
|
if ( this.imageModel.getAlignment() !== position ) {
|
|
|
|
this.imageModel.setAlignment( position );
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-06-05 02:15:42 +00:00
|
|
|
}
|
2014-03-25 16:01:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-11-12 19:09:52 +00:00
|
|
|
* Handle change event on the typeSelect element.
|
2014-03-25 16:01:04 +00:00
|
|
|
*
|
2018-03-27 12:37:43 +00:00
|
|
|
* @param {OO.ui.MenuOptionWidget} item Selected item
|
2014-03-25 16:01:04 +00:00
|
|
|
*/
|
2014-11-12 19:09:52 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onTypeSelectChoose = function ( item ) {
|
2015-03-27 10:51:06 +00:00
|
|
|
var type = item.getData();
|
2014-03-25 16:01:04 +00:00
|
|
|
|
2014-06-05 02:15:42 +00:00
|
|
|
// Only update if the value is different than the model
|
|
|
|
if ( this.imageModel.getType() !== type ) {
|
|
|
|
this.imageModel.setType( type );
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-06-05 02:15:42 +00:00
|
|
|
}
|
2014-06-09 18:47:22 +00:00
|
|
|
|
2018-09-24 14:16:20 +00:00
|
|
|
// If type is 'frame', custom size is ignored
|
|
|
|
if ( type === 'frame' ) {
|
|
|
|
this.sizeWidget.setSizeType( 'default' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle changeSizeType events from the MediaSizeWidget
|
|
|
|
*
|
|
|
|
* @param {string} sizeType Size type
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.onChangeSizeType = function ( sizeType ) {
|
|
|
|
// type=frame is not resizeable, so change it to type=thumb
|
|
|
|
if ( sizeType === 'custom' && this.imageModel.getType() === 'frame' ) {
|
|
|
|
this.imageModel.setType( 'thumb' );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.checkChanged();
|
2014-04-16 22:12:39 +00:00
|
|
|
};
|
|
|
|
|
2014-08-07 17:02:52 +00:00
|
|
|
/**
|
|
|
|
* Respond to change in alternate text
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-08-07 17:02:52 +00:00
|
|
|
* @param {string} text New alternate text
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.onAlternateTextChange = function ( text ) {
|
|
|
|
this.imageModel.setAltText( text );
|
|
|
|
this.checkChanged();
|
|
|
|
};
|
|
|
|
|
2014-07-02 19:23:25 +00:00
|
|
|
/**
|
|
|
|
* When changes occur, enable the apply button.
|
|
|
|
*/
|
2014-08-07 17:02:52 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.checkChanged = function () {
|
|
|
|
var captionChanged = false;
|
|
|
|
|
|
|
|
// Only check 'changed' status after the model has finished
|
|
|
|
// building itself
|
|
|
|
if ( !this.isSettingUpModel ) {
|
2016-11-20 22:53:34 +00:00
|
|
|
captionChanged = !!this.captionTarget && this.captionTarget.hasBeenModified();
|
2014-08-07 17:02:52 +00:00
|
|
|
|
|
|
|
if (
|
2018-05-04 13:52:03 +00:00
|
|
|
this.imageModel &&
|
2014-09-16 18:48:40 +00:00
|
|
|
// Activate or deactivate the apply/insert buttons
|
|
|
|
// Make sure sizes are valid first
|
|
|
|
this.sizeWidget.isValid() &&
|
|
|
|
(
|
|
|
|
// Check that the model or caption changed
|
2018-05-04 13:52:03 +00:00
|
|
|
this.isInsertion ||
|
2014-09-16 18:48:40 +00:00
|
|
|
captionChanged ||
|
|
|
|
this.imageModel.hasBeenModified()
|
|
|
|
)
|
2014-08-07 17:02:52 +00:00
|
|
|
) {
|
2019-02-19 17:08:38 +00:00
|
|
|
this.actions.setAbilities( { insert: true, done: true } );
|
2014-08-07 17:02:52 +00:00
|
|
|
} else {
|
2019-02-19 17:08:38 +00:00
|
|
|
this.actions.setAbilities( { insert: false, done: false } );
|
2014-08-07 17:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-02 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWMediaDialog.super.prototype.getSetupProcess.call( this, data )
|
2014-05-31 04:47:08 +00:00
|
|
|
.next( function () {
|
2015-10-28 21:30:03 +00:00
|
|
|
var
|
|
|
|
dialog = this,
|
|
|
|
pageTitle = mw.config.get( 'wgTitle' ),
|
2014-07-02 19:23:25 +00:00
|
|
|
namespace = mw.config.get( 'wgNamespaceNumber' ),
|
2019-02-08 19:18:22 +00:00
|
|
|
namespacesWithSubpages = mw.config.get( 'wgVisualEditorConfig' ).namespacesWithSubpages,
|
|
|
|
isReadOnly = this.isReadOnly();
|
2014-07-02 19:23:25 +00:00
|
|
|
|
|
|
|
// Read the page title
|
|
|
|
if ( namespacesWithSubpages[ namespace ] ) {
|
|
|
|
// If we are in a namespace that allows for subpages, strip the entire
|
|
|
|
// title except for the part after the last /
|
2014-12-06 19:11:02 +00:00
|
|
|
pageTitle = pageTitle.slice( pageTitle.lastIndexOf( '/' ) + 1 );
|
2014-07-02 19:23:25 +00:00
|
|
|
}
|
|
|
|
this.pageTitle = pageTitle;
|
2014-05-31 04:47:08 +00:00
|
|
|
|
2014-09-18 19:49:22 +00:00
|
|
|
// Set language for search results
|
|
|
|
this.search.setLang( this.getFragment().getDocument().getLang() );
|
|
|
|
|
2014-07-17 19:55:24 +00:00
|
|
|
if ( this.selectedNode ) {
|
2014-08-07 17:02:52 +00:00
|
|
|
this.isInsertion = false;
|
2014-07-25 02:28:07 +00:00
|
|
|
// Create image model
|
2015-08-27 06:49:26 +00:00
|
|
|
this.imageModel = ve.dm.MWImageModel.static.newFromImageNode( this.selectedNode );
|
2014-07-25 02:28:07 +00:00
|
|
|
this.attachImageModel();
|
|
|
|
|
|
|
|
if ( !this.imageModel.isDefaultSize() ) {
|
|
|
|
// To avoid dirty diff in case where only the image changes,
|
|
|
|
// we will store the initial bounding box, in case the image
|
|
|
|
// is not defaultSize
|
|
|
|
this.imageModel.setBoundingBox( this.imageModel.getCurrentDimensions() );
|
|
|
|
}
|
2014-08-07 17:02:52 +00:00
|
|
|
// Store initial hash to compare against
|
|
|
|
this.imageModel.storeInitialHash( this.imageModel.getHashObject() );
|
|
|
|
} else {
|
|
|
|
this.isInsertion = true;
|
2014-07-17 19:55:24 +00:00
|
|
|
}
|
2014-05-31 04:47:08 +00:00
|
|
|
|
2015-04-16 19:14:27 +00:00
|
|
|
this.search.setup();
|
|
|
|
|
2018-07-18 00:45:14 +00:00
|
|
|
// Set initial values
|
|
|
|
this.search.getQuery().setValue( this.pageTitle );
|
2014-06-19 15:44:05 +00:00
|
|
|
this.resetCaption();
|
2014-05-31 04:47:08 +00:00
|
|
|
|
2019-02-08 19:18:22 +00:00
|
|
|
this.altTextInput.setReadOnly( isReadOnly );
|
|
|
|
this.positionCheckbox.setDisabled( isReadOnly );
|
|
|
|
// TODO: This widget is not readable when disabled
|
|
|
|
this.positionSelect.setDisabled( isReadOnly );
|
|
|
|
this.typeSelectDropdown.setDisabled( isReadOnly );
|
|
|
|
this.borderCheckbox.setDisabled( isReadOnly );
|
|
|
|
this.sizeWidget.setDisabled( isReadOnly );
|
|
|
|
|
2018-07-18 00:45:14 +00:00
|
|
|
// Pass `true` to avoid focussing. If we focus the image caption widget during dialog
|
|
|
|
// opening, and it wants to display a context menu, it will be mispositioned.
|
|
|
|
this.switchPanels( this.selectedNode ? 'edit' : 'search', true );
|
|
|
|
|
2015-10-22 17:44:39 +00:00
|
|
|
// Reset upload booklet
|
|
|
|
// The first time this is called, it will try to switch panels,
|
|
|
|
// so the this.switchPanels() call has to be later.
|
2018-09-17 16:50:28 +00:00
|
|
|
return ( this.mediaUploadBooklet ?
|
|
|
|
this.mediaUploadBooklet.initialize() :
|
|
|
|
$.Deferred().resolve().promise()
|
|
|
|
).then( function () {
|
2019-02-19 17:08:38 +00:00
|
|
|
dialog.actions.setAbilities( { upload: false, save: false, insert: false, done: false } );
|
2014-05-31 04:47:08 +00:00
|
|
|
|
2015-10-28 21:30:03 +00:00
|
|
|
if ( data.file ) {
|
2017-05-10 18:46:49 +00:00
|
|
|
dialog.searchTabs.setTabPanel( 'upload' );
|
2015-10-28 21:30:03 +00:00
|
|
|
dialog.mediaUploadBooklet.setFile( data.file );
|
|
|
|
}
|
|
|
|
} );
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
/**
|
|
|
|
* Switch between the edit and insert/search panels
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-06-19 15:44:05 +00:00
|
|
|
* @param {string} panel Panel name
|
2018-07-18 00:45:14 +00:00
|
|
|
* @param {boolean} [noFocus] Do not put focus into the default field of the panel
|
2014-06-19 15:44:05 +00:00
|
|
|
*/
|
2018-07-18 00:45:14 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.switchPanels = function ( panel, noFocus ) {
|
2014-06-19 15:44:05 +00:00
|
|
|
switch ( panel ) {
|
|
|
|
case 'edit':
|
2018-09-17 16:50:28 +00:00
|
|
|
this.setSize( this.constructor.static.size );
|
2014-07-02 19:23:25 +00:00
|
|
|
// Set the edit panel
|
2018-09-17 16:50:28 +00:00
|
|
|
this.panels.setItem( this.mediaSettingsLayout );
|
2014-07-02 19:23:25 +00:00
|
|
|
// Focus the general settings page
|
2018-09-17 16:50:28 +00:00
|
|
|
this.mediaSettingsLayout.setTabPanel( 'general' );
|
2019-02-19 17:08:38 +00:00
|
|
|
// Parent functionality (edit/insert/readonly)
|
|
|
|
this.actions.setMode( this.getMode() );
|
2018-07-18 00:45:14 +00:00
|
|
|
if ( !noFocus ) {
|
|
|
|
// Focus the caption surface
|
|
|
|
this.captionTarget.focus();
|
|
|
|
}
|
2014-06-19 15:44:05 +00:00
|
|
|
break;
|
|
|
|
case 'search':
|
2015-01-17 00:01:59 +00:00
|
|
|
this.setSize( 'larger' );
|
2014-09-18 19:49:22 +00:00
|
|
|
this.selectedImageInfo = null;
|
2014-07-02 19:23:25 +00:00
|
|
|
// Set the edit panel
|
2014-06-19 15:44:05 +00:00
|
|
|
this.panels.setItem( this.mediaSearchPanel );
|
2017-05-10 18:46:49 +00:00
|
|
|
this.searchTabs.setTabPanel( 'search' );
|
2015-10-10 15:40:39 +00:00
|
|
|
this.searchTabs.toggleMenu( true );
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setMode( this.imageModel ? 'change' : 'select' );
|
2018-07-18 00:45:14 +00:00
|
|
|
if ( !noFocus ) {
|
|
|
|
this.search.getQuery().focus().select();
|
|
|
|
}
|
2015-01-16 17:11:13 +00:00
|
|
|
// Layout pending items
|
|
|
|
this.search.runLayoutQueue();
|
2014-09-18 19:49:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 'imageInfo':
|
2015-01-17 00:01:59 +00:00
|
|
|
this.setSize( 'larger' );
|
2014-09-18 19:49:22 +00:00
|
|
|
// Hide/show buttons
|
|
|
|
this.actions.setMode( 'info' );
|
|
|
|
// Hide/show the panels
|
2015-01-16 17:11:13 +00:00
|
|
|
this.panels.setItem( this.mediaImageInfoPanel );
|
2014-06-19 15:44:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-07 02:07:11 +00:00
|
|
|
this.currentPanel = panel || 'imageinfo';
|
2014-06-19 15:44:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-07-25 02:28:07 +00:00
|
|
|
* Attach the image model to the dialog
|
2014-06-19 15:44:05 +00:00
|
|
|
*/
|
2014-07-25 02:28:07 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.attachImageModel = function () {
|
2014-06-19 15:44:05 +00:00
|
|
|
if ( this.imageModel ) {
|
|
|
|
this.imageModel.disconnect( this );
|
2014-07-08 05:42:31 +00:00
|
|
|
this.sizeWidget.disconnect( this );
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.imageModel.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
alignmentChange: 'onImageModelAlignmentChange',
|
|
|
|
typeChange: 'onImageModelTypeChange',
|
2014-08-07 17:02:52 +00:00
|
|
|
sizeDefaultChange: 'checkChanged'
|
2014-06-19 15:44:05 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Set up
|
2014-08-07 17:02:52 +00:00
|
|
|
// Ignore the following changes in validation while we are
|
|
|
|
// setting up the initial tools according to the model state
|
|
|
|
this.isSettingUpModel = true;
|
2014-06-19 15:44:05 +00:00
|
|
|
|
2015-01-08 23:40:12 +00:00
|
|
|
// Filename
|
2018-07-03 16:59:43 +00:00
|
|
|
this.updateFilenameFieldset();
|
2015-01-08 23:40:12 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
// Size widget
|
|
|
|
this.sizeWidget.setScalable( this.imageModel.getScalable() );
|
2014-10-21 22:15:44 +00:00
|
|
|
this.sizeWidget.connect( this, {
|
2018-09-24 14:16:20 +00:00
|
|
|
changeSizeType: 'onChangeSizeType',
|
2014-10-21 22:15:44 +00:00
|
|
|
change: 'checkChanged',
|
|
|
|
valid: 'checkChanged'
|
|
|
|
} );
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
// Initialize size
|
2017-07-18 11:55:33 +00:00
|
|
|
this.sizeWidget.setSizeType( this.imageModel.isDefaultSize() ? 'default' : 'custom' );
|
2014-06-19 15:44:05 +00:00
|
|
|
|
2014-07-25 02:28:07 +00:00
|
|
|
// Update default dimensions
|
|
|
|
this.sizeWidget.updateDefaultDimensions();
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
// Set initial alt text
|
2015-05-08 15:15:16 +00:00
|
|
|
this.altTextInput.setValue( this.imageModel.getAltText() );
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
// Set initial alignment
|
2015-05-08 15:15:16 +00:00
|
|
|
this.positionSelect.setDisabled( !this.imageModel.isAligned() );
|
|
|
|
this.positionSelect.selectItemByData( this.imageModel.isAligned() && this.imageModel.getAlignment() );
|
|
|
|
this.positionCheckbox.setSelected( this.imageModel.isAligned() );
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
// Border flag
|
2015-05-08 15:15:16 +00:00
|
|
|
this.borderCheckbox.setDisabled( !this.imageModel.isBorderable() );
|
|
|
|
this.borderCheckbox.setSelected( this.imageModel.isBorderable() && this.imageModel.hasBorder() );
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
// Type select
|
2015-05-08 15:15:16 +00:00
|
|
|
this.typeSelect.selectItemByData( this.imageModel.getType() || 'none' );
|
2014-08-07 17:02:52 +00:00
|
|
|
|
|
|
|
this.isSettingUpModel = false;
|
2014-06-19 15:44:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the caption surface
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.resetCaption = function () {
|
2016-11-20 22:53:34 +00:00
|
|
|
var captionNode, captionDocument,
|
2014-12-10 19:40:22 +00:00
|
|
|
doc = this.getFragment().getDocument();
|
2014-06-19 15:44:05 +00:00
|
|
|
|
2014-07-17 19:55:24 +00:00
|
|
|
// Get existing caption. We only do this in setup, because the caption
|
|
|
|
// should not reset to original if the image is replaced or edited.
|
2016-11-20 22:53:34 +00:00
|
|
|
//
|
2014-07-17 19:55:24 +00:00
|
|
|
// If the selected node is a block image and the caption already exists,
|
|
|
|
// store the initial caption and set it as the caption document
|
|
|
|
if (
|
|
|
|
this.imageModel &&
|
|
|
|
this.selectedNode &&
|
|
|
|
this.selectedNode.getDocument() &&
|
|
|
|
this.selectedNode instanceof ve.dm.MWBlockImageNode
|
|
|
|
) {
|
2016-11-20 22:53:34 +00:00
|
|
|
captionNode = this.selectedNode.getCaptionNode();
|
|
|
|
if ( captionNode && captionNode.getLength() > 0 ) {
|
2014-07-17 19:55:24 +00:00
|
|
|
this.imageModel.setCaptionDocument(
|
2016-11-20 22:53:34 +00:00
|
|
|
this.selectedNode.getDocument().cloneFromRange( captionNode.getRange() )
|
2014-07-17 19:55:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
if ( this.imageModel ) {
|
|
|
|
captionDocument = this.imageModel.getCaptionDocument();
|
|
|
|
} else {
|
2016-05-30 20:40:07 +00:00
|
|
|
captionDocument = doc.cloneWithData( [
|
2014-08-22 20:50:48 +00:00
|
|
|
{ type: 'paragraph', internal: { generated: 'wrapper' } },
|
|
|
|
{ type: '/paragraph' },
|
|
|
|
{ type: 'internalList' },
|
|
|
|
{ type: '/internalList' }
|
2016-05-30 20:40:07 +00:00
|
|
|
] );
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
|
|
|
|
2016-11-20 22:53:34 +00:00
|
|
|
// Set document
|
|
|
|
this.captionTarget.setDocument( captionDocument );
|
2019-02-08 19:18:22 +00:00
|
|
|
this.captionTarget.setReadOnly( this.isReadOnly() );
|
2015-07-18 21:42:09 +00:00
|
|
|
this.captionTarget.initialize();
|
2014-06-19 15:44:05 +00:00
|
|
|
};
|
|
|
|
|
2014-04-16 22:12:39 +00:00
|
|
|
/**
|
2014-05-31 04:47:08 +00:00
|
|
|
* @inheritdoc
|
2014-04-16 22:12:39 +00:00
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWMediaDialog.super.prototype.getReadyProcess.call( this, data )
|
2014-05-31 04:47:08 +00:00
|
|
|
.next( function () {
|
2018-10-30 02:07:30 +00:00
|
|
|
if ( !data.file ) {
|
|
|
|
this.switchPanels( this.selectedNode ? 'edit' : 'search' );
|
|
|
|
}
|
2014-07-25 02:28:07 +00:00
|
|
|
// Revalidate size
|
|
|
|
this.sizeWidget.validateDimensions();
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2014-04-16 22:12:39 +00:00
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWMediaDialog.super.prototype.getTeardownProcess.call( this, data )
|
2014-05-31 04:47:08 +00:00
|
|
|
.first( function () {
|
2018-10-05 17:11:23 +00:00
|
|
|
this.mediaSettingsLayout.resetScroll();
|
2014-05-31 04:47:08 +00:00
|
|
|
// Cleanup
|
2014-06-19 15:44:05 +00:00
|
|
|
this.search.getQuery().setValue( '' );
|
2015-04-16 19:14:27 +00:00
|
|
|
this.search.teardown();
|
2014-06-19 15:44:05 +00:00
|
|
|
if ( this.imageModel ) {
|
|
|
|
this.imageModel.disconnect( this );
|
2014-07-14 21:32:49 +00:00
|
|
|
this.sizeWidget.disconnect( this );
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
2016-11-20 22:53:34 +00:00
|
|
|
this.captionTarget.clear();
|
2014-06-19 15:44:05 +00:00
|
|
|
this.imageModel = null;
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2014-04-24 00:22:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.getActionProcess = function ( action ) {
|
2014-09-18 19:49:22 +00:00
|
|
|
var handler;
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-09-18 19:49:22 +00:00
|
|
|
switch ( action ) {
|
|
|
|
case 'change':
|
|
|
|
handler = function () {
|
|
|
|
this.switchPanels( 'search' );
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'back':
|
|
|
|
handler = function () {
|
|
|
|
this.switchPanels( 'edit' );
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'choose':
|
|
|
|
handler = function () {
|
|
|
|
this.confirmSelectedImage();
|
|
|
|
this.switchPanels( 'edit' );
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'cancelchoose':
|
|
|
|
handler = function () {
|
2018-07-18 00:45:14 +00:00
|
|
|
this.switchPanels( 'search' );
|
2018-09-17 16:50:28 +00:00
|
|
|
if ( this.mediaUploadBooklet ) {
|
|
|
|
// Reset upload booklet, in case we got here by uploading a file
|
|
|
|
return this.mediaUploadBooklet.initialize();
|
|
|
|
}
|
2014-09-18 19:49:22 +00:00
|
|
|
};
|
|
|
|
break;
|
2016-09-22 14:12:55 +00:00
|
|
|
case 'cancelupload':
|
|
|
|
handler = function () {
|
2017-05-10 18:46:49 +00:00
|
|
|
this.searchTabs.setTabPanel( 'upload' );
|
2016-09-22 14:12:55 +00:00
|
|
|
this.searchTabs.toggleMenu( true );
|
|
|
|
return this.mediaUploadBooklet.initialize();
|
|
|
|
};
|
|
|
|
break;
|
2015-09-22 15:55:01 +00:00
|
|
|
case 'upload':
|
|
|
|
return new OO.ui.Process( this.mediaUploadBooklet.uploadFile() );
|
|
|
|
case 'save':
|
|
|
|
return new OO.ui.Process( this.mediaUploadBooklet.saveFile() );
|
2019-02-19 17:08:38 +00:00
|
|
|
case 'done':
|
2014-09-18 19:49:22 +00:00
|
|
|
case 'insert':
|
|
|
|
handler = function () {
|
|
|
|
var surfaceModel = this.getFragment().getSurface();
|
|
|
|
|
|
|
|
// Update from the form
|
|
|
|
this.imageModel.setAltText( this.altTextInput.getValue() );
|
|
|
|
this.imageModel.setCaptionDocument(
|
2015-07-18 21:42:09 +00:00
|
|
|
this.captionTarget.getSurface().getModel().getDocument()
|
2014-09-18 19:49:22 +00:00
|
|
|
);
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2015-08-02 17:42:07 +00:00
|
|
|
if (
|
|
|
|
// There was an initial node
|
|
|
|
this.selectedNode &&
|
2015-12-09 16:47:13 +00:00
|
|
|
// And we didn't change the image type block/inline or vice versa
|
2015-08-02 17:42:07 +00:00
|
|
|
this.selectedNode.type === this.imageModel.getImageNodeType() &&
|
|
|
|
// And we didn't change the image itself
|
|
|
|
this.selectedNode.getAttribute( 'src' ) ===
|
|
|
|
this.imageModel.getImageSource()
|
|
|
|
) {
|
|
|
|
// We only need to update the attributes of the current node
|
|
|
|
this.imageModel.updateImageNode( this.selectedNode, surfaceModel );
|
|
|
|
} else {
|
|
|
|
// Replacing an image or inserting a brand new one
|
|
|
|
this.fragment = this.imageModel.insertImageNode( this.getFragment() );
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 19:49:22 +00:00
|
|
|
this.close( { action: action } );
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ve.ui.MWMediaDialog.super.prototype.getActionProcess.call( this, action );
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
2014-09-18 19:49:22 +00:00
|
|
|
|
|
|
|
return new OO.ui.Process( handler, this );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.windowFactory.register( ve.ui.MWMediaDialog );
|