mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 19:09:29 +00:00
434c11f6de
Notably: * Don't require the model in the new sidebar via dependency injection, but connect the event handlers later. This is relevant because we currently create the new sidebar in the wrong spot. Removing the hard dependency allows us to split the code and utilize initialize() and getSetupProcess() correctly. This will be done in a following patch. * The change event now includes the new position. This makes it very easy to add this missing feature to the new sidebar. Also: * Stop triggering change events when nothing changed. These events are expensive. They bubble all the way up to the TransclusionModel, and to all linked onTransclusionModelChange() handlers. * Update event documentation to make this more visible. Bug: T274544 Change-Id: Iafe29f18a6fed14d9c3124c9756aa840886afbbc
97 lines
2.5 KiB
JavaScript
97 lines
2.5 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWTransclusionPartModel class.
|
|
*
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Abstract base class for items in a {@see ve.dm.MWTransclusionModel}. Holds a back-reference to
|
|
* it's parent. Currently used for:
|
|
* - {@see ve.dm.MWTemplateModel} for a single template invocation.
|
|
* - {@see ve.dm.MWTemplatePlaceholderModel} while searching for a template name to be added.
|
|
* - {@see ve.dm.MWTransclusionContentModel} for a raw wikitext snippet.
|
|
*
|
|
* @class
|
|
* @mixins OO.EventEmitter
|
|
*
|
|
* @constructor
|
|
* @param {ve.dm.MWTransclusionModel} transclusion
|
|
*/
|
|
ve.dm.MWTransclusionPartModel = function VeDmMWTransclusionPartModel( transclusion ) {
|
|
// Mixin constructors
|
|
OO.EventEmitter.call( this );
|
|
|
|
// Properties
|
|
this.transclusion = transclusion;
|
|
this.id = 'part_' + this.transclusion.getUniquePartId();
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.mixinClass( ve.dm.MWTransclusionPartModel, OO.EventEmitter );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* Emitted when anything changed in the content the part represents, e.g. a parameter was added to a
|
|
* template, or a value edited.
|
|
*
|
|
* @event change
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get transclusion part is in.
|
|
*
|
|
* @return {ve.dm.MWTransclusionModel} Transclusion
|
|
*/
|
|
ve.dm.MWTransclusionPartModel.prototype.getTransclusion = function () {
|
|
return this.transclusion;
|
|
};
|
|
|
|
/**
|
|
* Get a unique part ID within the transclusion.
|
|
*
|
|
* @return {string} Unique ID
|
|
*/
|
|
ve.dm.MWTransclusionPartModel.prototype.getId = function () {
|
|
return this.id;
|
|
};
|
|
|
|
/**
|
|
* Remove part from transclusion.
|
|
*/
|
|
ve.dm.MWTransclusionPartModel.prototype.remove = function () {
|
|
this.transclusion.removePart( this );
|
|
};
|
|
|
|
/**
|
|
* Create a serialized representation of this part. Contains all information needed to recreate the
|
|
* original wikitext, including extra whitespace. Used in
|
|
* {@see ve.dm.MWTransclusionModel.getPlainObject}. The corresponding deserializer is in
|
|
* {@see ve.dm.MWTransclusionNode.static.getWikitext}.
|
|
*
|
|
* @return {Object|string|undefined} Serialized representation, raw wikitext, or undefined if empty
|
|
*/
|
|
ve.dm.MWTransclusionPartModel.prototype.serialize = function () {
|
|
return undefined;
|
|
};
|
|
|
|
/**
|
|
* Add all non-existing required and suggested parameters, if any.
|
|
*
|
|
* @return {number} Number of parameters added
|
|
*/
|
|
ve.dm.MWTransclusionPartModel.prototype.addPromptedParameters = function () {
|
|
return 0;
|
|
};
|
|
|
|
/**
|
|
* @return {boolean} True if there is no user input
|
|
*/
|
|
ve.dm.MWTransclusionPartModel.prototype.isEmpty = function () {
|
|
return true;
|
|
};
|