Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232741
Change subject: Override GeneratedContentNodes methods at a lower level
......................................................................
Override GeneratedContentNodes methods at a lower level
We really need generated content node features such as caching, or
MWExtensionNode features such as fetching contents from the server.
Override #update directly so none of this happens.
As a result we don't need to listen to change events from the model.
Change-Id: Ifb53d877c476247f9865c82e3cd63b19b5f3ad76
---
M modules/VisualEditor/ve.ce.MWGraphNode.js
M modules/VisualEditor/ve.dm.MWGraphNode.js
2 files changed, 16 insertions(+), 71 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph
refs/changes/41/232741/1
diff --git a/modules/VisualEditor/ve.ce.MWGraphNode.js
b/modules/VisualEditor/ve.ce.MWGraphNode.js
index a86d280..3b200a2 100644
--- a/modules/VisualEditor/ve.ce.MWGraphNode.js
+++ b/modules/VisualEditor/ve.ce.MWGraphNode.js
@@ -17,6 +17,8 @@
ve.ce.MWGraphNode = function VeCeMWGraphNode() {
// Parent constructor
ve.ce.MWGraphNode.super.apply( this, arguments );
+
+ this.$element.addClass( 'mw-wiki-graph-container' );
};
/* Inheritance */
@@ -28,6 +30,8 @@
ve.ce.MWGraphNode.static.name = 'mwGraph';
ve.ce.MWGraphNode.static.primaryCommandName = 'graph';
+
+ve.ce.MWGraphNode.static.tagName = 'div';
/* Static Methods */
@@ -41,6 +45,7 @@
*/
ve.ce.MWGraphNode.static.vegaParseSpec = function ( spec, $node ) {
var deferred = $.Deferred(),
+ node = this,
canvasNode;
// Check if the spec is currently valid
@@ -53,7 +58,7 @@
// Once Vega allows for proper rendering
validation, this should be
// swapped for a validation check.
canvasNode = $node[0].children[0].children[0];
- if ( ve.ce.MWGraphNode.static.isCanvasBlank(
canvasNode ) ) {
+ if ( node.isCanvasBlank( canvasNode ) ) {
deferred.reject(
'graph-ve-vega-error-no-render' );
} else {
deferred.resolve();
@@ -75,7 +80,7 @@
*
* @author Austin Brunkhorst http://stackoverflow.com/a/17386803/2055594
* @param {HTMLElement} canvas The canvas to Check
- * @return True if the canvas is blank, False otherwise
+ * @return {booean} The canvas is blank
*/
ve.ce.MWGraphNode.static.isCanvasBlank = function ( canvas ) {
var blank = document.createElement( 'canvas' );
@@ -89,61 +94,20 @@
/* Methods */
/**
- * @inheritdoc
- */
-ve.ce.MWGraphNode.prototype.onSetup = function () {
- // Parent method
- ve.ce.MWGraphNode.super.prototype.onSetup.call( this );
-
- // Events
- this.getModel().connect( this, {
- specChange: 'onSpecChange'
- } );
-
- // Initial rendering
- this.renderGraph();
-};
-
-/**
- * @inheritdoc
- */
-ve.ce.MWGraphNode.prototype.onTeardown = function () {
- // Parent method
- ve.ce.MWGraphNode.super.prototype.onTeardown.call( this );
-
- // Events
- this.getModel().disconnect( this );
-};
-
-/**
* Render a Vega graph inside the node
- *
- * @private
- * @return {jQuery.Promise} Promise that resolves when the graph is rendered.
- * The promise is rejected if there was a problem rendering the graph.
*/
-ve.ce.MWGraphNode.prototype.renderGraph = function () {
- var element = this.$element[0],
- spec = this.getModel().getSpec();
+ve.ce.MWGraphNode.prototype.update = function () {
+ var node = this;
// Clear element
this.$element.empty();
- return ve.ce.MWGraphNode.static.vegaParseSpec( spec, this.$element
).then(
+ this.constructor.static.vegaParseSpec( this.getModel().getSpec(),
this.$element ).then(
null,
function ( failMessageKey ) {
- $( element ).text( ve.msg( failMessageKey ) );
+ node.$element.text( ve.msg( failMessageKey ) );
}
);
-};
-
-/**
- * React to specification model update
- *
- * @private
- */
-ve.ce.MWGraphNode.prototype.onSpecChange = function () {
- this.renderGraph();
};
/* Registration */
diff --git a/modules/VisualEditor/ve.dm.MWGraphNode.js
b/modules/VisualEditor/ve.dm.MWGraphNode.js
index d456457..06a8724 100644
--- a/modules/VisualEditor/ve.dm.MWGraphNode.js
+++ b/modules/VisualEditor/ve.dm.MWGraphNode.js
@@ -8,7 +8,7 @@
* DataModel MediaWiki graph node.
*
* @class
- * @extends ve.dm.MWInlineExtensionNode
+ * @extends ve.dm.MWBlockExtensionNode
*
* @constructor
* @param {Object} [element]
@@ -39,7 +39,7 @@
/* Inheritance */
-OO.inheritClass( ve.dm.MWGraphNode, ve.dm.MWInlineExtensionNode );
+OO.inheritClass( ve.dm.MWGraphNode, ve.dm.MWBlockExtensionNode );
/* Static Members */
@@ -48,16 +48,6 @@
ve.dm.MWGraphNode.static.tagName = 'graph';
ve.dm.MWGraphNode.static.extensionName = 'graph';
-
-/* Events */
-
-/**
- * @event specChange
- *
- * Change when the specification object is updated
- *
- * @param {Object} The new specification object
- */
/* Static Methods */
@@ -104,7 +94,7 @@
* @return {string} The specification JSON string
*/
ve.dm.MWGraphNode.prototype.getSpecString = function () {
- return ve.dm.MWGraphNode.static.stringifySpec( this.spec );
+ return this.constructor.static.stringifySpec( this.spec );
};
/**
@@ -120,27 +110,19 @@
* Set the specificiation
*
* @param {Object} spec The new spec
- * @fires specChange
*/
ve.dm.MWGraphNode.prototype.setSpec = function ( spec ) {
// Consolidate all falsy values to an empty object for consistency
- spec = spec || {};
-
- // Check if there are any actual changes
- if ( !OO.compare( this.spec, spec ) ) {
- this.spec = spec;
- this.emit( 'specChange', this.spec );
- }
+ this.spec = spec || {};
};
/**
* Set the specification from a stringified version
*
* @param {string} str The new specification JSON string
- * @fires specChange
*/
ve.dm.MWGraphNode.prototype.setSpecFromString = function ( str ) {
- this.setSpec( ve.dm.MWGraphNode.static.parseSpecString( str ) );
+ this.setSpec( this.constructor.static.parseSpecString( str ) );
};
/**
@@ -149,7 +131,6 @@
* @param {string} attributeName The attribute being updated
* @param {Object} from The old value of the attribute
* @param {Object} to The new value of the attribute
- * @fires specChange
*/
ve.dm.MWGraphNode.prototype.onAttributeChange = function ( attributeName,
from, to ) {
if ( attributeName === 'mw' ) {
--
To view, visit https://gerrit.wikimedia.org/r/232741
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb53d877c476247f9865c82e3cd63b19b5f3ad76
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Graph
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits