mediawiki-extensions-Visual.../modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js
Roan Kattouw 3611664663 Update VE core submodule to master (7d2a68e)
New changes:
0ceafd5 Fix V8 deopt for ve.ce.BranchNode#onSplice
01d2d4b [BREAKING CHANGE] Store originalDomElements instead of htmlAttributes
96005a7 Localisation updates from https://translatewiki.net.
42e672e ve.ui.Toolbar: Don't call #updateToolState from #initialize
373562d Localisation updates from https://translatewiki.net.

Local changes:
Update for htmlAttributes going away

Change-Id: I576a1e5d5883b03d1fff6666926f80a5682a280f
2015-02-18 15:35:46 -08:00

64 lines
1.8 KiB
JavaScript

/*!
* VisualEditor DataModel MWNowikiAnnotation class.
*
* @copyright 2011-2015 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 = dataElement.originalDomElements,
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 );