Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/133236
Change subject: Create phantom/shield nodes with methods not templates
......................................................................
Create phantom/shield nodes with methods not templates
Templates have the following problems:
* Static, so don't have access to this.*, hence the
importNode hack.
* Run on file node, so potential load order issues
with things like ve.msg.
Change-Id: Ia7f6a2b7ac10b111bcd7245aa96c8ec9bfb183fb
---
M modules/ve/ce/nodes/ve.ce.AlienNode.js
M modules/ve/ce/ve.ce.ProtectedNode.js
2 files changed, 33 insertions(+), 26 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/36/133236/1
diff --git a/modules/ve/ce/nodes/ve.ce.AlienNode.js
b/modules/ve/ce/nodes/ve.ce.AlienNode.js
index 6af1e09..fb2515e 100644
--- a/modules/ve/ce/nodes/ve.ce.AlienNode.js
+++ b/modules/ve/ce/nodes/ve.ce.AlienNode.js
@@ -42,12 +42,21 @@
ve.ce.AlienNode.static.name = 'alien';
-ve.ce.AlienNode.static.$phantomTemplate =
ve.ce.AlienNode.static.$phantomTemplate.clone()
- .addClass( 've-ce-alienNode-phantom' )
- .attr( 'title', ve.msg( 'visualeditor-aliennode-tooltip' ) );
-
/* Methods */
+/**
+ * @inheritDoc
+ */
+ve.ce.AlienNode.prototype.createPhantom = function () {
+ // Mixin method
+ return ve.ce.ProtectedNode.prototype.createPhantom.call( this )
+ .addClass( 've-ce-alienNode-phantom' )
+ .attr( 'title', ve.msg( 'visualeditor-aliennode-tooltip' ) );
+};
+
+/**
+ * @inheritDoc
+ */
ve.ce.AlienNode.prototype.generateContents = function ( config ) {
var deferred = $.Deferred();
deferred.resolve( ( config && config.domElements ) ||
this.model.getAttribute( 'domElements' ) || [] );
diff --git a/modules/ve/ce/ve.ce.ProtectedNode.js
b/modules/ve/ce/ve.ce.ProtectedNode.js
index 3411e7e..f3342ca 100644
--- a/modules/ve/ce/ve.ce.ProtectedNode.js
+++ b/modules/ve/ce/ve.ce.ProtectedNode.js
@@ -34,31 +34,31 @@
ve.ce.ProtectedNode.static = {};
+/* Methods */
+
/**
- * Template for shield elements.
+ * Create a shield element.
*
* Uses data URI to inject a 1x1 transparent GIF image into the DOM.
*
- * @property {jQuery}
- * @static
- * @inheritable
+ * @returns {jQuery} A shield element
*/
-ve.ce.ProtectedNode.static.$shieldTemplate = $( '<img>' )
- .addClass( 've-ce-protectedNode-shield' )
- .attr( 'src',
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
);
+ve.ce.ProtectedNode.prototype.createShield = function () {
+ return this.$( '<img>' )
+ .addClass( 've-ce-protectedNode-shield' )
+ .attr( 'src',
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
);
+};
/**
- * Phantom element template.
+ * Create a phantom element.
*
- * @property {jQuery}
- * @static
- * @inheritable
+ * @returns {jQuery} A phantom element
*/
-ve.ce.ProtectedNode.static.$phantomTemplate = $( '<div>' )
- .addClass( 've-ce-protectedNode-phantom' )
- .attr( 'draggable', false );
-
-/* Methods */
+ve.ce.ProtectedNode.prototype.createPhantom = function () {
+ return this.$( '<div>' )
+ .addClass( 've-ce-protectedNode-phantom' )
+ .attr( 'draggable', false );
+};
/**
* Handle setup events.
@@ -67,8 +67,7 @@
*/
ve.ce.ProtectedNode.prototype.onProtectedSetup = function () {
var $shield,
- node = this,
- $shieldTemplate = this.constructor.static.$shieldTemplate;
+ node = this;
// Exit if already setup or not unattached
if ( this.isSetup || !this.root ) {
@@ -97,7 +96,7 @@
) {
return;
}
- $shield = node.$( node.$.context.importNode(
$shieldTemplate[0], true ) )
+ $shield = node.createShield()
.appendTo( $this )
.on( 'dblclick', function () {
node.emit( 'dblclick' );
@@ -219,14 +218,13 @@
* @method
*/
ve.ce.ProtectedNode.prototype.createPhantoms = function () {
- var $phantomTemplate = this.constructor.static.$phantomTemplate,
- surface = this.root.getSurface(),
+ var surface = this.root.getSurface(),
node = this;
this.$phantomable.find( '.ve-ce-protectedNode-shield:visible' ).each(
ve.bind( function () {
this.$phantoms = this.$phantoms.add(
- this.$( this.$.context.importNode(
$phantomTemplate[0], true ) )
+ this.createPhantom()
.on( 'mousedown', ve.bind(
this.onPhantomMouseDown, this ) )
.on( 'dblclick', function () {
node.emit( 'dblclick' );
--
To view, visit https://gerrit.wikimedia.org/r/133236
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia7f6a2b7ac10b111bcd7245aa96c8ec9bfb183fb
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits