2013-01-25 04:09:53 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel AlienNode, AlienBlockNode and AlienInlineNode classes.
|
|
|
|
*
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
2013-01-25 04:09:53 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel alien node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2013-04-03 18:21:10 +00:00
|
|
|
* @extends ve.dm.GeneratedContentNode
|
2013-01-25 04:09:53 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {number} [length] Length of content data in document; ignored and overridden to 0
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
2013-03-06 22:44:18 +00:00
|
|
|
ve.dm.AlienNode = function VeDmAlienNode( length, element ) {
|
2013-01-25 04:09:53 +00:00
|
|
|
// Parent constructor
|
2013-04-03 18:21:10 +00:00
|
|
|
ve.dm.GeneratedContentNode.call( this, 0, element );
|
2013-01-25 04:09:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-04-03 18:21:10 +00:00
|
|
|
ve.inheritClass( ve.dm.AlienNode, ve.dm.GeneratedContentNode );
|
2013-01-25 04:09:53 +00:00
|
|
|
|
|
|
|
/* Static members */
|
|
|
|
|
|
|
|
ve.dm.AlienNode.static.name = 'alien';
|
|
|
|
|
2013-02-16 01:42:25 +00:00
|
|
|
ve.dm.AlienNode.static.storeHtmlAttributes = false;
|
|
|
|
|
2013-02-16 02:37:50 +00:00
|
|
|
ve.dm.AlienNode.static.toDataElement = function ( domElements, context ) {
|
|
|
|
var i, isInline, allTagsInline, type, html;
|
|
|
|
// Check whether all elements are inline elements
|
|
|
|
allTagsInline = true;
|
|
|
|
for ( i = 0; i < domElements.length; i++ ) {
|
|
|
|
if ( ve.isBlockElement( domElements[i] ) ) {
|
|
|
|
allTagsInline = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-25 04:09:53 +00:00
|
|
|
// We generate alienBlock elements for block tags and alienInline elements for
|
|
|
|
// inline tags; unless we're in a content location, in which case we have no choice
|
|
|
|
// but to generate an alienInline element.
|
2013-02-16 02:37:50 +00:00
|
|
|
isInline =
|
|
|
|
// Force inline in content locations (but not wrappers)
|
|
|
|
( context.expectingContent && !context.inWrapper ) ||
|
|
|
|
// Also force inline in wrappers that we can't close
|
|
|
|
( context.inWrapper && !context.canCloseWrapper ) ||
|
|
|
|
// Look at the tag names otherwise
|
|
|
|
allTagsInline;
|
|
|
|
type = isInline ? 'alienInline' : 'alienBlock';
|
|
|
|
html = $( '<div>', domElements[0].ownerDocument ).append( $( domElements ).clone() ).html();
|
2013-01-25 04:09:53 +00:00
|
|
|
return {
|
|
|
|
'type': type,
|
|
|
|
'attributes': {
|
|
|
|
'html': html
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-04-02 20:23:16 +00:00
|
|
|
ve.dm.AlienNode.static.toDomElements = function ( dataElement, doc ) {
|
|
|
|
var wrapper = doc.createElement( 'div' );
|
2013-01-25 04:09:53 +00:00
|
|
|
wrapper.innerHTML = dataElement.attributes.html;
|
2013-02-16 02:37:50 +00:00
|
|
|
// Convert wrapper.children to an array
|
|
|
|
return Array.prototype.slice.call( wrapper.childNodes, 0 );
|
2013-01-25 04:09:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Concrete subclasses */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel alienBlock node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.AlienNode
|
|
|
|
* @constructor
|
|
|
|
* @param {number} [length] Length of content data in document; ignored and overridden to 0
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
|
|
|
ve.dm.AlienBlockNode = function VeDmAlienBlockNode( length, element ) {
|
|
|
|
// Parent constructor
|
2013-03-06 22:44:18 +00:00
|
|
|
ve.dm.AlienNode.call( this, length, element );
|
2013-01-25 04:09:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.inheritClass( ve.dm.AlienBlockNode, ve.dm.AlienNode );
|
|
|
|
|
|
|
|
ve.dm.AlienBlockNode.static.name = 'alienBlock';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel alienInline node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.AlienNode
|
|
|
|
* @constructor
|
|
|
|
* @param {number} [length] Length of content data in document; ignored and overridden to 0
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
|
|
|
ve.dm.AlienInlineNode = function VeDmAlienInlineNode( length, element ) {
|
|
|
|
// Parent constructor
|
2013-03-06 22:44:18 +00:00
|
|
|
ve.dm.AlienNode.call( this, length, element );
|
2013-01-25 04:09:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.inheritClass( ve.dm.AlienInlineNode, ve.dm.AlienNode );
|
|
|
|
|
|
|
|
ve.dm.AlienInlineNode.static.name = 'alienInline';
|
|
|
|
|
|
|
|
ve.dm.AlienInlineNode.static.isContent = true;
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.AlienNode );
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.AlienBlockNode );
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.AlienInlineNode );
|