Split nodes into block/inline

Bug: T103963
Change-Id: Ib0390d6432fe97810988be3aca59ba38c0d55b64
This commit is contained in:
Ed Sanders 2015-09-16 17:23:02 +01:00
parent 196c6aca20
commit 8212ef5609
4 changed files with 93 additions and 20 deletions

View file

@ -9,20 +9,16 @@
* ContentEditable MediaWiki syntax highlight node.
*
* @class
* @extends ve.ce.MWBlockExtensionNode
* @abstract
*
* @constructor
* @param {ve.dm.MWSyntaxHighlightNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWSyntaxHighlightNode = function VeCeMWSyntaxHighlightNode() {
// Parent constructor
ve.ce.MWSyntaxHighlightNode.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWSyntaxHighlightNode, ve.ce.MWBlockExtensionNode );
OO.initClass( ve.ce.MWSyntaxHighlightNode );
/* Static Properties */
@ -38,13 +34,13 @@ ve.ce.MWSyntaxHighlightNode.prototype.generateContents = function () {
return $.Deferred().reject().promise();
}
// Parent method
return ve.ce.MWSyntaxHighlightNode.super.prototype.generateContents.apply( this, arguments );
return ve.ce.MWExtensionNode.prototype.generateContents.apply( this, arguments );
};
/** */
ve.ce.MWSyntaxHighlightNode.prototype.onSetup = function () {
// Parent method
ve.ce.MWSyntaxHighlightNode.super.prototype.onSetup.call( this );
ve.ce.MWExtensionNode.prototype.onSetup.call( this );
// DOM changes
this.$element.addClass( 've-ce-mwSyntaxHighlightNode' );
@ -54,9 +50,40 @@ ve.ce.MWSyntaxHighlightNode.prototype.onSetup = function () {
ve.ce.MWSyntaxHighlightNode.prototype.getBoundingRect = function () {
// HACK: Because nodes can overflow due to the pre tag, just use the
// first rect (of the wrapper div) for placing the context.
return this.rects[0];
return this.rects[ 0 ];
};
/* Concrete subclasses */
ve.ce.MWBlockSyntaxHighlightNode = function VeCeMWBlockSyntaxHighlightNode() {
// Parent method
ve.ce.MWBlockExtensionNode.super.apply( this, arguments );
// Mixin method
ve.ce.MWSyntaxHighlightNode.call( this );
};
OO.inheritClass( ve.ce.MWBlockSyntaxHighlightNode, ve.ce.MWBlockExtensionNode );
OO.mixinClass( ve.ce.MWBlockSyntaxHighlightNode, ve.ce.MWSyntaxHighlightNode );
ve.ce.MWBlockSyntaxHighlightNode.static.name = 'mwBlockSyntaxHighlight';
ve.ce.MWInlineSyntaxHighlightNode = function VeCeMWInlineSyntaxHighlightNode() {
// Parent method
ve.ce.MWInlineExtensionNode.super.apply( this, arguments );
// Mixin method
ve.ce.MWSyntaxHighlightNode.call( this );
};
OO.inheritClass( ve.ce.MWInlineSyntaxHighlightNode, ve.ce.MWInlineExtensionNode );
OO.mixinClass( ve.ce.MWInlineSyntaxHighlightNode, ve.ce.MWSyntaxHighlightNode );
ve.ce.MWInlineSyntaxHighlightNode.static.name = 'mwInlineSyntaxHighlight';
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWSyntaxHighlightNode );
ve.ce.nodeFactory.register( ve.ce.MWBlockSyntaxHighlightNode );
ve.ce.nodeFactory.register( ve.ce.MWInlineSyntaxHighlightNode );

View file

@ -9,26 +9,21 @@
* DataModel MediaWiki syntax highlight node.
*
* @class
* @extends ve.dm.MWBlockExtensionNode
* @abstract
*
* @constructor
* @param {Object} [element]
*/
ve.dm.MWSyntaxHighlightNode = function VeDmMWSyntaxHighlightNode() {
// Parent constructor
ve.dm.MWSyntaxHighlightNode.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.dm.MWSyntaxHighlightNode, ve.dm.MWBlockExtensionNode );
OO.initClass( ve.dm.MWSyntaxHighlightNode );
/* Static members */
ve.dm.MWSyntaxHighlightNode.static.name = 'mwSyntaxHighlight';
ve.dm.MWSyntaxHighlightNode.static.tagName = 'div';
ve.dm.MWSyntaxHighlightNode.static.extensionName = 'syntaxhighlight';
ve.dm.MWSyntaxHighlightNode.static.getMatchRdfaTypes = function () {
@ -37,6 +32,20 @@ ve.dm.MWSyntaxHighlightNode.static.getMatchRdfaTypes = function () {
/* Static methods */
/**
* @inheritdoc
*/
ve.dm.MWSyntaxHighlightNode.static.toDataElement = function ( domElements, converter ) {
// Parent method
var dataElement = ve.dm.MWExtensionNode.static.toDataElement( domElements, converter ),
isInline = this.isHybridInline( domElements, converter ),
type = isInline ? 'mwInlineSyntaxHighlight' : 'mwBlockSyntaxHighlight';
dataElement.type = type;
return dataElement;
};
( function () {
var supportedLanguages = [];
@ -84,6 +93,43 @@ ve.dm.MWSyntaxHighlightNode.prototype.getLanguage = function () {
return this.getAttribute( 'mw' ).attrs.lang;
};
/* Concrete subclasses */
ve.dm.MWBlockSyntaxHighlightNode = function VeDmMWBlockSyntaxHighlightNode() {
// Parent method
ve.dm.MWBlockExtensionNode.super.apply( this, arguments );
// Mixin method
ve.dm.MWSyntaxHighlightNode.call( this );
};
OO.inheritClass( ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWBlockExtensionNode );
OO.mixinClass( ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWSyntaxHighlightNode );
ve.dm.MWBlockSyntaxHighlightNode.static.name = 'mwBlockSyntaxHighlight';
ve.dm.MWBlockSyntaxHighlightNode.static.tagName = 'div';
ve.dm.MWInlineSyntaxHighlightNode = function VeDmMWInlineSyntaxHighlightNode() {
// Parent method
ve.dm.MWInlineExtensionNode.super.apply( this, arguments );
// Mixin method
ve.dm.MWSyntaxHighlightNode.call( this );
};
OO.inheritClass( ve.dm.MWInlineSyntaxHighlightNode, ve.dm.MWInlineExtensionNode );
OO.mixinClass( ve.dm.MWInlineSyntaxHighlightNode, ve.dm.MWSyntaxHighlightNode );
ve.dm.MWInlineSyntaxHighlightNode.static.name = 'mwInlineSyntaxHighlight';
ve.dm.MWInlineSyntaxHighlightNode.static.tagName = 'code';
ve.dm.MWInlineSyntaxHighlightNode.static.isContent = true;
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWSyntaxHighlightNode );
ve.dm.modelRegistry.register( ve.dm.MWBlockSyntaxHighlightNode );
ve.dm.modelRegistry.register( ve.dm.MWInlineSyntaxHighlightNode );

View file

@ -33,7 +33,7 @@ ve.ui.MWSyntaxHighlightInspector.static.size = 'large';
ve.ui.MWSyntaxHighlightInspector.static.title = OO.ui.deferMsg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title' );
ve.ui.MWSyntaxHighlightInspector.static.modelClasses = [ ve.dm.MWSyntaxHighlightNode ];
ve.ui.MWSyntaxHighlightInspector.static.modelClasses = [ ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWInlineSyntaxHighlightNode ];
ve.ui.MWSyntaxHighlightInspector.static.dir = 'ltr';

View file

@ -25,7 +25,7 @@ ve.ui.MWSyntaxHighlightInspectorTool.static.group = 'object';
ve.ui.MWSyntaxHighlightInspectorTool.static.icon = 'alienextension';
ve.ui.MWSyntaxHighlightInspectorTool.static.title = OO.ui.deferMsg(
'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title' );
ve.ui.MWSyntaxHighlightInspectorTool.static.modelClasses = [ ve.dm.MWSyntaxHighlightNode ];
ve.ui.MWSyntaxHighlightInspectorTool.static.modelClasses = [ ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWInlineSyntaxHighlightNode ];
ve.ui.MWSyntaxHighlightInspectorTool.static.commandName = 'syntaxhighlight';
ve.ui.toolFactory.register( ve.ui.MWSyntaxHighlightInspectorTool );