mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 00:00:49 +00:00
Merge "Move checkbox widget creation to mw.libs.ve"
This commit is contained in:
commit
2c1383b79e
|
@ -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().
|
||||
*/
|
||||
ve.init.mw.ArticleTarget.prototype.parseMetadata = function ( response ) {
|
||||
var aboutDoc, docRevIdMatches, docRevId,
|
||||
name, options, accesskey, title, $label, checkbox,
|
||||
var aboutDoc, docRevIdMatches, docRevId, checkboxes,
|
||||
data = response ? ( response.visualeditor || response.visualeditoredit ) : null;
|
||||
|
||||
if ( !data ) {
|
||||
|
@ -461,54 +460,15 @@ ve.init.mw.ArticleTarget.prototype.parseMetadata = function ( response ) {
|
|||
this.retriedRevIdConflict = false;
|
||||
}
|
||||
|
||||
this.checkboxFields = [];
|
||||
this.checkboxesByName = {};
|
||||
checkboxes = mw.libs.ve.targetLoader.createCheckboxFields( this.checkboxesDef );
|
||||
this.checkboxFields = checkboxes.checkboxFields;
|
||||
this.checkboxesByName = checkboxes.checkboxesByName;
|
||||
|
||||
if ( this.checkboxesDef ) {
|
||||
for ( name in this.checkboxesDef ) {
|
||||
options = this.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() );
|
||||
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;
|
||||
}
|
||||
}
|
||||
this.checkboxFields.forEach( function ( field ) {
|
||||
// TODO: This method should be upstreamed or moved so that targetLoader
|
||||
// can use it safely.
|
||||
ve.targetLinksToNewWindow( field.$label[ 0 ] );
|
||||
} );
|
||||
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
* Parsoid or RESTBase).
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue