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
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 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-01-26 14:26:57 +00:00
|
|
|
this.store = null;
|
2014-06-19 15:44:05 +00:00
|
|
|
this.fileRepoPromise = 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-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
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.icon = 'picture';
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWMediaDialog.static.size = 'large';
|
|
|
|
|
|
|
|
ve.ui.MWMediaDialog.static.actions = [
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'apply',
|
|
|
|
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' ),
|
|
|
|
flags: [ 'primary', 'constructive' ],
|
|
|
|
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-08-22 20:50:48 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
|
|
|
|
flags: 'safe',
|
|
|
|
modes: [ 'edit', 'insert', 'select' ]
|
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' ),
|
|
|
|
flags: 'safe',
|
|
|
|
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
|
|
|
|
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',
|
|
|
|
'number',
|
|
|
|
'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 () {
|
2014-05-23 09:57:58 +00:00
|
|
|
return ve.extendObject(
|
2014-11-24 11:27:25 +00:00
|
|
|
ve.copy( ve.init.target.constructor.static.importRules ),
|
2014-05-23 09:57:58 +00:00
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
all: {
|
|
|
|
blacklist: OO.simpleArrayUnion(
|
2014-11-24 11:27:25 +00:00
|
|
|
ve.getProp( ve.init.target.constructor.static.importRules, 'all', 'blacklist' ) || [],
|
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
|
|
|
|
'list', 'listItem', 'definitionList', 'definitionListItem',
|
|
|
|
'table', 'tableCaption', 'tableSection', 'tableRow', 'tableCell'
|
|
|
|
]
|
|
|
|
),
|
|
|
|
// Headings are also possible, but discouraged
|
2014-08-22 20:50:48 +00:00
|
|
|
conversions: {
|
|
|
|
mwHeading: 'paragraph'
|
2014-05-23 09:57:58 +00:00
|
|
|
}
|
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 () {
|
|
|
|
return 400;
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.initialize = function () {
|
2014-08-06 12:29:41 +00:00
|
|
|
var altTextFieldset, positionFieldset, borderField, positionField,
|
2014-08-16 06:38:00 +00:00
|
|
|
alignLeftButton, alignCenterButton, alignRightButton, alignButtons;
|
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
|
|
|
|
2014-04-10 00:26:48 +00:00
|
|
|
this.$spinner = this.$( '<div>' ).addClass( 've-specialchar-spinner' );
|
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
this.panels = new OO.ui.StackLayout( { $: this.$ } );
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// Set up the booklet layout
|
|
|
|
this.bookletLayout = new OO.ui.BookletLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
outlined: true
|
2013-12-21 22:37:54 +00:00
|
|
|
} );
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
this.mediaSearchPanel = new OO.ui.PanelLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
scrollable: true
|
2014-06-19 15:44:05 +00:00
|
|
|
} );
|
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
this.generalSettingsPage = new OO.ui.PageLayout( 'general', { $: this.$ } );
|
|
|
|
this.advancedSettingsPage = new OO.ui.PageLayout( 'advanced', { $: this.$ } );
|
2013-12-21 22:37:54 +00:00
|
|
|
this.bookletLayout.addPages( [
|
|
|
|
this.generalSettingsPage, this.advancedSettingsPage
|
|
|
|
] );
|
2014-02-15 01:37:32 +00:00
|
|
|
this.generalSettingsPage.getOutlineItem()
|
|
|
|
.setIcon( 'parameter' )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-media-page-general' ) );
|
|
|
|
this.advancedSettingsPage.getOutlineItem()
|
|
|
|
.setIcon( 'parameter' )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-media-page-advanced' ) );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
// Define the media search page
|
2014-08-22 20:50:48 +00:00
|
|
|
this.search = new ve.ui.MWMediaSearchWidget( { $: this.$ } );
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
this.$body.append( this.search.$spinner );
|
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// Define fieldsets for image settings
|
|
|
|
|
|
|
|
// Caption
|
2014-01-26 14:26:57 +00:00
|
|
|
this.captionFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-content-section' ),
|
|
|
|
icon: 'parameter'
|
2013-06-18 22:58:10 +00:00
|
|
|
} );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2013-12-28 10:29:35 +00:00
|
|
|
// Alt text
|
|
|
|
altTextFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-alttext-section' ),
|
|
|
|
icon: 'parameter'
|
2013-12-28 10:29:35 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
this.altTextInput = new OO.ui.TextInputWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$
|
2013-12-28 10:29:35 +00:00
|
|
|
} );
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
this.altTextInput.$element.addClass( 've-ui-mwMediaDialog-altText' );
|
2014-02-18 19:45:21 +00:00
|
|
|
|
2013-12-28 10:29:35 +00:00
|
|
|
// Build alt text fieldset
|
|
|
|
altTextFieldset.$element
|
|
|
|
.append( this.altTextInput.$element );
|
|
|
|
|
2013-12-29 03:49:06 +00:00
|
|
|
// Position
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect = new OO.ui.ButtonSelectWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$
|
2013-12-29 03:49:06 +00:00
|
|
|
} );
|
2014-08-06 12:29:41 +00:00
|
|
|
|
2014-11-22 01:40:00 +00:00
|
|
|
alignLeftButton = new OO.ui.ButtonOptionWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'left',
|
2014-08-22 20:50:48 +00:00
|
|
|
icon: 'align-float-left',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-position-left' )
|
2014-08-06 12:29:41 +00:00
|
|
|
} );
|
2014-11-22 01:40:00 +00:00
|
|
|
alignCenterButton = new OO.ui.ButtonOptionWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'center',
|
2014-08-22 20:50:48 +00:00
|
|
|
icon: 'align-center',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-position-center' )
|
2014-08-06 12:29:41 +00:00
|
|
|
} );
|
2014-11-22 01:40:00 +00:00
|
|
|
alignRightButton = new OO.ui.ButtonOptionWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'right',
|
2014-08-22 20:50:48 +00:00
|
|
|
icon: 'align-float-right',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-position-right' )
|
2014-08-06 12:29:41 +00:00
|
|
|
} );
|
|
|
|
|
2014-08-21 00:50:54 +00:00
|
|
|
alignButtons = ( this.getDir() === 'ltr' ) ?
|
2014-08-06 12:29:41 +00:00
|
|
|
[ alignLeftButton, alignCenterButton, alignRightButton ] :
|
|
|
|
[ alignRightButton, alignCenterButton, alignLeftButton ];
|
|
|
|
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect.addItems( alignButtons, 0 );
|
2014-01-21 18:05:50 +00:00
|
|
|
|
|
|
|
this.positionCheckbox = new OO.ui.CheckboxInputWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$
|
2014-01-21 18:05:50 +00:00
|
|
|
} );
|
|
|
|
positionField = new OO.ui.FieldLayout( this.positionCheckbox, {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
align: 'inline',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-position-checkbox' )
|
2014-01-21 18:05:50 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
positionFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-position-section' ),
|
|
|
|
icon: 'parameter'
|
2014-01-21 18:05:50 +00:00
|
|
|
} );
|
|
|
|
|
2013-12-29 03:49:06 +00:00
|
|
|
// Build position fieldset
|
2014-08-12 13:57:07 +00:00
|
|
|
positionFieldset.$element.append(
|
2014-01-21 18:05:50 +00:00
|
|
|
positionField.$element,
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect.$element
|
2014-08-12 13:57:07 +00:00
|
|
|
);
|
2013-12-29 03:49:06 +00:00
|
|
|
|
2013-12-29 05:49:56 +00:00
|
|
|
// Type
|
|
|
|
this.typeFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-section' ),
|
|
|
|
icon: 'parameter'
|
2013-12-29 05:49:56 +00:00
|
|
|
} );
|
|
|
|
|
2014-11-12 19:09:52 +00:00
|
|
|
this.typeSelect = new OO.ui.ButtonSelectWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$
|
2013-12-29 05:49:56 +00:00
|
|
|
} );
|
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
|
2014-11-22 01:40:00 +00:00
|
|
|
new OO.ui.ButtonOptionWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'thumb',
|
2014-08-22 20:50:48 +00:00
|
|
|
icon: 'image-thumbnail',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-thumb' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} ),
|
2014-11-22 01:40:00 +00:00
|
|
|
new OO.ui.ButtonOptionWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'frameless',
|
2014-08-22 20:50:48 +00:00
|
|
|
icon: 'image-frameless',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-frameless' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} ),
|
2014-11-22 01:40:00 +00:00
|
|
|
new OO.ui.ButtonOptionWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'frame',
|
2014-08-22 20:50:48 +00:00
|
|
|
icon: 'image-frame',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-frame' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} ),
|
2014-11-22 01:40:00 +00:00
|
|
|
new OO.ui.ButtonOptionWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-22 01:40:00 +00:00
|
|
|
data: 'none',
|
2014-08-22 20:50:48 +00:00
|
|
|
icon: 'image-none',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-none' )
|
2013-12-29 05:49:56 +00:00
|
|
|
} )
|
|
|
|
] );
|
2014-02-27 17:39:19 +00:00
|
|
|
this.borderCheckbox = new OO.ui.CheckboxInputWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$
|
2014-02-27 17:39:19 +00:00
|
|
|
} );
|
|
|
|
borderField = new OO.ui.FieldLayout( this.borderCheckbox, {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
align: 'inline',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-type-border' )
|
2014-02-27 17:39:19 +00:00
|
|
|
} );
|
2013-12-29 05:49:56 +00:00
|
|
|
|
|
|
|
// Build type fieldset
|
2014-08-12 13:57:07 +00:00
|
|
|
this.typeFieldset.$element.append(
|
2014-11-12 19:09:52 +00:00
|
|
|
this.typeSelect.$element,
|
2014-02-27 17:39:19 +00:00
|
|
|
borderField.$element
|
2014-08-12 13:57:07 +00:00
|
|
|
);
|
2013-12-29 05:49:56 +00:00
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// Size
|
2014-01-26 14:26:57 +00:00
|
|
|
this.sizeFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-size-section' ),
|
|
|
|
icon: 'parameter'
|
2013-12-21 22:37:54 +00:00
|
|
|
} );
|
|
|
|
|
2014-01-22 20:13:59 +00:00
|
|
|
this.sizeErrorLabel = new OO.ui.LabelWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-size-originalsize-error' )
|
2013-12-21 22:37:54 +00:00
|
|
|
} );
|
|
|
|
|
2014-04-10 00:26:48 +00:00
|
|
|
this.sizeWidget = new ve.ui.MediaSizeWidget( {}, {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$
|
2014-02-20 05:11:04 +00:00
|
|
|
} );
|
|
|
|
|
2014-08-12 13:57:07 +00:00
|
|
|
this.$sizeWidgetElements = this.$( '<div>' ).append(
|
2014-01-26 14:26:57 +00:00
|
|
|
this.sizeWidget.$element,
|
2014-01-26 15:02:07 +00:00
|
|
|
this.sizeErrorLabel.$element
|
2014-08-12 13:57:07 +00:00
|
|
|
);
|
|
|
|
this.sizeFieldset.$element.append(
|
2014-04-10 00:26:48 +00:00
|
|
|
this.$spinner,
|
|
|
|
this.$sizeWidgetElements
|
2014-08-12 13:57:07 +00:00
|
|
|
);
|
2013-12-21 22:37:54 +00:00
|
|
|
|
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' } );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.search.connect( this, { select: 'onSearchSelect' } );
|
2014-08-07 17:02:52 +00:00
|
|
|
this.altTextInput.connect( this, { change: 'onAlternateTextChange' } );
|
2014-06-19 15:44:05 +00:00
|
|
|
// Panel classes
|
|
|
|
this.mediaSearchPanel.$element.addClass( 've-ui-mwMediaDialog-panel-search' );
|
|
|
|
this.bookletLayout.$element.addClass( 've-ui-mwMediaDialog-panel-settings' );
|
2014-07-14 21:32:49 +00:00
|
|
|
this.$body.append( this.panels.$element );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-06-19 15:44:05 +00:00
|
|
|
this.mediaSearchPanel.$element.append( this.search.$element );
|
2014-08-12 13:57:07 +00:00
|
|
|
this.generalSettingsPage.$element.append(
|
2013-12-28 10:29:35 +00:00
|
|
|
this.captionFieldset.$element,
|
|
|
|
altTextFieldset.$element
|
2014-08-12 13:57:07 +00:00
|
|
|
);
|
2013-12-29 03:49:06 +00:00
|
|
|
|
2014-08-12 13:57:07 +00:00
|
|
|
this.advancedSettingsPage.$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
|
|
|
);
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
this.panels.addItems( [ this.mediaSearchPanel, this.bookletLayout ] );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle search result selection.
|
|
|
|
*
|
|
|
|
* @param {ve.ui.MWMediaResultWidget|null} item Selected item
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.onSearchSelect = function ( item ) {
|
2014-07-25 02:28:07 +00:00
|
|
|
var info;
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
info = item.imageinfo[0];
|
|
|
|
|
|
|
|
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
|
|
|
|
href: './' + item.title,
|
2014-08-07 17:02:52 +00:00
|
|
|
src: info.url,
|
2014-07-25 02:28:07 +00:00
|
|
|
resource: './' + item.title,
|
|
|
|
width: info.thumbwidth,
|
|
|
|
height: info.thumbheight,
|
|
|
|
mediaType: info.mediatype,
|
|
|
|
type: 'thumb',
|
|
|
|
align: 'default',
|
|
|
|
defaultSize: true
|
|
|
|
},
|
2014-12-10 19:40:22 +00:00
|
|
|
this.getFragment().getDocument().getDir(),
|
|
|
|
this.getFragment().getDocument().getLang()
|
2014-07-25 02:28:07 +00:00
|
|
|
);
|
|
|
|
this.attachImageModel();
|
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,
|
|
|
|
href: './' + item.title,
|
2014-08-07 17:02:52 +00:00
|
|
|
src: info.url,
|
2014-07-25 02:28:07 +00:00
|
|
|
resource: './' + item.title
|
|
|
|
},
|
|
|
|
{ width: info.width, height: info.height }
|
|
|
|
);
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 17:02:52 +00:00
|
|
|
this.checkChanged();
|
2014-06-19 15:44:05 +00:00
|
|
|
this.switchPanels( 'edit' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-20 05:11:04 +00:00
|
|
|
/**
|
2014-03-25 16:01:04 +00:00
|
|
|
* Handle image model alignment change
|
|
|
|
* @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-06-05 02:15:42 +00:00
|
|
|
var item;
|
2014-05-24 02:42:14 +00:00
|
|
|
alignment = alignment || 'none';
|
|
|
|
|
2014-11-12 19:09:52 +00:00
|
|
|
item = alignment !== 'none' ? this.positionSelect.getItemFromData( alignment ) : null;
|
2014-06-05 02:15:42 +00:00
|
|
|
|
2014-05-24 02:42:14 +00:00
|
|
|
// Select the item without triggering the 'choose' event
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect.selectItem( item );
|
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
|
|
|
|
* @param {string} alignment Image alignment
|
2014-02-24 21:56:24 +00:00
|
|
|
*/
|
2014-04-16 04:03:35 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onImageModelTypeChange = function ( type ) {
|
2014-11-12 19:09:52 +00:00
|
|
|
var item = type ? this.typeSelect.getItemFromData( type ) : null;
|
2014-03-25 16:01:04 +00:00
|
|
|
|
2014-11-12 19:09:52 +00:00
|
|
|
this.typeSelect.selectItem( item );
|
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 ) {
|
2014-03-25 16:01:04 +00:00
|
|
|
var position = item ? item.getData() : 'default';
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* @param {OO.ui.ButtonOptionWidget} item Selected item
|
|
|
|
*/
|
2014-11-12 19:09:52 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onTypeSelectChoose = function ( item ) {
|
2014-03-25 16:01:04 +00:00
|
|
|
var type = item ? item.getData() : 'default';
|
|
|
|
|
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
|
|
|
|
|
|
|
// If type is 'frame', disable the size input widget completely
|
|
|
|
this.sizeWidget.setDisabled( type === 'frame' );
|
2014-04-16 22:12:39 +00:00
|
|
|
};
|
|
|
|
|
2014-08-07 17:02:52 +00:00
|
|
|
/**
|
|
|
|
* Respond to change in alternate text
|
|
|
|
* @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 ) {
|
|
|
|
if ( this.captionSurface && this.captionSurface.getSurface() ) {
|
|
|
|
captionChanged = this.captionSurface.getSurface().getModel().hasBeenModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
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
|
|
|
|
this.isInsertion && this.imageModel ||
|
|
|
|
captionChanged ||
|
|
|
|
this.imageModel.hasBeenModified()
|
|
|
|
)
|
2014-08-07 17:02:52 +00:00
|
|
|
) {
|
|
|
|
this.actions.setAbilities( { insert: true, apply: true } );
|
|
|
|
} else {
|
|
|
|
this.actions.setAbilities( { insert: false, apply: false } );
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
/**
|
|
|
|
* Get the object of file repos to use for the media search
|
|
|
|
*
|
|
|
|
* @returns {jQuery.Promise}
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.getFileRepos = function () {
|
|
|
|
var defaultSource = [ {
|
2014-08-22 20:50:48 +00:00
|
|
|
url: mw.util.wikiScript( 'api' ),
|
|
|
|
local: true
|
2014-06-19 15:44:05 +00:00
|
|
|
} ];
|
|
|
|
|
|
|
|
if ( !this.fileRepoPromise ) {
|
|
|
|
this.fileRepoPromise = ve.init.target.constructor.static.apiRequest( {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'query',
|
|
|
|
meta: 'filerepoinfo'
|
2014-06-19 15:44:05 +00:00
|
|
|
} ).then(
|
|
|
|
function ( resp ) {
|
2014-08-16 06:38:00 +00:00
|
|
|
return resp.query && resp.query.repos || defaultSource;
|
2014-06-19 15:44:05 +00:00
|
|
|
},
|
|
|
|
function () {
|
|
|
|
return $.Deferred().resolve( defaultSource );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.fileRepoPromise;
|
|
|
|
};
|
|
|
|
|
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 () {
|
2014-07-02 19:23:25 +00:00
|
|
|
var pageTitle = mw.config.get( 'wgTitle' ),
|
|
|
|
namespace = mw.config.get( 'wgNamespaceNumber' ),
|
|
|
|
namespacesWithSubpages = mw.config.get( 'wgVisualEditor' ).namespacesWithSubpages;
|
|
|
|
|
|
|
|
// 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-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
|
|
|
|
this.imageModel = ve.dm.MWImageModel.static.newFromImageAttributes(
|
|
|
|
this.selectedNode.getAttributes(),
|
2014-12-10 19:40:22 +00:00
|
|
|
this.selectedNode.getDocument().getDir(),
|
|
|
|
this.selectedNode.getDocument().getLang()
|
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
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
this.resetCaption();
|
2014-05-31 04:47:08 +00:00
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.setAbilities( { insert: false, apply: false } );
|
2014-05-31 04:47:08 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.captionFieldset.$element.append( this.captionSurface.$element );
|
|
|
|
this.captionSurface.initialize();
|
2014-07-02 19:23:25 +00:00
|
|
|
|
2014-11-27 00:26:44 +00:00
|
|
|
this.switchPanels( this.selectedNode ? 'edit' : 'search' );
|
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
|
|
|
|
* @param {string} panel Panel name
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.switchPanels = function ( panel ) {
|
2014-12-16 21:14:01 +00:00
|
|
|
var dialog = this;
|
2014-06-19 15:44:05 +00:00
|
|
|
switch ( panel ) {
|
|
|
|
case 'edit':
|
2014-07-02 19:23:25 +00:00
|
|
|
// Set the edit panel
|
2014-06-19 15:44:05 +00:00
|
|
|
this.panels.setItem( this.bookletLayout );
|
2014-07-02 19:23:25 +00:00
|
|
|
// Focus the general settings page
|
|
|
|
this.bookletLayout.setPage( 'general' );
|
|
|
|
// Hide/show buttons
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setMode( this.selectedNode ? 'edit' : 'insert' );
|
2014-07-03 01:00:58 +00:00
|
|
|
// HACK: OO.ui.Dialog needs an API for this
|
2014-08-21 00:50:54 +00:00
|
|
|
this.$content.removeClass( 'oo-ui-dialog-content-footless' );
|
2014-07-29 19:34:09 +00:00
|
|
|
// Focus the caption surface
|
|
|
|
this.captionSurface.focus();
|
2014-07-02 19:23:25 +00:00
|
|
|
// Hide/show the panels
|
2014-06-19 15:44:05 +00:00
|
|
|
this.bookletLayout.$element.show();
|
|
|
|
this.mediaSearchPanel.$element.hide();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 'search':
|
2014-07-02 19:23:25 +00:00
|
|
|
// Show a spinner while we check for file repos.
|
|
|
|
// this will only be done once per session.
|
|
|
|
// The filerepo promise will be sent to the API
|
|
|
|
// only once per session so this will be resolved
|
|
|
|
// every time the search panel reloads
|
|
|
|
this.$spinner.show();
|
|
|
|
this.search.$element.hide();
|
|
|
|
|
|
|
|
// Get the repos from the API first
|
|
|
|
// The ajax request will only be done once per session
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.getFileRepos().done( function ( repos ) {
|
|
|
|
dialog.search.setSources( repos );
|
2014-07-02 19:23:25 +00:00
|
|
|
// Done, hide the spinner
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.$spinner.hide();
|
2014-07-02 19:23:25 +00:00
|
|
|
// Show the search and query the media sources
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.search.$element.show();
|
|
|
|
dialog.search.query.setValue( dialog.pageTitle );
|
|
|
|
dialog.search.queryMediaSources();
|
2014-07-02 19:23:25 +00:00
|
|
|
// Initialization
|
|
|
|
// This must be done only after there are proper
|
|
|
|
// sources defined
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.search.getQuery().focus().select();
|
|
|
|
dialog.search.getResults().selectItem();
|
|
|
|
dialog.search.getResults().highlightItem();
|
|
|
|
} );
|
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 );
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setMode( this.imageModel ? 'change' : 'select' );
|
|
|
|
|
2014-07-03 01:00:58 +00:00
|
|
|
// HACK: OO.ui.Dialog needs an API for this
|
2014-08-21 00:50:54 +00:00
|
|
|
this.$content.toggleClass( 'oo-ui-dialog-content-footless', !this.imageModel );
|
2014-07-03 01:00:58 +00:00
|
|
|
|
2014-07-02 19:23:25 +00:00
|
|
|
// Hide/show the panels
|
2014-06-19 15:44:05 +00:00
|
|
|
this.bookletLayout.$element.hide();
|
|
|
|
this.mediaSearchPanel.$element.show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
|
|
|
// Size widget
|
|
|
|
this.sizeErrorLabel.$element.hide();
|
|
|
|
this.sizeWidget.setScalable( this.imageModel.getScalable() );
|
2014-10-21 22:15:44 +00:00
|
|
|
this.sizeWidget.connect( this, {
|
|
|
|
changeSizeType: 'checkChanged',
|
|
|
|
change: 'checkChanged',
|
|
|
|
valid: 'checkChanged'
|
|
|
|
} );
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
// Initialize size
|
|
|
|
this.sizeWidget.setSizeType(
|
|
|
|
this.imageModel.isDefaultSize() ?
|
|
|
|
'default' :
|
|
|
|
'custom'
|
|
|
|
);
|
|
|
|
this.sizeWidget.setDisabled( this.imageModel.getType() === 'frame' );
|
|
|
|
|
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
|
|
|
|
this.altTextInput.setValue(
|
|
|
|
this.imageModel.getAltText()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Set initial alignment
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect.setDisabled(
|
2014-06-19 15:44:05 +00:00
|
|
|
!this.imageModel.isAligned()
|
|
|
|
);
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect.selectItem(
|
2014-06-19 15:44:05 +00:00
|
|
|
this.imageModel.isAligned() ?
|
2014-11-12 19:09:52 +00:00
|
|
|
this.positionSelect.getItemFromData(
|
2014-06-19 15:44:05 +00:00
|
|
|
this.imageModel.getAlignment()
|
|
|
|
) :
|
|
|
|
null
|
|
|
|
);
|
2014-12-09 20:58:08 +00:00
|
|
|
this.positionCheckbox.setSelected(
|
2014-06-19 15:44:05 +00:00
|
|
|
this.imageModel.isAligned()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Border flag
|
|
|
|
this.borderCheckbox.setDisabled(
|
|
|
|
!this.imageModel.isBorderable()
|
|
|
|
);
|
2014-12-09 20:58:08 +00:00
|
|
|
this.borderCheckbox.setSelected(
|
2014-06-19 15:44:05 +00:00
|
|
|
this.imageModel.isBorderable() && this.imageModel.hasBorder()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Type select
|
2014-11-12 19:09:52 +00:00
|
|
|
this.typeSelect.selectItem(
|
|
|
|
this.typeSelect.getItemFromData(
|
2014-06-19 15:44:05 +00:00
|
|
|
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 () {
|
|
|
|
var captionDocument,
|
2014-12-10 19:40:22 +00:00
|
|
|
doc = this.getFragment().getDocument();
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
if ( this.captionSurface ) {
|
|
|
|
// Reset the caption surface if it already exists
|
|
|
|
this.captionSurface.destroy();
|
|
|
|
this.captionSurface = null;
|
|
|
|
this.captionNode = null;
|
|
|
|
}
|
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.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
) {
|
|
|
|
this.captionNode = this.selectedNode.getCaptionNode();
|
|
|
|
if ( this.captionNode && this.captionNode.getLength() > 0 ) {
|
|
|
|
this.imageModel.setCaptionDocument(
|
|
|
|
this.selectedNode.getDocument().cloneFromRange( this.captionNode.getRange() )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-06-19 15:44:05 +00:00
|
|
|
|
|
|
|
if ( this.imageModel ) {
|
|
|
|
captionDocument = this.imageModel.getCaptionDocument();
|
|
|
|
} else {
|
|
|
|
captionDocument = new ve.dm.Document( [
|
2014-08-22 20:50:48 +00:00
|
|
|
{ type: 'paragraph', internal: { generated: 'wrapper' } },
|
|
|
|
{ type: '/paragraph' },
|
|
|
|
{ type: 'internalList' },
|
|
|
|
{ type: '/internalList' }
|
2014-12-10 19:40:22 +00:00
|
|
|
],
|
|
|
|
// The ve.dm.Document constructor expects
|
|
|
|
// ( data, htmlDocument, parentDocument, internalList, innerWhitespace, lang, dir )
|
|
|
|
// as parameters. We are only interested in setting up language, hence the
|
|
|
|
// multiple 'null' values.
|
|
|
|
null, null, null, null, doc.getLang(), doc.getDir() );
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.store = doc.getStore();
|
|
|
|
|
|
|
|
// Set up the caption surface
|
2014-10-15 23:56:44 +00:00
|
|
|
this.captionSurface = new ve.ui.MWSurfaceWidget(
|
2014-06-19 15:44:05 +00:00
|
|
|
captionDocument,
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
2014-11-24 17:43:16 +00:00
|
|
|
tools: ve.init.target.constructor.static.toolbarGroups,
|
|
|
|
excludeCommands: this.constructor.static.excludeCommands,
|
2014-11-24 11:27:25 +00:00
|
|
|
importRules: this.constructor.static.getImportRules()
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
|
|
|
);
|
2014-07-17 19:55:24 +00:00
|
|
|
|
|
|
|
// Events
|
2014-11-26 19:12:29 +00:00
|
|
|
|
|
|
|
this.captionSurface.getSurface().getModel().getDocument().connect( this, {
|
|
|
|
transact: this.checkChanged.bind( this )
|
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 () {
|
|
|
|
// Focus the caption surface
|
|
|
|
this.captionSurface.focus();
|
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 () {
|
|
|
|
// Cleanup
|
2014-06-19 15:44:05 +00:00
|
|
|
this.search.getQuery().setValue( '' );
|
|
|
|
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
|
|
|
}
|
2014-05-31 04:47:08 +00:00
|
|
|
this.captionSurface.destroy();
|
|
|
|
this.captionSurface = null;
|
|
|
|
this.captionNode = null;
|
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 ) {
|
|
|
|
if ( action === 'change' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.switchPanels( 'search' );
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
if ( action === 'back' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.switchPanels( 'edit' );
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
if ( action === 'apply' || action === 'insert' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
var surfaceModel = this.getFragment().getSurface();
|
|
|
|
|
|
|
|
// Update from the form
|
|
|
|
this.imageModel.setAltText( this.altTextInput.getValue() );
|
|
|
|
this.imageModel.setCaptionDocument(
|
|
|
|
this.captionSurface.getSurface().getModel().getDocument()
|
|
|
|
);
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
// TODO: Simplify this condition
|
|
|
|
if ( this.imageModel ) {
|
|
|
|
if (
|
|
|
|
// There was an initial node
|
|
|
|
this.selectedNode &&
|
|
|
|
// And we didn't change the image type block/inline or vise versa
|
|
|
|
this.selectedNode.type === this.imageModel.getImageNodeType() &&
|
|
|
|
// And we didn't change the image itself
|
|
|
|
this.selectedNode.getAttribute( 'src' ) ===
|
2014-07-17 19:55:24 +00:00
|
|
|
this.imageModel.getImageSource()
|
2014-07-14 21:32:49 +00:00
|
|
|
) {
|
|
|
|
// We only need to update the attributes of the current node
|
2014-07-17 19:55:24 +00:00
|
|
|
this.imageModel.updateImageNode( this.selectedNode, surfaceModel );
|
2014-07-14 21:32:49 +00:00
|
|
|
} else {
|
|
|
|
// Replacing an image or inserting a brand new one
|
|
|
|
|
|
|
|
// If there was a previous node, remove it first
|
|
|
|
if ( this.selectedNode ) {
|
|
|
|
// Remove the old image
|
|
|
|
this.fragment = this.getFragment().clone(
|
2014-10-08 19:55:38 +00:00
|
|
|
new ve.dm.LinearSelection( this.fragment.getDocument(), this.selectedNode.getOuterRange() )
|
2014-07-14 21:32:49 +00:00
|
|
|
);
|
|
|
|
this.fragment.removeContent();
|
|
|
|
}
|
|
|
|
// Insert the new image
|
|
|
|
this.fragment = this.imageModel.insertImageNode( this.getFragment() );
|
|
|
|
}
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
this.close( { action: action } );
|
2014-07-14 21:32:49 +00:00
|
|
|
}, this );
|
2014-06-19 15:44:05 +00:00
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
return ve.ui.MWMediaDialog.super.prototype.getActionProcess.call( this, action );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.windowFactory.register( ve.ui.MWMediaDialog );
|