diff --git a/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js b/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js index 7d03c1b7..fb5a0be6 100644 --- a/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js +++ b/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js @@ -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 ); diff --git a/modules/VisualEditor/ve.dm.MWSyntaxHighlightNode.js b/modules/VisualEditor/ve.dm.MWSyntaxHighlightNode.js index e8abb0d2..6f14a069 100644 --- a/modules/VisualEditor/ve.dm.MWSyntaxHighlightNode.js +++ b/modules/VisualEditor/ve.dm.MWSyntaxHighlightNode.js @@ -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 ); diff --git a/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js b/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js index 9821a8f2..285fccb8 100644 --- a/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js +++ b/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js @@ -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'; diff --git a/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspectorTool.js b/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspectorTool.js index b3ab5da2..1192976b 100644 --- a/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspectorTool.js +++ b/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspectorTool.js @@ -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 );