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-06-19 15:44:05 +00:00
|
|
|
/*global mw */
|
|
|
|
|
2013-06-18 22:58:10 +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
|
|
|
* Dialog for editing MediaWiki media objects.
|
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-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog = function VeUiMWMediaDialog( config ) {
|
2013-06-18 22:58:10 +00:00
|
|
|
// Parent constructor
|
2014-06-19 15:44:05 +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.mediaNode = null;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.defaultSize = 'large';
|
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-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.toolbarGroups = [
|
2013-12-12 19:04:15 +00:00
|
|
|
// History
|
2013-08-27 23:28:29 +00:00
|
|
|
{ 'include': [ 'undo', 'redo' ] },
|
2013-12-12 19:04:15 +00:00
|
|
|
// No formatting
|
|
|
|
/* {
|
|
|
|
'type': 'menu',
|
2014-01-13 22:46:15 +00:00
|
|
|
'indicator': 'down',
|
2014-03-15 00:01:44 +00:00
|
|
|
'title': OO.ui.deferMsg( 'visualeditor-toolbar-format-tooltip' ),
|
2013-12-12 19:04:15 +00:00
|
|
|
'include': [ { 'group': 'format' } ],
|
|
|
|
'promote': [ 'paragraph' ],
|
|
|
|
'demote': [ 'preformatted', 'heading1' ]
|
|
|
|
},*/
|
|
|
|
// Style
|
|
|
|
{
|
|
|
|
'type': 'list',
|
|
|
|
'icon': 'text-style',
|
2014-01-13 22:46:15 +00:00
|
|
|
'indicator': 'down',
|
2014-03-15 00:01:44 +00:00
|
|
|
'title': OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
2014-07-01 00:54:47 +00:00
|
|
|
'include': [ { 'group': 'textStyle' }, 'language', 'clear' ],
|
2013-12-12 19:04:15 +00:00
|
|
|
'promote': [ 'bold', 'italic' ],
|
2014-07-01 00:54:47 +00:00
|
|
|
'demote': [ 'strikethrough', 'code', 'underline', 'language', 'clear' ]
|
2013-12-12 19:04:15 +00:00
|
|
|
},
|
|
|
|
// Link
|
|
|
|
{ 'include': [ 'link' ] },
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
// Cite
|
|
|
|
{
|
|
|
|
'type': 'list',
|
2014-06-02 16:44:52 +00:00
|
|
|
'label': OO.ui.deferMsg( 'visualeditor-toolbar-cite-label' ),
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
'indicator': 'down',
|
2014-07-01 00:54:47 +00:00
|
|
|
'include': [ { 'group': 'cite' }, 'reference' ],
|
|
|
|
'demote': [ 'reference' ]
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
},
|
2014-03-25 00:13:59 +00:00
|
|
|
// No structure
|
|
|
|
/* {
|
2014-05-23 00:47:29 +00:00
|
|
|
'type': 'list',
|
|
|
|
'icon': 'bullet-list',
|
|
|
|
'indicator': 'down',
|
|
|
|
'include': [ { 'group': 'structure' } ],
|
|
|
|
'demote': [ 'outdent', 'indent' ]
|
2014-03-25 00:13:59 +00:00
|
|
|
},*/
|
2013-12-12 19:04:15 +00:00
|
|
|
// Insert
|
2013-09-05 00:32:50 +00:00
|
|
|
{
|
2014-02-12 23:04:28 +00:00
|
|
|
'label': OO.ui.deferMsg( 'visualeditor-toolbar-insert' ),
|
2014-01-13 22:46:15 +00:00
|
|
|
'indicator': 'down',
|
2013-09-05 00:32:50 +00:00
|
|
|
'include': '*',
|
2014-02-05 19:45:56 +00:00
|
|
|
'exclude': [
|
2014-03-15 00:01:44 +00:00
|
|
|
{ 'group': 'format' },
|
|
|
|
{ 'group': 'structure' },
|
2014-02-05 19:45:56 +00:00
|
|
|
'referenceList',
|
|
|
|
'gallery'
|
|
|
|
],
|
2014-06-19 15:44:05 +00:00
|
|
|
'promote': [ 'media', 'transclusion' ],
|
2014-07-01 00:54:47 +00:00
|
|
|
'demote': [ 'specialcharacter' ]
|
2013-09-05 00:32:50 +00:00
|
|
|
}
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.surfaceCommands = [
|
2013-12-12 19:04:15 +00:00
|
|
|
'undo',
|
|
|
|
'redo',
|
|
|
|
'bold',
|
|
|
|
'italic',
|
|
|
|
'link',
|
|
|
|
'clear',
|
|
|
|
'underline',
|
|
|
|
'subscript',
|
|
|
|
'superscript',
|
|
|
|
'pasteSpecial'
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
|
2014-05-23 09:57:58 +00:00
|
|
|
/**
|
|
|
|
* Get the paste rules for the surface widget in the dialog
|
|
|
|
*
|
|
|
|
* @see ve.dm.ElementLinearData#sanitize
|
|
|
|
* @return {Object} Paste rules
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.static.getPasteRules = function () {
|
2014-05-23 09:57:58 +00:00
|
|
|
return ve.extendObject(
|
|
|
|
ve.copy( ve.init.target.constructor.static.pasteRules ),
|
|
|
|
{
|
|
|
|
'all': {
|
|
|
|
'blacklist': OO.simpleArrayUnion(
|
|
|
|
ve.getProp( ve.init.target.constructor.static.pasteRules, 'all', 'blacklist' ) || [],
|
|
|
|
[
|
|
|
|
// 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
|
|
|
|
'conversions': {
|
|
|
|
'mwHeading': 'paragraph'
|
|
|
|
}
|
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 */
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.initialize = function () {
|
2014-02-27 17:39:19 +00:00
|
|
|
var altTextFieldset, positionFieldset, borderField, positionField;
|
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' );
|
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// Set up the booklet layout
|
|
|
|
this.bookletLayout = new OO.ui.BookletLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'outlined': true
|
|
|
|
} );
|
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
this.mediaSearchPanel = new OO.ui.PanelLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'scrollable': true
|
|
|
|
} );
|
|
|
|
|
2014-02-15 01:37:32 +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
|
|
|
|
this.search = new ve.ui.MWMediaSearchWidget( { '$': this.$ } );
|
|
|
|
|
|
|
|
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( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-06-18 22:58:10 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-content-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2013-12-28 10:29:35 +00:00
|
|
|
// Alt text
|
|
|
|
altTextFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-alttext-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.altTextInput = new OO.ui.TextInputWidget( {
|
|
|
|
'$': this.$
|
|
|
|
} );
|
|
|
|
|
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
|
2013-12-29 05:49:56 +00:00
|
|
|
this.positionInput = new OO.ui.ButtonSelectWidget( {
|
2013-12-29 03:49:06 +00:00
|
|
|
'$': this.$
|
|
|
|
} );
|
|
|
|
this.positionInput.addItems( [
|
2014-03-03 11:42:52 +00:00
|
|
|
new OO.ui.ButtonOptionWidget( 'left', {
|
|
|
|
'$': this.$,
|
|
|
|
'icon': 'align-float-left',
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-position-left' )
|
|
|
|
} ),
|
|
|
|
new OO.ui.ButtonOptionWidget( 'center', {
|
|
|
|
'$': this.$,
|
|
|
|
'icon': 'align-center',
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-position-center' )
|
|
|
|
} ),
|
|
|
|
new OO.ui.ButtonOptionWidget( 'right', {
|
|
|
|
'$': this.$,
|
|
|
|
'icon': 'align-float-right',
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-position-right' )
|
2014-05-15 16:12:43 +00:00
|
|
|
} )
|
2013-12-29 03:49:06 +00:00
|
|
|
], 0 );
|
2014-01-21 18:05:50 +00:00
|
|
|
|
|
|
|
this.positionCheckbox = new OO.ui.CheckboxInputWidget( {
|
|
|
|
'$': this.$
|
|
|
|
} );
|
|
|
|
positionField = new OO.ui.FieldLayout( this.positionCheckbox, {
|
|
|
|
'$': this.$,
|
|
|
|
'align': 'inline',
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-position-checkbox' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
positionFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-position-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
2013-12-29 03:49:06 +00:00
|
|
|
// Build position fieldset
|
2014-01-21 18:05:50 +00:00
|
|
|
positionFieldset.$element.append( [
|
|
|
|
positionField.$element,
|
|
|
|
this.positionInput.$element
|
|
|
|
] );
|
2013-12-29 03:49:06 +00:00
|
|
|
|
2013-12-29 05:49:56 +00:00
|
|
|
// Type
|
|
|
|
this.typeFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-type-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.typeInput = new OO.ui.ButtonSelectWidget( {
|
|
|
|
'$': this.$
|
|
|
|
} );
|
|
|
|
this.typeInput.addItems( [
|
|
|
|
// TODO: Inline images require a bit of further work, will be coming soon
|
|
|
|
new OO.ui.ButtonOptionWidget( 'thumb', {
|
|
|
|
'$': this.$,
|
2014-03-03 12:40:07 +00:00
|
|
|
'icon': 'image-thumbnail',
|
2013-12-29 05:49:56 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-type-thumb' )
|
|
|
|
} ),
|
|
|
|
new OO.ui.ButtonOptionWidget( 'frameless', {
|
|
|
|
'$': this.$,
|
2014-03-03 12:40:07 +00:00
|
|
|
'icon': 'image-frameless',
|
2013-12-29 05:49:56 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-type-frameless' )
|
|
|
|
} ),
|
|
|
|
new OO.ui.ButtonOptionWidget( 'frame', {
|
|
|
|
'$': this.$,
|
2014-03-03 12:40:07 +00:00
|
|
|
'icon': 'image-frame',
|
2013-12-29 05:49:56 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-type-frame' )
|
|
|
|
} ),
|
2014-02-27 17:39:19 +00:00
|
|
|
new OO.ui.ButtonOptionWidget( 'none', {
|
2013-12-29 05:49:56 +00:00
|
|
|
'$': this.$,
|
2014-03-03 12:40:07 +00:00
|
|
|
'icon': 'image-none',
|
2014-02-27 17:39:19 +00:00
|
|
|
'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( {
|
|
|
|
'$': this.$
|
|
|
|
} );
|
|
|
|
borderField = new OO.ui.FieldLayout( this.borderCheckbox, {
|
|
|
|
'$': this.$,
|
|
|
|
'align': 'inline',
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-type-border' )
|
|
|
|
} );
|
2013-12-29 05:49:56 +00:00
|
|
|
|
|
|
|
// Build type fieldset
|
2014-02-27 17:39:19 +00:00
|
|
|
this.typeFieldset.$element.append( [
|
|
|
|
this.typeInput.$element,
|
|
|
|
borderField.$element
|
|
|
|
] );
|
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( {
|
2013-12-21 22:37:54 +00:00
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-size-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
2014-01-22 20:13:59 +00:00
|
|
|
this.sizeErrorLabel = new OO.ui.LabelWidget( {
|
2013-12-21 22:37:54 +00:00
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-size-originalsize-error' )
|
|
|
|
} );
|
|
|
|
|
2014-04-10 00:26:48 +00:00
|
|
|
this.sizeWidget = new ve.ui.MediaSizeWidget( {}, {
|
2014-02-20 05:11:04 +00:00
|
|
|
'$': this.$
|
|
|
|
} );
|
|
|
|
|
2014-04-10 00:26:48 +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
|
2013-12-21 22:37:54 +00:00
|
|
|
] );
|
2014-04-10 00:26:48 +00:00
|
|
|
this.sizeFieldset.$element.append( [
|
|
|
|
this.$spinner,
|
|
|
|
this.$sizeWidgetElements
|
|
|
|
] );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
// Footer button
|
|
|
|
this.changeImageButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-change-image' )
|
|
|
|
} );
|
|
|
|
this.$foot.append( this.changeImageButton.$element );
|
|
|
|
|
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-01-21 18:05:50 +00:00
|
|
|
this.positionCheckbox.connect( this, { 'change': 'onPositionCheckboxChange' } );
|
2014-03-25 16:01:04 +00:00
|
|
|
this.borderCheckbox.connect( this, { 'change': 'onBorderCheckboxChange' } );
|
2014-06-05 02:15:42 +00:00
|
|
|
this.positionInput.connect( this, { 'choose': 'onPositionInputChoose' } );
|
|
|
|
this.typeInput.connect( this, { 'choose': 'onTypeInputChoose' } );
|
2014-06-19 15:44:05 +00:00
|
|
|
this.search.connect( this, { 'select': 'onSearchSelect' } );
|
|
|
|
this.changeImageButton.connect( this, { 'click': 'onChangeImageButtonClick' } );
|
|
|
|
|
|
|
|
// Panel classes
|
|
|
|
this.mediaSearchPanel.$element.addClass( 've-ui-mwMediaDialog-panel-search' );
|
|
|
|
this.bookletLayout.$element.addClass( 've-ui-mwMediaDialog-panel-settings' );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-06-19 15:44:05 +00:00
|
|
|
this.mediaSearchPanel.$element.append( this.search.$element );
|
2013-12-28 10:29:35 +00:00
|
|
|
this.generalSettingsPage.$element.append( [
|
|
|
|
this.captionFieldset.$element,
|
|
|
|
altTextFieldset.$element
|
|
|
|
] );
|
2013-12-29 03:49:06 +00:00
|
|
|
|
|
|
|
this.advancedSettingsPage.$element.append( [
|
|
|
|
positionFieldset.$element,
|
2013-12-29 05:49:56 +00:00
|
|
|
this.typeFieldset.$element,
|
2013-12-29 03:49:06 +00:00
|
|
|
this.sizeFieldset.$element
|
|
|
|
] );
|
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 ) {
|
|
|
|
var newNode, attrs, info,
|
|
|
|
nodeType = 'mwBlockImage';
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
info = item.imageinfo[0];
|
|
|
|
attrs = {
|
|
|
|
// Per https://www.mediawiki.org/w/?diff=931265&oldid=prev
|
|
|
|
'href': './' + item.title,
|
|
|
|
'src': info.thumburl,
|
|
|
|
'width': info.width,
|
|
|
|
'height': info.height,
|
|
|
|
'resource': './' + item.title,
|
|
|
|
'mediaType': info.mediatype
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( !this.imageModel ) {
|
|
|
|
// Image model doesn't exist yet, which means we are creating
|
|
|
|
// a brand new node to insert
|
|
|
|
attrs.type = 'thumb';
|
|
|
|
attrs.align = 'default';
|
|
|
|
attrs.defaultSize = true;
|
|
|
|
} else {
|
|
|
|
// Image model already exists, so we just need to create a new
|
|
|
|
// image based on the parameters that already exist
|
|
|
|
attrs.type = this.imageModel.getType();
|
|
|
|
attrs.align = this.imageModel.getAlignment();
|
|
|
|
attrs.defaultSize = this.imageModel.isDefaultSize();
|
|
|
|
if ( this.imageModel.getAltText() ) {
|
|
|
|
attrs.alt = this.imageModel.getAltText();
|
|
|
|
}
|
|
|
|
nodeType = this.imageModel.getImageNodeType();
|
|
|
|
}
|
|
|
|
|
|
|
|
newNode = ve.dm.MWImageModel.static.createImageNode( attrs, nodeType );
|
|
|
|
this.setImageModel( newNode );
|
|
|
|
this.switchPanels( 'edit' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to change image button click
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.onChangeImageButtonClick = function () {
|
|
|
|
this.switchPanels( 'search' );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
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-06-05 02:15:42 +00:00
|
|
|
item = alignment !== 'none' ? this.positionInput.getItemFromData( alignment ) : null;
|
|
|
|
|
2014-05-24 02:42:14 +00:00
|
|
|
// Select the item without triggering the 'choose' event
|
2014-03-25 16:01:04 +00:00
|
|
|
this.positionInput.selectItem( item );
|
2014-05-24 02:42:14 +00:00
|
|
|
|
2014-06-05 02:15:42 +00:00
|
|
|
this.positionCheckbox.setValue( alignment !== 'none' );
|
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-05-27 19:47:14 +00:00
|
|
|
var item = type ? this.typeInput.getItemFromData( type ) : null;
|
2014-03-25 16:01:04 +00:00
|
|
|
|
|
|
|
this.typeInput.selectItem( item );
|
|
|
|
|
|
|
|
this.borderCheckbox.setDisabled(
|
|
|
|
!this.imageModel.isBorderable()
|
|
|
|
);
|
2014-03-05 19:31:45 +00:00
|
|
|
|
2014-03-25 16:01:04 +00:00
|
|
|
this.borderCheckbox.setValue(
|
|
|
|
this.imageModel.isBorderable() && this.imageModel.hasBorder()
|
|
|
|
);
|
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.
|
|
|
|
*
|
|
|
|
* @param {boolean} checked Checkbox status
|
2014-01-21 18:05:50 +00:00
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onPositionCheckboxChange = function ( checked ) {
|
2014-06-05 02:15:42 +00:00
|
|
|
var newPositionValue,
|
|
|
|
currentModelAlignment = this.imageModel.getAlignment();
|
|
|
|
|
2014-06-10 19:18:36 +00:00
|
|
|
this.positionInput.setDisabled( !checked );
|
|
|
|
// 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 (
|
|
|
|
( currentModelAlignment === 'none' && checked ) ||
|
|
|
|
( currentModelAlignment !== 'none' && !checked )
|
|
|
|
) {
|
|
|
|
if ( checked ) {
|
|
|
|
// 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.
|
|
|
|
*
|
|
|
|
* @param {boolean} checked Checkbox status
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onBorderCheckboxChange = function ( checked ) {
|
2014-06-05 02:15:42 +00:00
|
|
|
// Only update if the value is different than the model
|
|
|
|
if ( this.imageModel.hasBorder() !== checked ) {
|
|
|
|
// Update the image model
|
|
|
|
this.imageModel.toggleBorder( checked );
|
|
|
|
}
|
2014-03-25 16:01:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle change event on the positionInput element.
|
|
|
|
*
|
|
|
|
* @param {OO.ui.ButtonOptionWidget} item Selected item
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onPositionInputChoose = 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-03-25 16:01:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle change event on the typeInput element.
|
|
|
|
*
|
|
|
|
* @param {OO.ui.ButtonOptionWidget} item Selected item
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.onTypeInputChoose = 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-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-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 = [ {
|
|
|
|
'url': mw.util.wikiScript( 'api' ),
|
|
|
|
'local': true
|
|
|
|
} ];
|
|
|
|
|
|
|
|
if ( !this.fileRepoPromise ) {
|
|
|
|
this.fileRepoPromise = ve.init.target.constructor.static.apiRequest( {
|
|
|
|
'action': 'query',
|
|
|
|
'meta': 'filerepoinfo'
|
|
|
|
} ).then(
|
|
|
|
function ( resp ) {
|
|
|
|
return resp.query.repos || defaultSource;
|
|
|
|
},
|
|
|
|
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-06-19 15:44:05 +00:00
|
|
|
// Show a spinner while we check for file repos.
|
|
|
|
// this will only be done once per session.
|
|
|
|
//
|
|
|
|
// This is in .setup rather than .initialize so that
|
|
|
|
// the user has visual indication (spinner) during the
|
|
|
|
// ajax request
|
|
|
|
this.$spinner.show();
|
|
|
|
this.search.$element.hide();
|
|
|
|
|
|
|
|
// Get the repos from the API first
|
|
|
|
// The ajax request will only be done once per session
|
|
|
|
this.getFileRepos().done( ve.bind( function ( repos ) {
|
|
|
|
this.search.setSources( repos );
|
|
|
|
// Done, hide the spinner
|
|
|
|
this.$spinner.hide();
|
|
|
|
// Show the search and query the media sources
|
|
|
|
this.search.$element.show();
|
|
|
|
this.search.queryMediaSources();
|
|
|
|
// Initialization
|
|
|
|
// This must be done only after there are proper
|
|
|
|
// sources defined
|
|
|
|
this.search.getQuery().focus().select();
|
|
|
|
this.search.getResults().selectItem();
|
|
|
|
this.search.getResults().highlightItem();
|
|
|
|
}, this ) );
|
2014-05-31 04:47:08 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-06-19 15:44:05 +00:00
|
|
|
this.mediaNode = this.getSelectedNode();
|
|
|
|
this.setImageModel( this.mediaNode );
|
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-06-19 15:44:05 +00:00
|
|
|
this.switchPanels( this.mediaNode ? 'edit' : 'search' );
|
2014-05-31 04:47:08 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.captionFieldset.$element.append( this.captionSurface.$element );
|
|
|
|
this.captionSurface.initialize();
|
|
|
|
}, 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 ) {
|
|
|
|
switch ( panel ) {
|
|
|
|
case 'edit':
|
|
|
|
this.panels.setItem( this.bookletLayout );
|
|
|
|
this.changeImageButton.setDisabled( false );
|
|
|
|
this.bookletLayout.$element.show();
|
|
|
|
this.mediaSearchPanel.$element.hide();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 'search':
|
|
|
|
this.panels.setItem( this.mediaSearchPanel );
|
|
|
|
this.changeImageButton.setDisabled( true );
|
|
|
|
this.bookletLayout.$element.hide();
|
|
|
|
this.mediaSearchPanel.$element.show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the image model
|
|
|
|
* @param {ve.dm.MWImageNode} node Image node, if it doesn't come from the selected node
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.setImageModel = function ( node ) {
|
|
|
|
var dir;
|
|
|
|
|
|
|
|
if ( !node ) {
|
|
|
|
this.applyButton.setDisabled( true );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.imageModel ) {
|
|
|
|
this.imageModel.disconnect( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = node.getDocument() ?
|
|
|
|
node.getDocument().getDir() :
|
|
|
|
this.getFragment().getSurface().getDocument().getDir();
|
|
|
|
|
|
|
|
this.imageModel = ve.dm.MWImageModel.static.newFromImageNode( node, dir );
|
|
|
|
this.applyButton.setDisabled( false );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.imageModel.connect( this, {
|
|
|
|
'alignmentChange': 'onImageModelAlignmentChange',
|
|
|
|
'typeChange': 'onImageModelTypeChange'
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Set up
|
|
|
|
|
|
|
|
// Size widget
|
|
|
|
this.sizeErrorLabel.$element.hide();
|
|
|
|
this.sizeWidget.setScalable( this.imageModel.getScalable() );
|
|
|
|
|
|
|
|
// Initialize size
|
|
|
|
this.sizeWidget.setSizeType(
|
|
|
|
this.imageModel.isDefaultSize() ?
|
|
|
|
'default' :
|
|
|
|
'custom'
|
|
|
|
);
|
|
|
|
|
|
|
|
this.sizeWidget.setDisabled( this.imageModel.getType() === 'frame' );
|
|
|
|
|
|
|
|
// Set initial alt text
|
|
|
|
this.altTextInput.setValue(
|
|
|
|
this.imageModel.getAltText()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Set initial alignment
|
|
|
|
this.positionInput.setDisabled(
|
|
|
|
!this.imageModel.isAligned()
|
|
|
|
);
|
|
|
|
this.positionInput.selectItem(
|
|
|
|
this.imageModel.isAligned() ?
|
|
|
|
this.positionInput.getItemFromData(
|
|
|
|
this.imageModel.getAlignment()
|
|
|
|
) :
|
|
|
|
null
|
|
|
|
);
|
|
|
|
this.positionCheckbox.setValue(
|
|
|
|
this.imageModel.isAligned()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Border flag
|
|
|
|
this.borderCheckbox.setDisabled(
|
|
|
|
!this.imageModel.isBorderable()
|
|
|
|
);
|
|
|
|
this.borderCheckbox.setValue(
|
|
|
|
this.imageModel.isBorderable() && this.imageModel.hasBorder()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Type select
|
|
|
|
this.typeInput.selectItem(
|
|
|
|
this.typeInput.getItemFromData(
|
|
|
|
this.imageModel.getType() || 'none'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the caption surface
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaDialog.prototype.resetCaption = function () {
|
|
|
|
var captionDocument,
|
|
|
|
doc = this.getFragment().getSurface().getDocument();
|
|
|
|
|
|
|
|
if ( this.captionSurface ) {
|
|
|
|
// Reset the caption surface if it already exists
|
|
|
|
this.captionSurface.destroy();
|
|
|
|
this.captionSurface = null;
|
|
|
|
this.captionNode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.imageModel ) {
|
|
|
|
captionDocument = this.imageModel.getCaptionDocument();
|
|
|
|
} else {
|
|
|
|
captionDocument = new ve.dm.Document( [
|
|
|
|
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': 'internalList' },
|
|
|
|
{ 'type': '/internalList' }
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.store = doc.getStore();
|
|
|
|
|
|
|
|
// Set up the caption surface
|
|
|
|
this.captionSurface = new ve.ui.SurfaceWidget(
|
|
|
|
captionDocument,
|
|
|
|
{
|
|
|
|
'$': this.$,
|
|
|
|
'tools': this.constructor.static.toolbarGroups,
|
|
|
|
'commands': this.constructor.static.surfaceCommands,
|
|
|
|
'pasteRules': this.constructor.static.getPasteRules()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
this.captionSurface.getSurface().getModel().connect( this, {
|
|
|
|
'documentUpdate': function () {
|
|
|
|
this.wikitextWarning = ve.init.mw.ViewPageTarget.static.checkForWikitextWarning(
|
|
|
|
this.captionSurface.getSurface(),
|
|
|
|
this.wikitextWarning
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
}, 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-06-10 21:19:03 +00:00
|
|
|
if ( this.wikitextWarning ) {
|
|
|
|
this.wikitextWarning.close();
|
|
|
|
}
|
2014-05-31 04:47:08 +00:00
|
|
|
this.captionSurface.destroy();
|
|
|
|
this.captionSurface = null;
|
|
|
|
this.captionNode = null;
|
|
|
|
// Reset the considerations for the scalable
|
|
|
|
// in the image node
|
2014-06-19 15:44:05 +00:00
|
|
|
if ( this.mediaNode ) {
|
|
|
|
this.mediaNode.syncScalableToType();
|
|
|
|
}
|
|
|
|
this.imageModel = null;
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2014-04-24 00:22:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-06-19 15:44:05 +00:00
|
|
|
ve.ui.MWMediaDialog.prototype.applyChanges = function () {
|
2014-03-25 16:01:04 +00:00
|
|
|
var surfaceModel = this.getFragment().getSurface();
|
|
|
|
|
|
|
|
// Update from the form
|
|
|
|
this.imageModel.setAltText(
|
|
|
|
this.altTextInput.getValue()
|
2014-04-24 00:22:45 +00:00
|
|
|
);
|
2014-05-21 18:41:33 +00:00
|
|
|
|
2014-03-25 16:01:04 +00:00
|
|
|
this.imageModel.setCaptionDocument(
|
|
|
|
this.captionSurface.getSurface().getModel().getDocument()
|
2014-04-24 00:22:45 +00:00
|
|
|
);
|
2014-02-20 05:11:04 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
// TODO: Simplify this condition
|
|
|
|
if ( this.imageModel ) {
|
|
|
|
if (
|
|
|
|
// There was an initial node
|
|
|
|
this.mediaNode &&
|
|
|
|
// And we didn't change the image type block/inline or vise versa
|
|
|
|
this.mediaNode.type === this.imageModel.getImageNodeType() &&
|
|
|
|
// And we didn't change the image itself
|
|
|
|
this.mediaNode.getAttribute( 'src' ) === this.imageModel.getMediaNode().getAttribute( 'src' )
|
|
|
|
) {
|
|
|
|
// We only need to update the attributes of the current node
|
|
|
|
this.imageModel.updateImageNode( surfaceModel );
|
|
|
|
} else {
|
|
|
|
// Replacing an image or inserting a brand new one
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2014-06-19 15:44:05 +00:00
|
|
|
// If there was a previous node, remove it first
|
|
|
|
if ( this.mediaNode ) {
|
|
|
|
// Remove the old image
|
|
|
|
this.fragment = this.getFragment().clone( this.mediaNode.getOuterRange() );
|
|
|
|
this.fragment.removeContent();
|
|
|
|
}
|
|
|
|
// Insert the new image
|
|
|
|
this.fragment = this.imageModel.insertImageNode( this.getFragment() );
|
|
|
|
}
|
|
|
|
}
|
2013-11-05 00:29:50 +00:00
|
|
|
// Parent method
|
2014-06-19 15:44:05 +00:00
|
|
|
return ve.ui.MWMediaDialog.super.prototype.applyChanges.call( 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 );
|