2013-06-18 22:58:10 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWMediaEditDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
* Dialog for editing MediaWiki media objects.
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-07-03 01:30:10 +00:00
|
|
|
* @extends ve.ui.MWDialog
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Surface} surface
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaEditDialog = function VeUiMWMediaEditDialog( surface, config ) {
|
|
|
|
// Parent constructor
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.call( this, surface, config );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.captionNode = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.inheritClass( ve.ui.MWMediaEditDialog, ve.ui.MWDialog );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.titleMessage = 'visualeditor-dialog-media-title';
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.icon = 'picture';
|
|
|
|
|
2013-08-09 18:29:09 +00:00
|
|
|
ve.ui.MWMediaEditDialog.static.toolbarGroups = [
|
|
|
|
{
|
|
|
|
'include': [ 'history' ],
|
|
|
|
'promote': [
|
|
|
|
'history/undo',
|
|
|
|
'history/redo'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'include': [ 'textStyle', 'meta', 'utility/clear' ],
|
|
|
|
'promote': [
|
|
|
|
'textStyle/bold',
|
|
|
|
'textStyle/italic',
|
|
|
|
'meta/link'
|
|
|
|
],
|
|
|
|
'demote': [ 'utility/clear' ]
|
|
|
|
},
|
|
|
|
{ 'include': [ 'object' ], 'exclude': [ 'object/referenceList/mw' ] }
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.surfaceCommands = [
|
2013-08-09 18:29:09 +00:00
|
|
|
'history/undo',
|
|
|
|
'history/redo',
|
|
|
|
'textStyle/bold',
|
|
|
|
'textStyle/italic',
|
2013-08-21 23:52:47 +00:00
|
|
|
'meta/link/mw',
|
2013-08-09 18:29:09 +00:00
|
|
|
'utility/clear'
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-06-18 22:58:10 +00:00
|
|
|
ve.ui.MWMediaEditDialog.prototype.initialize = function () {
|
2013-06-21 02:47:10 +00:00
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Properties
|
2013-07-18 18:36:43 +00:00
|
|
|
this.editPanel = new ve.ui.PanelLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'padded': true,
|
|
|
|
'scrollable': true
|
|
|
|
} );
|
|
|
|
this.captionFieldset = new ve.ui.FieldsetLayout( {
|
2013-06-18 22:58:10 +00:00
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-content-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
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
|
|
|
this.applyButton = new ve.ui.ButtonWidget( {
|
2013-07-18 18:36:43 +00:00
|
|
|
'$$': this.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-action-apply' ),
|
|
|
|
'flags': ['primary']
|
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
|
|
|
|
this.applyButton.connect( this, { 'click': [ 'close', 'apply' ] } );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Initialization
|
2013-07-18 18:36:43 +00:00
|
|
|
this.editPanel.$.append( this.captionFieldset.$ );
|
|
|
|
this.$body.append( this.editPanel.$ );
|
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
|
|
|
this.$foot.append( this.applyButton.$ );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-06-18 22:58:10 +00:00
|
|
|
ve.ui.MWMediaEditDialog.prototype.onOpen = function () {
|
|
|
|
var data, doc = this.surface.getModel().getDocument();
|
|
|
|
|
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.onOpen.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2013-07-18 18:36:43 +00:00
|
|
|
// Properties
|
2013-06-18 22:58:10 +00:00
|
|
|
this.captionNode = this.surface.getView().getFocusedNode().getModel().getCaptionNode();
|
|
|
|
if ( this.captionNode && this.captionNode.getLength() > 0 ) {
|
|
|
|
data = doc.getData( this.captionNode.getRange(), true );
|
|
|
|
} else {
|
|
|
|
data = [
|
|
|
|
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2013-07-18 18:36:43 +00:00
|
|
|
this.captionSurface = new ve.ui.SurfaceWidget(
|
|
|
|
new ve.dm.ElementLinearData( doc.getStore(), data ),
|
|
|
|
{
|
|
|
|
'$$': this.frame.$$,
|
2013-08-09 18:29:09 +00:00
|
|
|
'tools': this.constructor.static.toolbarGroups,
|
2013-07-18 18:36:43 +00:00
|
|
|
'commands': this.constructor.static.surfaceCommands
|
|
|
|
}
|
2013-06-18 22:58:10 +00:00
|
|
|
);
|
|
|
|
|
2013-07-18 18:36:43 +00:00
|
|
|
// Initialization
|
|
|
|
this.captionFieldset.$.append( this.captionSurface.$ );
|
2013-06-18 22:58:10 +00:00
|
|
|
this.captionSurface.initialize();
|
|
|
|
};
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-06-18 22:58:10 +00:00
|
|
|
ve.ui.MWMediaEditDialog.prototype.onClose = function ( action ) {
|
|
|
|
var data, doc, surfaceModel = this.surface.getModel();
|
|
|
|
|
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.onClose.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
if ( action === 'apply' ) {
|
2013-07-18 18:36:43 +00:00
|
|
|
data = this.captionSurface.getContent();
|
2013-06-18 22:58:10 +00:00
|
|
|
doc = surfaceModel.getDocument();
|
|
|
|
if ( this.captionNode ) {
|
|
|
|
// Replace the contents of the caption
|
|
|
|
surfaceModel.getFragment( this.captionNode.getRange(), true ).insertContent( data );
|
|
|
|
} else {
|
|
|
|
// Insert a new caption at the beginning of the image node
|
|
|
|
surfaceModel.getFragment()
|
|
|
|
.adjustRange( 1 )
|
|
|
|
.collapseRangeToStart()
|
|
|
|
.insertContent(
|
|
|
|
[ { 'type': 'mwImageCaption' } ]
|
|
|
|
.concat( data )
|
|
|
|
.concat( [ { 'type': '/mwImageCaption' } ] )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
this.captionSurface.destroy();
|
2013-07-18 18:36:43 +00:00
|
|
|
this.captionSurface = null;
|
|
|
|
this.captionNode = null;
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.dialogFactory.register( 'mwMediaEdit', ve.ui.MWMediaEditDialog );
|