mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
5788340b49
New changes: 14b5fbc [BREAKING CHANGE] Move originalDomElements to the IV store and use MD5 c5d21f0 Provide methods to (de)serialize transactions Local changes to move originalDomElements to IV store Depends-On: I8a71c1a40ec35108d0a9a388da6f75632f8dc53c Depends-On: I32c9b5f984fcf96e3354841ecfcd444149e8f159 Change-Id: I0fbb6324eede94558426178cbdad6b5daf0f8318
64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWNowikiAnnotation class.
|
|
*
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
|
* @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]
|
|
*/
|
|
ve.dm.MWNowikiAnnotation = function VeDmMWNowikiAnnotation( element ) {
|
|
// Parent constructor
|
|
ve.dm.Annotation.call( this, element );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.dm.MWNowikiAnnotation, ve.dm.Annotation );
|
|
|
|
/* 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 ) {
|
|
var i, len,
|
|
originalDomElements = converter.getStore().value( dataElement.originalDomElementsIndex ),
|
|
originalChildren = originalDomElements && originalDomElements[ 0 ] && originalDomElements[ 0 ].childNodes,
|
|
contentsChanged = false,
|
|
domElement = document.createElement( 'span' );
|
|
|
|
// Determine whether the contents changed
|
|
if ( !originalChildren || childDomElements.length !== originalChildren.length ) {
|
|
contentsChanged = true;
|
|
} else {
|
|
for ( i = 0, len = originalChildren.length; i < len; i++ ) {
|
|
if ( !originalChildren[ i ].isEqualNode( childDomElements[ i ] ) ) {
|
|
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 );
|