mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
226 lines
7 KiB
JavaScript
226 lines
7 KiB
JavaScript
/*!
|
|
* VisualEditor user interface MWAdvancedSettingsPage class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* MediaWiki meta dialog advanced settings page.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.PageLayout
|
|
*
|
|
* @constructor
|
|
* @param {ve.ui.Surface} surface Surface being worked on
|
|
* @param {string} name Unique symbolic name of page
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage = function VeUiMWAdvancedSettingsPage( surface, name, config ) {
|
|
// Parent constructor
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
// Properties
|
|
this.metaList = surface.getModel().metaList;
|
|
this.indexingOptionTouched = false;
|
|
this.newSectionEditLinkOptionTouched = false;
|
|
|
|
this.advancedSettingsFieldset = new OO.ui.FieldsetLayout( {
|
|
'$': this.$,
|
|
'label': ve.msg( 'visualeditor-dialog-meta-advancedsettings-label' ),
|
|
'icon': 'advanced'
|
|
} );
|
|
|
|
// Initialization
|
|
|
|
// Indexing items
|
|
this.indexingOptionSelector = new OO.ui.ButtonSelectWidget( { '$': this.$ } );
|
|
this.indexingOptionWidgets = {
|
|
'mwIndexForce': new OO.ui.ButtonOptionWidget(
|
|
'mwIndexForce',
|
|
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-index-force' ) }
|
|
),
|
|
'default': new OO.ui.ButtonOptionWidget(
|
|
'default',
|
|
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-index-default' ) }
|
|
),
|
|
'mwIndexDisable': new OO.ui.ButtonOptionWidget(
|
|
'mwIndexDisable',
|
|
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-index-disable' ) }
|
|
)
|
|
};
|
|
this.indexingOptionSelector.addItems( ve.getObjectValues( this.indexingOptionWidgets ) );
|
|
this.advancedSettingsFieldset.$element.append(
|
|
this.$( '<span>' )
|
|
.text( ve.msg( 'visualeditor-dialog-meta-settings-index-label' ) ),
|
|
this.indexingOptionSelector.$element
|
|
);
|
|
|
|
// New edit section link items
|
|
this.newSectionEditLinkOptionSelector = new OO.ui.ButtonSelectWidget( { '$': this.$ } );
|
|
this.newSectionEditLinkOptionWidgets = {
|
|
'mwNewSectionEditForce': new OO.ui.ButtonOptionWidget(
|
|
'mwNewSectionEditForce',
|
|
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-force' ) }
|
|
),
|
|
'default': new OO.ui.ButtonOptionWidget(
|
|
'default',
|
|
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-default' ) }
|
|
),
|
|
'mwNewSectionEditDisable': new OO.ui.ButtonOptionWidget(
|
|
'mwNewSectionEditDisable',
|
|
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-disable' ) }
|
|
)
|
|
};
|
|
this.newSectionEditLinkOptionSelector.addItems( ve.getObjectValues( this.newSectionEditLinkOptionWidgets ) );
|
|
this.advancedSettingsFieldset.$element.append(
|
|
this.$( '<span>' )
|
|
.text( ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-label' ) ),
|
|
this.newSectionEditLinkOptionSelector.$element
|
|
);
|
|
|
|
this.$element.append( this.advancedSettingsFieldset.$element );
|
|
|
|
// Events
|
|
this.indexingOptionSelector.connect( this, { 'select': 'onIndexingOptionChange' } );
|
|
this.newSectionEditLinkOptionSelector.connect( this, { 'select': 'onNewSectionEditLinkOptionChange' } );
|
|
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWAdvancedSettingsPage, OO.ui.PageLayout );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage.prototype.setOutlineItem = function ( outlineItem ) {
|
|
// Parent method
|
|
OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem );
|
|
|
|
if ( this.outlineItem ) {
|
|
this.outlineItem
|
|
.setIcon( 'advanced' )
|
|
.setLabel( ve.msg( 'visualeditor-dialog-meta-advancedsettings-section' ) );
|
|
}
|
|
};
|
|
|
|
/* Indexing option methods */
|
|
|
|
/**
|
|
* Handle indexing option state change events.
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage.prototype.onIndexingOptionChange = function () {
|
|
this.indexingOptionTouched = true;
|
|
};
|
|
|
|
/**
|
|
* Get indexing options
|
|
*
|
|
* @returns {Object|null} Indexing option, if any
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage.prototype.getIndexingOptionItem = function () {
|
|
return this.metaList.getItemsInGroup( 'mwIndex' )[0] || null;
|
|
};
|
|
|
|
/* New edit section link option methods */
|
|
|
|
/**
|
|
* Handle new edit section link change events.
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage.prototype.onNewSectionEditLinkOptionChange = function () {
|
|
this.newSectionEditLinkOptionTouched = true;
|
|
};
|
|
|
|
/**
|
|
* Get the new section edit link item
|
|
*
|
|
* @returns {Object|null} New section edit link option, if any
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage.prototype.getNewSectionEditLinkItem = function () {
|
|
return this.metaList.getItemsInGroup( 'mwNewSectionEdit' )[0] || null;
|
|
};
|
|
|
|
/**
|
|
* Setup settings page.
|
|
*
|
|
* @param {Object} [data] Dialog setup data
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage.prototype.setup = function () {
|
|
var // Indexing items
|
|
indexingOption = this.getIndexingOptionItem(),
|
|
indexingType = indexingOption && indexingOption.element.type || 'default',
|
|
|
|
// New section edit link items
|
|
newSectionEditLinkOption = this.getNewSectionEditLinkItem(),
|
|
newSectionEditLinkType = newSectionEditLinkOption && newSectionEditLinkOption.element.type || 'default';
|
|
|
|
// Indexing items
|
|
this.indexingOptionSelector.selectItem( this.indexingOptionWidgets[indexingType] );
|
|
this.indexingOptionTouched = false;
|
|
|
|
// New section edit link items
|
|
this.newSectionEditLinkOptionSelector.selectItem( this.newSectionEditLinkOptionWidgets[newSectionEditLinkType] );
|
|
this.newSectionEditLinkOptionTouched = false;
|
|
};
|
|
|
|
/**
|
|
* Tear down settings page.
|
|
*
|
|
* @param {Object} [data] Dialog tear down data
|
|
*/
|
|
ve.ui.MWAdvancedSettingsPage.prototype.teardown = function ( data ) {
|
|
// Data initialization
|
|
data = data || {};
|
|
|
|
var // Indexing items
|
|
currentIndexingItem = this.getIndexingOptionItem(),
|
|
newIndexingData = this.indexingOptionSelector.getSelectedItem(),
|
|
|
|
// New section edit link items
|
|
currentNewSectionEditLinkItem = this.getNewSectionEditLinkItem(),
|
|
newNewSectionEditLinkOptionData = this.newSectionEditLinkOptionSelector.getSelectedItem();
|
|
|
|
// Alter the indexing option flag iff it's been touched & is actually different
|
|
if ( this.indexingOptionTouched ) {
|
|
if ( newIndexingData.data === 'default' ) {
|
|
if ( currentIndexingItem ) {
|
|
currentIndexingItem.remove();
|
|
}
|
|
} else {
|
|
if ( !currentIndexingItem ) {
|
|
this.metaList.insertMeta( { 'type': newIndexingData.data } );
|
|
} else if ( currentIndexingItem.element.type !== newIndexingData.data ) {
|
|
currentIndexingItem.replaceWith(
|
|
ve.extendObject( true, {},
|
|
currentIndexingItem.getElement(),
|
|
{ 'type': newIndexingData.data }
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Alter the new section edit option flag iff it's been touched & is actually different
|
|
if ( this.newSectionEditLinkOptionTouched ) {
|
|
if ( newNewSectionEditLinkOptionData.data === 'default' ) {
|
|
if ( currentNewSectionEditLinkItem ) {
|
|
currentNewSectionEditLinkItem.remove();
|
|
}
|
|
} else {
|
|
if ( !currentNewSectionEditLinkItem ) {
|
|
this.metaList.insertMeta( { 'type': newNewSectionEditLinkOptionData.data } );
|
|
} else if ( currentNewSectionEditLinkItem.element.type !== newNewSectionEditLinkOptionData.data ) {
|
|
currentNewSectionEditLinkItem.replaceWith(
|
|
ve.extendObject( true, {},
|
|
currentNewSectionEditLinkItem.getElement(),
|
|
{ 'type': newNewSectionEditLinkOptionData.data }
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
};
|