2016-03-08 21:14:12 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWGalleryDialog class.
|
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
2016-03-08 21:14:12 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog for editing MediaWiki galleries.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.MWExtensionDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog = function VeUiMWGalleryDialog() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWGalleryDialog.super.apply( this, arguments );
|
|
|
|
|
|
|
|
this.$element.addClass( 've-ui-mwGalleryDialog' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWGalleryDialog, ve.ui.MWExtensionDialog );
|
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
|
|
|
ve.ui.MWGalleryDialog.static.name = 'gallery';
|
|
|
|
|
|
|
|
ve.ui.MWGalleryDialog.static.size = 'large';
|
|
|
|
|
|
|
|
ve.ui.MWGalleryDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-mwgallerydialog-title' );
|
|
|
|
|
|
|
|
ve.ui.MWGalleryDialog.static.modelClasses = [ ve.dm.MWGalleryNode ];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.initialize = function () {
|
2017-05-10 18:46:49 +00:00
|
|
|
var imagesTabPanel, optionsTabPanel, menuLayout,
|
2016-11-30 21:48:37 +00:00
|
|
|
innerMenuLayout, innerMenuPanel, innerContentPanel,
|
2016-03-08 21:14:12 +00:00
|
|
|
modeField, captionField, widthsField, heightsField,
|
|
|
|
perrowField, showFilenameField, classesField, stylesField;
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWGalleryDialog.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// States
|
|
|
|
this.highlightedItem = null;
|
|
|
|
this.searchPanelVisible = false;
|
2016-11-19 15:51:21 +00:00
|
|
|
this.selectedFilenames = {};
|
|
|
|
this.initialImageData = [];
|
2016-03-08 21:14:12 +00:00
|
|
|
|
2016-08-04 23:28:53 +00:00
|
|
|
// Default settings
|
|
|
|
this.defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions;
|
|
|
|
|
2017-05-10 18:46:49 +00:00
|
|
|
// Images and options tab panels
|
2016-10-12 05:07:37 +00:00
|
|
|
this.indexLayout = new OO.ui.IndexLayout( {
|
2016-03-08 21:14:12 +00:00
|
|
|
scrollable: false,
|
|
|
|
expanded: true
|
|
|
|
} );
|
2017-05-10 18:46:49 +00:00
|
|
|
imagesTabPanel = new OO.ui.TabPanelLayout( 'images', {
|
2016-03-08 21:14:12 +00:00
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-card-images' ),
|
|
|
|
expandable: false,
|
|
|
|
scrollable: false,
|
|
|
|
padded: true
|
|
|
|
} );
|
2017-05-10 18:46:49 +00:00
|
|
|
optionsTabPanel = new OO.ui.TabPanelLayout( 'options', {
|
2016-03-08 21:14:12 +00:00
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-card-options' ),
|
|
|
|
expandable: false,
|
|
|
|
scrollable: false,
|
|
|
|
padded: true
|
|
|
|
} );
|
|
|
|
|
2017-05-10 18:46:49 +00:00
|
|
|
// Images tab panel
|
2016-03-08 21:14:12 +00:00
|
|
|
|
|
|
|
// General layout
|
2016-11-30 21:48:37 +00:00
|
|
|
menuLayout = new OO.ui.MenuLayout( {
|
|
|
|
classes: [ 've-ui-mwGalleryDialog-menuLayout' ]
|
|
|
|
} );
|
|
|
|
innerMenuLayout = new OO.ui.MenuLayout( {
|
|
|
|
menuPosition: 'bottom',
|
|
|
|
classes: [ 've-ui-mwGalleryDialog-innerMenuLayout' ]
|
|
|
|
} );
|
|
|
|
innerMenuPanel = new OO.ui.PanelLayout( {
|
2016-03-08 21:14:12 +00:00
|
|
|
padded: true,
|
|
|
|
expanded: true,
|
|
|
|
scrollable: true
|
|
|
|
} );
|
2016-11-30 21:48:37 +00:00
|
|
|
innerContentPanel = new OO.ui.PanelLayout( {
|
|
|
|
padded: true,
|
|
|
|
expanded: true
|
|
|
|
} );
|
2016-03-08 21:14:12 +00:00
|
|
|
this.editPanel = new OO.ui.PanelLayout( {
|
|
|
|
padded: true,
|
|
|
|
expanded: true,
|
|
|
|
scrollable: true
|
|
|
|
} );
|
|
|
|
this.searchPanel = new OO.ui.PanelLayout( {
|
|
|
|
padded: true,
|
|
|
|
expanded: true,
|
|
|
|
scrollable: true
|
|
|
|
} ).toggle( false );
|
|
|
|
|
|
|
|
// Menu
|
|
|
|
this.$emptyGalleryMessage = $( '<div>' )
|
|
|
|
.addClass( 'oo-ui-element-hidden' )
|
|
|
|
.text( ve.msg( 'visualeditor-mwgallerydialog-empty-gallery-message' ) );
|
|
|
|
this.galleryGroup = new ve.ui.MWGalleryGroupWidget();
|
|
|
|
this.showSearchPanelButton = new OO.ui.ButtonWidget( {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-search-button-label' ),
|
|
|
|
flags: [ 'progressive' ],
|
|
|
|
classes: [ 've-ui-mwGalleryDialog-show-search-panel-button' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Edit panel
|
2017-06-06 14:46:31 +00:00
|
|
|
this.filenameFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-content-filename' ),
|
|
|
|
icon: 'image'
|
|
|
|
} );
|
2016-03-08 21:14:12 +00:00
|
|
|
this.$highlightedImage = $( '<div>' )
|
|
|
|
.addClass( 've-ui-mwGalleryDialog-highlighted-image' );
|
|
|
|
// TODO: make into a ve.ui.MWTargetWidget once Parsoid handles galleries
|
|
|
|
this.highlightedCaptionInput = new OO.ui.TextInputWidget( {
|
2016-11-24 00:09:49 +00:00
|
|
|
placeholder: ve.msg( 'visualeditor-mwgallerydialog-image-caption-placeholder' ),
|
2016-07-06 16:24:12 +00:00
|
|
|
multiline: true,
|
|
|
|
autosize: true
|
2016-03-08 21:14:12 +00:00
|
|
|
} );
|
2017-06-06 14:46:31 +00:00
|
|
|
this.highlightedCaptionFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-content-section' ),
|
|
|
|
icon: 'parameter',
|
|
|
|
classes: [ 've-ui-mwGalleryDialog-caption-fieldset' ]
|
|
|
|
} );
|
|
|
|
this.highlightedCaptionFieldset.$element.append( this.highlightedCaptionInput.$element );
|
2016-03-08 21:14:12 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-remove-button-label' ),
|
|
|
|
flags: [ 'destructive' ],
|
|
|
|
classes: [ 've-ui-mwGalleryDialog-remove-button' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Search panel
|
2016-12-03 16:31:23 +00:00
|
|
|
this.searchWidget = new mw.widgets.MediaSearchWidget( {
|
|
|
|
rowHeight: 150
|
|
|
|
} );
|
2016-03-08 21:14:12 +00:00
|
|
|
|
2017-05-10 18:46:49 +00:00
|
|
|
// Options tab panel
|
2016-03-08 21:14:12 +00:00
|
|
|
|
|
|
|
// Input widgets
|
|
|
|
this.modeDropdown = new OO.ui.DropdownWidget( {
|
|
|
|
menu: {
|
|
|
|
items: [
|
2017-03-09 15:16:21 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2016-03-08 21:14:12 +00:00
|
|
|
data: 'traditional',
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-mode-dropdown-label-traditional' )
|
|
|
|
} ),
|
2017-03-09 15:16:21 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2016-03-08 21:14:12 +00:00
|
|
|
data: 'nolines',
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-mode-dropdown-label-nolines' )
|
|
|
|
} ),
|
2017-03-09 15:16:21 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2016-03-08 21:14:12 +00:00
|
|
|
data: 'packed',
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-mode-dropdown-label-packed' )
|
|
|
|
} ),
|
2017-03-09 15:16:21 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2016-03-08 21:14:12 +00:00
|
|
|
data: 'packed-overlay',
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-mode-dropdown-label-packed-overlay' )
|
|
|
|
} ),
|
2017-03-09 15:16:21 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2016-03-08 21:14:12 +00:00
|
|
|
data: 'packed-hover',
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-mode-dropdown-label-packed-hover' )
|
2016-07-07 17:45:44 +00:00
|
|
|
} ),
|
2017-03-09 15:16:21 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
2016-07-07 17:45:44 +00:00
|
|
|
data: 'slideshow',
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-mode-dropdown-label-slideshow' )
|
2016-03-08 21:14:12 +00:00
|
|
|
} )
|
|
|
|
]
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
this.captionInput = new OO.ui.TextInputWidget( {
|
|
|
|
placeholder: ve.msg( 'visualeditor-mwgallerydialog-caption-input-placeholder' )
|
|
|
|
} );
|
|
|
|
this.widthsInput = new OO.ui.NumberInputWidget( {
|
|
|
|
min: 0,
|
2016-08-04 23:28:53 +00:00
|
|
|
showButtons: false,
|
|
|
|
input: {
|
|
|
|
placeholder: ve.msg( 'visualeditor-mwgallerydialog-widths-input-placeholder', this.defaults.imageWidth )
|
|
|
|
}
|
2016-03-08 21:14:12 +00:00
|
|
|
} );
|
|
|
|
this.heightsInput = new OO.ui.NumberInputWidget( {
|
|
|
|
min: 0,
|
2016-08-04 23:28:53 +00:00
|
|
|
showButtons: false,
|
|
|
|
input: {
|
|
|
|
placeholder: ve.msg( 'visualeditor-mwgallerydialog-heights-input-placeholder', this.defaults.imageHeight )
|
|
|
|
}
|
2016-03-08 21:14:12 +00:00
|
|
|
} );
|
|
|
|
this.perrowInput = new OO.ui.NumberInputWidget( {
|
|
|
|
min: 0,
|
|
|
|
showButtons: false
|
|
|
|
} );
|
|
|
|
this.showFilenameCheckbox = new OO.ui.CheckboxInputWidget( {
|
|
|
|
value: 'yes'
|
|
|
|
} );
|
|
|
|
this.classesInput = new OO.ui.TextInputWidget( {
|
|
|
|
placeholder: ve.msg( 'visualeditor-mwgallerydialog-classes-input-placeholder' )
|
|
|
|
} );
|
|
|
|
this.stylesInput = new OO.ui.TextInputWidget( {
|
|
|
|
placeholder: ve.msg( 'visualeditor-mwgallerydialog-styles-input-placeholder' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Field layouts
|
|
|
|
modeField = new OO.ui.FieldLayout( this.modeDropdown, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-mode-field-label' )
|
|
|
|
} );
|
|
|
|
captionField = new OO.ui.FieldLayout( this.captionInput, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-caption-field-label' )
|
|
|
|
} );
|
|
|
|
widthsField = new OO.ui.FieldLayout( this.widthsInput, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-widths-field-label' )
|
|
|
|
} );
|
|
|
|
heightsField = new OO.ui.FieldLayout( this.heightsInput, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-heights-field-label' )
|
|
|
|
} );
|
|
|
|
perrowField = new OO.ui.FieldLayout( this.perrowInput, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-perrow-field-label' )
|
|
|
|
} );
|
|
|
|
showFilenameField = new OO.ui.FieldLayout( this.showFilenameCheckbox, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-show-filename-field-label' )
|
|
|
|
} );
|
|
|
|
classesField = new OO.ui.FieldLayout( this.classesInput, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-classes-field-label' )
|
|
|
|
} );
|
|
|
|
stylesField = new OO.ui.FieldLayout( this.stylesInput, {
|
|
|
|
label: ve.msg( 'visualeditor-mwgallerydialog-styles-field-label' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Append everything
|
2016-11-30 21:48:37 +00:00
|
|
|
innerMenuLayout.$menu.append(
|
|
|
|
innerContentPanel.$element.append(
|
2016-03-08 21:14:12 +00:00
|
|
|
this.showSearchPanelButton.$element
|
|
|
|
)
|
|
|
|
);
|
2016-11-30 21:48:37 +00:00
|
|
|
innerMenuLayout.$content.append(
|
|
|
|
innerMenuPanel.$element.append(
|
|
|
|
this.$emptyGalleryMessage,
|
|
|
|
this.galleryGroup.$element
|
|
|
|
)
|
|
|
|
);
|
|
|
|
menuLayout.$menu.append(
|
|
|
|
innerMenuLayout.$element
|
|
|
|
);
|
2016-03-08 21:14:12 +00:00
|
|
|
menuLayout.$content.append(
|
|
|
|
this.editPanel.$element.append(
|
|
|
|
this.$highlightedImage,
|
2017-06-06 14:46:31 +00:00
|
|
|
this.filenameFieldset.$element,
|
|
|
|
this.highlightedCaptionFieldset.$element,
|
2016-03-08 21:14:12 +00:00
|
|
|
this.removeButton.$element
|
|
|
|
),
|
|
|
|
this.searchPanel.$element.append(
|
|
|
|
this.searchWidget.$element
|
|
|
|
)
|
|
|
|
);
|
2017-05-10 18:46:49 +00:00
|
|
|
imagesTabPanel.$element.append(
|
2016-03-08 21:14:12 +00:00
|
|
|
menuLayout.$element
|
|
|
|
);
|
2017-05-10 18:46:49 +00:00
|
|
|
optionsTabPanel.$element.append(
|
2016-03-08 21:14:12 +00:00
|
|
|
modeField.$element,
|
|
|
|
captionField.$element,
|
|
|
|
widthsField.$element,
|
|
|
|
heightsField.$element,
|
|
|
|
perrowField.$element,
|
|
|
|
showFilenameField.$element,
|
|
|
|
classesField.$element,
|
|
|
|
stylesField.$element
|
|
|
|
);
|
2017-05-10 18:46:49 +00:00
|
|
|
this.indexLayout.addTabPanels( [
|
|
|
|
imagesTabPanel,
|
|
|
|
optionsTabPanel
|
2016-03-08 21:14:12 +00:00
|
|
|
] );
|
2016-10-12 05:07:37 +00:00
|
|
|
this.$body.append( this.indexLayout.$element );
|
2016-03-08 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWGalleryDialog.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
2016-09-30 16:07:10 +00:00
|
|
|
var title, titleText, imageTitles, mode,
|
2016-03-08 21:14:12 +00:00
|
|
|
caption, widths, heights, perrow,
|
|
|
|
showFilename, classes, styles,
|
2016-11-29 16:19:06 +00:00
|
|
|
namespaceIds = mw.config.get( 'wgNamespaceIds' ),
|
2016-03-08 21:14:12 +00:00
|
|
|
dialog = this,
|
|
|
|
attributes = this.selectedNode && this.selectedNode.getAttribute( 'mw' ).attrs;
|
|
|
|
|
2017-05-10 18:46:49 +00:00
|
|
|
// Images tab panel
|
2016-03-08 21:14:12 +00:00
|
|
|
// If editing an existing gallery, populate with the images...
|
|
|
|
if ( this.selectedNode ) {
|
|
|
|
imageTitles = [];
|
|
|
|
// Get image and caption data
|
|
|
|
// TODO: Can be multiple pipes. See parser.php -> renderImageGallery in MediaWiki
|
|
|
|
$.trim( this.selectedNode.getAttribute( 'mw' ).body.extsrc )
|
|
|
|
.split( '\n' ).forEach( function ( line ) {
|
|
|
|
var matches;
|
|
|
|
|
|
|
|
// Match lines like:
|
|
|
|
// Image:someimage.jpg|This is some image
|
|
|
|
matches = line.match( /^([^|]+)(\|(.*))?$/ );
|
|
|
|
|
|
|
|
// Ignore any empty lines
|
|
|
|
if ( matches ) {
|
2016-11-23 00:02:59 +00:00
|
|
|
// The "File:" prefix is optional in wikitext galleries. This will add
|
|
|
|
// the prefix if there is no prefix, but won't change an existing
|
|
|
|
// prefix (e.g. "Category:")
|
|
|
|
title = mw.Title.newFromText( matches[ 1 ], namespaceIds.file );
|
2016-03-08 21:14:12 +00:00
|
|
|
// Ignore any invalid titles
|
|
|
|
// (which will result in title being null)
|
|
|
|
if ( title ) {
|
|
|
|
titleText = title.getPrefixedText();
|
|
|
|
imageTitles.push( titleText );
|
2016-11-19 15:51:21 +00:00
|
|
|
dialog.initialImageData.push( {
|
|
|
|
title: titleText,
|
2016-11-28 17:36:29 +00:00
|
|
|
caption: matches[ 3 ] || ''
|
2016-11-19 15:51:21 +00:00
|
|
|
} );
|
2016-03-08 21:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Populate menu and edit panels
|
|
|
|
this.imagesPromise = this.requestImages( {
|
2016-09-30 16:07:10 +00:00
|
|
|
titles: imageTitles
|
2016-03-08 21:14:12 +00:00
|
|
|
} ).done( function () {
|
|
|
|
dialog.onHighlightItem();
|
|
|
|
} );
|
|
|
|
|
|
|
|
// ...Otherwise show the search panel
|
|
|
|
} else {
|
|
|
|
this.toggleEmptyGalleryMessage( true );
|
|
|
|
this.showSearchPanelButton.toggle( false );
|
|
|
|
this.toggleSearchPanel( true );
|
|
|
|
}
|
|
|
|
|
2017-05-10 18:46:49 +00:00
|
|
|
// Options tab panel
|
2016-03-08 21:14:12 +00:00
|
|
|
|
|
|
|
// Set options
|
2016-08-04 23:28:53 +00:00
|
|
|
mode = attributes && attributes.mode || this.defaults.mode;
|
2016-03-08 21:14:12 +00:00
|
|
|
caption = attributes && attributes.caption || '';
|
|
|
|
widths = attributes && parseInt( attributes.widths ) || '';
|
|
|
|
heights = attributes && parseInt( attributes.heights ) || '';
|
|
|
|
perrow = attributes && attributes.perrow || '';
|
|
|
|
showFilename = attributes && attributes.showfilename === 'yes';
|
|
|
|
classes = attributes && attributes.class || '';
|
|
|
|
styles = attributes && attributes.style || '';
|
|
|
|
|
|
|
|
// Populate options panel
|
|
|
|
this.modeDropdown.getMenu().selectItemByData( mode );
|
|
|
|
this.captionInput.setValue( caption );
|
|
|
|
this.widthsInput.setValue( widths );
|
|
|
|
this.heightsInput.setValue( heights );
|
|
|
|
this.perrowInput.setValue( perrow );
|
|
|
|
this.showFilenameCheckbox.setSelected( showFilename );
|
|
|
|
this.classesInput.setValue( classes );
|
|
|
|
this.stylesInput.setValue( styles );
|
|
|
|
|
2016-12-03 15:36:19 +00:00
|
|
|
// Disable fields depending on mode
|
|
|
|
this.onModeDropdownChange();
|
|
|
|
|
2016-03-08 21:14:12 +00:00
|
|
|
// Add event handlers
|
2016-10-12 05:07:37 +00:00
|
|
|
this.indexLayout.connect( this, { set: 'updateDialogSize' } );
|
2017-03-10 16:45:09 +00:00
|
|
|
this.highlightedCaptionInput.connect( this, { change: 'updateActions' } );
|
2016-03-08 21:14:12 +00:00
|
|
|
this.searchWidget.getResults().connect( this, { choose: 'onSearchResultsChoose' } );
|
|
|
|
this.showSearchPanelButton.connect( this, { click: 'onShowSearchPanelButtonClick' } );
|
|
|
|
this.galleryGroup.connect( this, { editItem: 'onHighlightItem' } );
|
2017-03-10 16:45:09 +00:00
|
|
|
this.galleryGroup.connect( this, { itemDragEnd: 'updateActions' } );
|
2016-03-08 21:14:12 +00:00
|
|
|
this.removeButton.connect( this, { click: 'onRemoveItem' } );
|
|
|
|
this.modeDropdown.getMenu().connect( this, { choose: 'onModeDropdownChange' } );
|
2017-03-10 16:45:09 +00:00
|
|
|
this.captionInput.connect( this, { change: 'updateActions' } );
|
|
|
|
this.widthsInput.connect( this, { change: 'updateActions' } );
|
|
|
|
this.heightsInput.connect( this, { change: 'updateActions' } );
|
|
|
|
this.perrowInput.connect( this, { change: 'updateActions' } );
|
|
|
|
this.showFilenameCheckbox.connect( this, { change: 'updateActions' } );
|
|
|
|
this.classesInput.connect( this, { change: 'updateActions' } );
|
|
|
|
this.stylesInput.connect( this, { change: 'updateActions' } );
|
2016-03-08 21:14:12 +00:00
|
|
|
|
|
|
|
// Hack: Give the input a value so that this.insertOrUpdateNode gets called
|
|
|
|
this.input.setValue( 'gallery' );
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWGalleryDialog.super.prototype.getReadyProcess.call( this, data )
|
|
|
|
.next( function () {
|
2016-09-27 20:50:15 +00:00
|
|
|
this.searchWidget.getQuery().focus().select();
|
2016-03-08 21:14:12 +00:00
|
|
|
return this.imagesPromise;
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWGalleryDialog.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.first( function () {
|
|
|
|
this.galleryGroup.clearItems();
|
|
|
|
this.highlightedItem = null;
|
|
|
|
this.searchWidget.getQuery().setValue( '' );
|
|
|
|
this.searchWidget.teardown();
|
|
|
|
this.searchPanelVisible = false;
|
|
|
|
|
|
|
|
// Disconnect events
|
2016-10-12 05:07:37 +00:00
|
|
|
this.indexLayout.disconnect( this );
|
2017-03-10 16:45:09 +00:00
|
|
|
this.highlightedCaptionInput.disconnect( this );
|
2016-03-08 21:14:12 +00:00
|
|
|
this.searchWidget.getResults().disconnect( this );
|
|
|
|
this.showSearchPanelButton.disconnect( this );
|
|
|
|
this.galleryGroup.disconnect( this );
|
|
|
|
this.removeButton.disconnect( this );
|
|
|
|
this.modeDropdown.disconnect( this );
|
2017-03-10 16:45:09 +00:00
|
|
|
this.captionInput.disconnect( this );
|
|
|
|
this.widthsInput.disconnect( this );
|
|
|
|
this.heightsInput.disconnect( this );
|
|
|
|
this.perrowInput.disconnect( this );
|
|
|
|
this.showFilenameCheckbox.disconnect( this );
|
|
|
|
this.classesInput.disconnect( this );
|
|
|
|
this.stylesInput.disconnect( this );
|
2016-03-08 21:14:12 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.getBodyHeight = function () {
|
|
|
|
return 600;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-05-10 18:46:49 +00:00
|
|
|
* Request the images for the images tab panel menu
|
2016-03-08 21:14:12 +00:00
|
|
|
*
|
|
|
|
* @param {Object} options Options for the request
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.requestImages = function ( options ) {
|
2016-09-30 16:07:10 +00:00
|
|
|
var i, len,
|
|
|
|
dialog = this,
|
|
|
|
promises = [];
|
|
|
|
for ( i = 0, len = options.titles.length; i < len; i++ ) {
|
|
|
|
promises.push( ve.init.platform.galleryImageInfoCache.get( options.titles[ i ] ) );
|
|
|
|
}
|
|
|
|
return $.when.apply( $, promises )
|
|
|
|
.done( function () {
|
|
|
|
var resp = {};
|
|
|
|
for ( i = 0; i < len; i++ ) {
|
|
|
|
resp[ options.titles[ i ] ] = arguments[ i ];
|
|
|
|
}
|
|
|
|
dialog.onRequestImagesSuccess( resp );
|
|
|
|
} );
|
2016-03-08 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create items for the returned images and add them to the gallery group
|
|
|
|
*
|
|
|
|
* @param {Object} response jQuery response object
|
|
|
|
*/
|
2016-09-30 16:07:10 +00:00
|
|
|
ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( response ) {
|
|
|
|
var title,
|
2016-03-08 21:14:12 +00:00
|
|
|
thumbUrls = {},
|
2016-09-30 16:07:10 +00:00
|
|
|
items = [];
|
2016-03-08 21:14:12 +00:00
|
|
|
|
2016-09-30 16:07:10 +00:00
|
|
|
for ( title in response ) {
|
|
|
|
thumbUrls[ title ] = response[ title ].thumburl;
|
2016-03-08 21:14:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 15:51:21 +00:00
|
|
|
if ( this.initialImageData.length > 0 ) {
|
|
|
|
this.initialImageData.forEach( function ( image ) {
|
|
|
|
image.thumbUrl = thumbUrls[ image.title ];
|
|
|
|
items.push( new ve.ui.MWGalleryItemWidget( image ) );
|
|
|
|
} );
|
|
|
|
this.initialImageData = [];
|
|
|
|
} else {
|
|
|
|
for ( title in this.selectedFilenames ) {
|
|
|
|
if ( Object.prototype.hasOwnProperty.call( thumbUrls, title ) ) {
|
|
|
|
items.push( new ve.ui.MWGalleryItemWidget( {
|
|
|
|
title: title,
|
|
|
|
thumbUrl: thumbUrls[ title ]
|
|
|
|
} ) );
|
|
|
|
delete this.selectedFilenames[ title ];
|
|
|
|
}
|
2016-10-20 01:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-08 21:14:12 +00:00
|
|
|
this.galleryGroup.addItems( items );
|
|
|
|
|
|
|
|
// Gallery is no longer empty
|
|
|
|
this.updateActions();
|
|
|
|
this.toggleEmptyGalleryMessage( false );
|
|
|
|
this.showSearchPanelButton.toggle( true );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a new image and highlight it
|
|
|
|
*
|
|
|
|
* @param {string} title File name for the new image
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.addNewImage = function ( title ) {
|
|
|
|
var dialog = this;
|
|
|
|
|
2016-11-19 15:51:21 +00:00
|
|
|
// Make list of unique pending images, for onRequestImagesSuccess
|
|
|
|
this.selectedFilenames[ title ] = true;
|
2016-03-08 21:14:12 +00:00
|
|
|
|
|
|
|
// Request image
|
|
|
|
this.requestImages( {
|
2016-09-30 16:07:10 +00:00
|
|
|
titles: [ title ]
|
2016-03-08 21:14:12 +00:00
|
|
|
} ).done( function () {
|
|
|
|
|
|
|
|
// populate edit panel with the new image
|
|
|
|
var items = dialog.galleryGroup.items;
|
|
|
|
dialog.onHighlightItem( items[ items.length - 1 ] );
|
|
|
|
dialog.highlightedCaptionInput.focus();
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle search results choose event.
|
|
|
|
*
|
2016-11-16 18:21:22 +00:00
|
|
|
* @param {mw.widgets.MediaResultWidget} item Chosen item
|
2016-03-08 21:14:12 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.onSearchResultsChoose = function ( item ) {
|
2016-11-14 22:04:25 +00:00
|
|
|
var title = mw.Title.newFromText( item.getData().title ).getPrefixedText();
|
|
|
|
|
2016-11-19 15:51:21 +00:00
|
|
|
if ( !Object.prototype.hasOwnProperty( this.selectedFilenames, title ) ) {
|
2016-10-20 01:06:54 +00:00
|
|
|
this.addNewImage( title );
|
|
|
|
}
|
2017-03-10 16:45:09 +00:00
|
|
|
|
|
|
|
this.updateActions();
|
2016-03-08 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle click event for the remove button
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.onRemoveItem = function () {
|
|
|
|
|
|
|
|
// Remove the highlighted item
|
|
|
|
this.galleryGroup.removeItems( [ this.highlightedItem ] );
|
|
|
|
|
|
|
|
// Show the search panel if the gallery is now empty...
|
|
|
|
if ( this.galleryGroup.items.length === 0 ) {
|
|
|
|
this.toggleEmptyGalleryMessage( true );
|
|
|
|
this.showSearchPanelButton.toggle( false );
|
|
|
|
this.toggleSearchPanel( true );
|
|
|
|
|
|
|
|
// ...Otherwise highlight the first item in the gallery
|
|
|
|
} else {
|
|
|
|
this.onHighlightItem();
|
|
|
|
}
|
|
|
|
this.updateActions();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicking on an image in the menu
|
|
|
|
*
|
|
|
|
* @param {ve.ui.MWGalleryItemWidget} item The item that was clicked on
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.onHighlightItem = function ( item ) {
|
2017-06-06 14:46:31 +00:00
|
|
|
var title;
|
|
|
|
|
2016-03-08 21:14:12 +00:00
|
|
|
// Unhighlight previous item
|
|
|
|
if ( this.highlightedItem ) {
|
|
|
|
this.highlightedItem.toggleHighlighted( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show edit panel
|
|
|
|
this.toggleSearchPanel( false );
|
|
|
|
|
|
|
|
// Highlight new item
|
2016-11-15 23:05:05 +00:00
|
|
|
item = item || this.galleryGroup.items[ 0 ];
|
2016-03-08 21:14:12 +00:00
|
|
|
item.toggleHighlighted( true );
|
|
|
|
this.highlightedItem = item;
|
|
|
|
|
2016-12-03 15:46:58 +00:00
|
|
|
// Scroll item into view in menu
|
|
|
|
OO.ui.Element.static.scrollIntoView( item.$element[ 0 ] );
|
|
|
|
|
2016-03-08 21:14:12 +00:00
|
|
|
// Populate edit panel
|
2017-06-06 14:46:31 +00:00
|
|
|
title = mw.Title.newFromText( item.imageTitle );
|
|
|
|
this.filenameFieldset.setLabel(
|
|
|
|
$( '<span>' ).append(
|
|
|
|
document.createTextNode( title.getMainText() + ' ' ),
|
|
|
|
$( '<a>' )
|
|
|
|
.addClass( 'visualeditor-dialog-media-content-description-link' )
|
|
|
|
.attr( 'href', title.getUrl() )
|
|
|
|
.attr( 'target', '_blank' )
|
|
|
|
.text( ve.msg( 'visualeditor-dialog-media-content-description-link' ) )
|
|
|
|
)
|
|
|
|
);
|
2016-03-08 21:14:12 +00:00
|
|
|
this.$highlightedImage
|
|
|
|
.css( 'background-image', 'url(' + item.thumbUrl + ')' );
|
|
|
|
this.highlightedCaptionInput
|
|
|
|
.setValue( item.caption );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle change event for this.modeDropdown
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.onModeDropdownChange = function () {
|
|
|
|
var mode = this.modeDropdown.getMenu().getSelectedItem().getData(),
|
2016-07-07 17:45:44 +00:00
|
|
|
disabled = (
|
|
|
|
mode === 'packed' ||
|
|
|
|
mode === 'packed-overlay' ||
|
|
|
|
mode === 'packed-hover' ||
|
|
|
|
mode === 'slideshow'
|
|
|
|
);
|
2016-03-08 21:14:12 +00:00
|
|
|
|
|
|
|
this.widthsInput.setDisabled( disabled );
|
|
|
|
this.perrowInput.setDisabled( disabled );
|
2016-12-03 15:36:19 +00:00
|
|
|
|
|
|
|
// heights is only ignored in slideshow mode
|
|
|
|
this.heightsInput.setDisabled( mode === 'slideshow' );
|
2017-03-10 16:45:09 +00:00
|
|
|
|
|
|
|
this.updateActions();
|
2016-03-08 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle click event for showSearchPanelButton
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.onShowSearchPanelButtonClick = function () {
|
|
|
|
this.toggleSearchPanel( true );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the search panel (and the edit panel, the opposite way)
|
|
|
|
*
|
|
|
|
* @param {boolean} visible The search panel is visible
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.toggleSearchPanel = function ( visible ) {
|
2016-11-29 16:19:06 +00:00
|
|
|
var pageTitle, namespace, namespacesWithSubpages;
|
|
|
|
|
2016-03-08 21:14:12 +00:00
|
|
|
visible = visible !== undefined ? visible : !this.searchPanelVisible;
|
|
|
|
|
|
|
|
// If currently visible panel is an edit panel, store the caption
|
|
|
|
if ( !this.searchPanelVisible && this.highlightedItem ) {
|
|
|
|
this.highlightedItem.setCaption(
|
|
|
|
this.highlightedCaptionInput.getValue()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record the state of the search panel
|
|
|
|
this.searchPanelVisible = visible;
|
|
|
|
|
|
|
|
// Toggle the search panel, and do the opposite for the edit panel
|
|
|
|
this.searchPanel.toggle( visible );
|
|
|
|
this.editPanel.toggle( !visible );
|
|
|
|
|
|
|
|
// If the edit panel is visible, focus the caption input
|
|
|
|
if ( !visible ) {
|
|
|
|
this.highlightedCaptionInput.focus();
|
|
|
|
} else {
|
2016-11-29 16:19:06 +00:00
|
|
|
if ( !this.searchWidget.getQuery().getValue() ) {
|
|
|
|
// Wait until the search panel is visible before setting a default query
|
|
|
|
// as this triggers a request and render.
|
|
|
|
pageTitle = mw.config.get( 'wgTitle' );
|
|
|
|
namespace = mw.config.get( 'wgNamespaceNumber' );
|
|
|
|
namespacesWithSubpages = mw.config.get( 'wgVisualEditorConfig' ).namespacesWithSubpages;
|
|
|
|
|
|
|
|
if ( namespacesWithSubpages[ namespace ] ) {
|
|
|
|
pageTitle = pageTitle.slice( pageTitle.lastIndexOf( '/' ) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.searchWidget.getQuery().setValue( pageTitle );
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:50:15 +00:00
|
|
|
this.searchWidget.getQuery().focus().select();
|
2016-03-08 21:14:12 +00:00
|
|
|
}
|
2016-10-12 05:07:37 +00:00
|
|
|
this.updateDialogSize();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize the dialog according to which panel is focused
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.updateDialogSize = function () {
|
2017-05-10 18:46:49 +00:00
|
|
|
if ( this.searchPanelVisible && this.indexLayout.currentTabPanelName === 'images' ) {
|
2016-10-12 05:07:37 +00:00
|
|
|
this.setSize( 'larger' );
|
|
|
|
} else {
|
|
|
|
this.setSize( 'large' );
|
|
|
|
}
|
2016-03-08 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the empty gallery message
|
|
|
|
*
|
|
|
|
* @param {boolean} empty The gallery is empty
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.toggleEmptyGalleryMessage = function ( empty ) {
|
|
|
|
if ( empty ) {
|
|
|
|
this.$emptyGalleryMessage.removeClass( 'oo-ui-element-hidden' );
|
|
|
|
} else {
|
|
|
|
this.$emptyGalleryMessage.addClass( 'oo-ui-element-hidden' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable the "Done" button if the gallery is empty, otherwise enable it
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.updateActions = function () {
|
2017-03-10 16:45:09 +00:00
|
|
|
this.actions.setAbilities( { done: this.galleryGroup.items.length > 0 && this.isModified() } );
|
2016-03-08 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-03-10 16:45:09 +00:00
|
|
|
* Get the current images and options data
|
|
|
|
*
|
|
|
|
* @return {Object} Images and options data
|
2016-03-08 21:14:12 +00:00
|
|
|
*/
|
2017-03-10 16:45:09 +00:00
|
|
|
ve.ui.MWGalleryDialog.prototype.getCurrentData = function () {
|
|
|
|
var i, ilen,
|
|
|
|
data = {},
|
2016-03-08 21:14:12 +00:00
|
|
|
items = this.galleryGroup.items;
|
|
|
|
|
2017-05-10 18:46:49 +00:00
|
|
|
// Get data from options tab panel
|
2017-03-10 16:45:09 +00:00
|
|
|
data.caption = this.captionInput.getValue() || undefined;
|
|
|
|
data.widths = this.widthsInput.getValue() || undefined;
|
|
|
|
data.heights = this.heightsInput.getValue() || undefined;
|
|
|
|
data.perrow = this.perrowInput.getValue() || undefined;
|
|
|
|
data.showFilename = this.showFilenameCheckbox.isSelected() ? 'yes' : undefined;
|
|
|
|
data.classes = this.classesInput.getValue() || undefined;
|
|
|
|
data.styles = this.stylesInput.getValue() || undefined;
|
2017-03-21 22:29:59 +00:00
|
|
|
if ( this.modeDropdown.getMenu().getSelectedItem() ) {
|
|
|
|
data.mode = this.modeDropdown.getMenu().getSelectedItem().getData();
|
|
|
|
}
|
2017-03-10 16:45:09 +00:00
|
|
|
|
|
|
|
// Unset mode attribute if it is the same as the default
|
|
|
|
data.mode = data.mode === this.defaults.mode ? undefined : data.mode;
|
2016-03-08 21:14:12 +00:00
|
|
|
|
|
|
|
// Get titles and captions from gallery group
|
2017-03-10 16:45:09 +00:00
|
|
|
data.extsrc = '';
|
|
|
|
if ( this.highlightedItem ) {
|
|
|
|
this.highlightedItem.setCaption( this.highlightedCaptionInput.getValue() );
|
|
|
|
}
|
2016-03-08 21:14:12 +00:00
|
|
|
for ( i = 0, ilen = items.length; i < ilen; i++ ) {
|
2017-03-10 16:45:09 +00:00
|
|
|
data.extsrc += '\n' + items[ i ].imageTitle + '|' + items[ i ].caption;
|
2016-03-08 21:14:12 +00:00
|
|
|
}
|
2017-03-10 16:45:09 +00:00
|
|
|
data.extsrc += '\n';
|
2016-03-08 21:14:12 +00:00
|
|
|
|
2017-03-10 16:45:09 +00:00
|
|
|
return data;
|
|
|
|
};
|
2016-08-04 23:28:53 +00:00
|
|
|
|
2017-03-10 16:45:09 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGalleryDialog.prototype.updateMwData = function ( mwData ) {
|
|
|
|
var data;
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWGalleryDialog.super.prototype.updateMwData.call( this, mwData );
|
|
|
|
|
|
|
|
data = this.getCurrentData();
|
|
|
|
|
|
|
|
mwData.body.extsrc = data.extsrc;
|
|
|
|
mwData.attrs.mode = data.mode;
|
|
|
|
mwData.attrs.caption = data.caption;
|
|
|
|
mwData.attrs.widths = data.widths;
|
|
|
|
mwData.attrs.heights = data.heights;
|
|
|
|
mwData.attrs.perrow = data.perrow;
|
|
|
|
mwData.attrs.showfilename = data.showFilename;
|
|
|
|
mwData.attrs.classes = data.classes;
|
|
|
|
mwData.attrs.styles = data.styles;
|
2016-03-08 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWGalleryDialog );
|