Merge "Move checkbox widget creation to mw.libs.ve"

This commit is contained in:
jenkins-bot 2020-03-13 18:13:46 +00:00 committed by Gerrit Code Review
commit 2c1383b79e
3 changed files with 73 additions and 51 deletions

View file

@ -404,8 +404,7 @@ ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) {
* loadSuccess(). If false, either that loadFail() has been called or we're retrying via load(). * loadSuccess(). If false, either that loadFail() has been called or we're retrying via load().
*/ */
ve.init.mw.ArticleTarget.prototype.parseMetadata = function ( response ) { ve.init.mw.ArticleTarget.prototype.parseMetadata = function ( response ) {
var aboutDoc, docRevIdMatches, docRevId, var aboutDoc, docRevIdMatches, docRevId, checkboxes,
name, options, accesskey, title, $label, checkbox,
data = response ? ( response.visualeditor || response.visualeditoredit ) : null; data = response ? ( response.visualeditor || response.visualeditoredit ) : null;
if ( !data ) { if ( !data ) {
@ -461,54 +460,15 @@ ve.init.mw.ArticleTarget.prototype.parseMetadata = function ( response ) {
this.retriedRevIdConflict = false; this.retriedRevIdConflict = false;
} }
this.checkboxFields = []; checkboxes = mw.libs.ve.targetLoader.createCheckboxFields( this.checkboxesDef );
this.checkboxesByName = {}; this.checkboxFields = checkboxes.checkboxFields;
this.checkboxesByName = checkboxes.checkboxesByName;
if ( this.checkboxesDef ) { this.checkboxFields.forEach( function ( field ) {
for ( name in this.checkboxesDef ) { // TODO: This method should be upstreamed or moved so that targetLoader
options = this.checkboxesDef[ name ]; // can use it safely.
ve.targetLinksToNewWindow( field.$label[ 0 ] );
accesskey = null; } );
title = null;
// The messages documented below are just the ones defined in core.
// Extensions may add other checkboxes.
if ( options.tooltip ) {
// The following messages are used here:
// * accesskey-minoredit
// * accesskey-watch
accesskey = mw.message( 'accesskey-' + options.tooltip ).text();
// The following messages are used here:
// * tooltip-minoredit
// * tooltip-watch
title = mw.message( 'tooltip-' + options.tooltip ).text();
}
if ( options[ 'title-message' ] ) {
// Not used in core
// eslint-disable-next-line mediawiki/msg-doc
title = mw.message( options[ 'title-message' ] ).text();
}
// The following messages are used here:
// * minoredit
// * watchthis
$label = $( '<span>' ).append( mw.message( options[ 'label-message' ] ).parseDom() );
ve.targetLinksToNewWindow( $label[ 0 ] );
checkbox = new OO.ui.CheckboxInputWidget( {
accessKey: accesskey,
selected: options.default,
classes: [ 've-ui-mwSaveDialog-checkbox-' + name ]
} );
this.checkboxFields.push(
new OO.ui.FieldLayout( checkbox, {
align: 'inline',
label: $label.contents(),
title: title
} )
);
this.checkboxesByName[ name ] = checkbox;
}
}
return true; return true;
}; };

View file

@ -103,6 +103,68 @@
} ); } );
}, },
/**
* Creates an OOUI checkbox inside an inline field layout
*
* @param {Object[]} checkboxesDef Checkbox definitions from the API
* @return {Object} Result object with checkboxFields (OO.ui.FieldLayout[]) and
* checkboxesByName (keyed object of OO.ui.CheckboxInputWidget).
*/
createCheckboxFields: function ( checkboxesDef ) {
var checkboxFields = [],
checkboxesByName = {};
if ( checkboxesDef ) {
Object.keys( checkboxesDef ).forEach( function ( name ) {
var $label, checkbox,
options = checkboxesDef[ name ],
accesskey = null,
title = null;
// The messages documented below are just the ones defined in core.
// Extensions may add other checkboxes.
if ( options.tooltip ) {
// The following messages are used here:
// * accesskey-minoredit
// * accesskey-watch
accesskey = mw.message( 'accesskey-' + options.tooltip ).text();
// The following messages are used here:
// * tooltip-minoredit
// * tooltip-watch
title = mw.message( 'tooltip-' + options.tooltip ).text();
}
if ( options[ 'title-message' ] ) {
// Not used in core
// eslint-disable-next-line mediawiki/msg-doc
title = mw.message( options[ 'title-message' ] ).text();
}
// The following messages are used here:
// * minoredit
// * watchthis
$label = $( '<span>' ).append( mw.message( options[ 'label-message' ] ).parseDom() );
checkbox = new OO.ui.CheckboxInputWidget( {
accessKey: accesskey,
selected: options.default,
classes: [ 've-ui-mwSaveDialog-checkbox-' + name ]
} );
checkboxFields.push(
new OO.ui.FieldLayout( checkbox, {
align: 'inline',
label: $label.contents(),
title: title
} )
);
checkboxesByName[ name ] = checkbox;
} );
}
return {
checkboxFields: checkboxFields,
checkboxesByName: checkboxesByName
};
},
/** /**
* Request the page data and various metadata from the MediaWiki API (which will use * Request the page data and various metadata from the MediaWiki API (which will use
* Parsoid or RESTBase). * Parsoid or RESTBase).

View file

@ -41,12 +41,12 @@
padding: 0.7em 0.7em 0 0.7em; padding: 0.7em 0.7em 0 0.7em;
} }
.ve-ui-mwSaveDialog-checkboxes .oo-ui-fieldLayout { .ve-ui-mwSaveDialog-checkboxes > .oo-ui-fieldLayout {
display: inline-block; display: inline-block;
margin: 0 1.5em 0 0; margin: 0 1.5em 0 0;
} }
.ve-ui-mwSaveDialog-checkboxes .oo-ui-fieldLayout:last-child { .ve-ui-mwSaveDialog-checkboxes > .oo-ui-fieldLayout:last-child {
margin-right: 0; margin-right: 0;
} }