mediawiki-extensions-Visual.../modules/ve-mw/dm/models/ve.dm.MWTransclusionContentModel.js
Thiemo Kreuz 434c11f6de Fix incomplete template dialog event handling in new sidebar
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
2021-07-16 11:29:26 +00:00

64 lines
1.4 KiB
JavaScript

/*!
* VisualEditor DataModel MWTransclusionContentModel class.
*
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Represents a raw wikitext snippet that is part of an unbalanced sequence of template invocations.
* Meant to be an item in a {@see ve.dm.MWTransclusionModel}. Holds a back-reference to it's parent.
*
* @class
* @extends ve.dm.MWTransclusionPartModel
*
* @constructor
* @param {ve.dm.MWTransclusionModel} transclusion
* @param {string} [wikitext='']
*/
ve.dm.MWTransclusionContentModel = function VeDmMWTransclusionContentModel( transclusion, wikitext ) {
// Parent constructor
ve.dm.MWTransclusionContentModel.super.call( this, transclusion );
// Properties
this.wikitext = wikitext || '';
};
/* Inheritance */
OO.inheritClass( ve.dm.MWTransclusionContentModel, ve.dm.MWTransclusionPartModel );
/* Events */
/**
* Emitted when the wikitext changed.
*
* @event change
*/
/* Methods */
/**
* @param {string} wikitext
*/
ve.dm.MWTransclusionContentModel.prototype.setWikitext = function ( wikitext ) {
if ( this.wikitext !== wikitext ) {
this.wikitext = wikitext;
this.emit( 'change' );
}
};
/**
* @inheritdoc
*/
ve.dm.MWTransclusionContentModel.prototype.serialize = function () {
return this.wikitext;
};
/**
* @inheritdoc
*/
ve.dm.MWTransclusionContentModel.prototype.isEmpty = function () {
return this.wikitext === '';
};