2013-07-17 01:22:22 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWNowikiAnnotation class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-07-17 01:22:22 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki nowiki annotation
|
|
|
|
*
|
|
|
|
* Represents `<nowiki>` tags (in HTML as `<span typeof="mw:Nowiki">`) and unwraps them when they change
|
|
|
|
* so as to retrigger Parsoid's escaping mechanism.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.Annotation
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} element [description]
|
|
|
|
*/
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.dm.MWNowikiAnnotation = function VeDmMWNowikiAnnotation() {
|
2013-07-17 01:22:22 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.dm.MWNowikiAnnotation.super.apply( this, arguments );
|
2013-07-17 01:22:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWNowikiAnnotation, ve.dm.Annotation );
|
2013-07-17 01:22:22 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.dm.MWNowikiAnnotation.static.name = 'mwNowiki';
|
|
|
|
|
|
|
|
ve.dm.MWNowikiAnnotation.static.matchRdfaTypes = [ 'mw:Nowiki' ];
|
|
|
|
|
|
|
|
ve.dm.MWNowikiAnnotation.static.toDomElements = function ( dataElement, doc, converter, childDomElements ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var originalDomElements = converter.getStore().value( dataElement.originalDomElementsHash ),
|
2015-08-19 17:33:02 +00:00
|
|
|
originalChildren = originalDomElements && originalDomElements[ 0 ] && originalDomElements[ 0 ].childNodes,
|
2013-07-17 01:22:22 +00:00
|
|
|
contentsChanged = false,
|
|
|
|
domElement = document.createElement( 'span' );
|
|
|
|
|
|
|
|
// Determine whether the contents changed
|
|
|
|
if ( !originalChildren || childDomElements.length !== originalChildren.length ) {
|
|
|
|
contentsChanged = true;
|
|
|
|
} else {
|
2021-10-13 12:57:45 +00:00
|
|
|
for ( var i = 0, len = originalChildren.length; i < len; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( !originalChildren[ i ].isEqualNode( childDomElements[ i ] ) ) {
|
2013-07-17 01:22:22 +00:00
|
|
|
contentsChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the contents changed, unwrap, otherwise, restore
|
|
|
|
if ( contentsChanged ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
domElement.setAttribute( 'typeof', 'mw:Nowiki' );
|
|
|
|
return [ domElement ];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWNowikiAnnotation );
|