Esanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351106 )

Change subject: MWSignatureNode/Tool: Avoid global variables
......................................................................

MWSignatureNode/Tool: Avoid global variables

Change-Id: I0596b33e797830f3718f4edbe34075fdaced0831
---
M modules/ve-mw/ce/nodes/ve.ce.MWSignatureNode.js
M modules/ve-mw/ui/tools/ve.ui.MWSignatureTool.js
2 files changed, 54 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/06/351106/1

diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWSignatureNode.js 
b/modules/ve-mw/ce/nodes/ve.ce.MWSignatureNode.js
index 4989eef..cdf65da 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWSignatureNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWSignatureNode.js
@@ -5,23 +5,6 @@
  * @license The MIT License (MIT); see LICENSE.txt
  */
 
-// Update the timestamp on inserted signatures every minute.
-var liveSignatures = [];
-setInterval( function () {
-       var updatedSignatures, i, sig;
-       updatedSignatures = [];
-       for ( i = 0; i < liveSignatures.length; i++ ) {
-               sig = liveSignatures[ i ];
-               try {
-                       sig.forceUpdate();
-                       updatedSignatures.push( sig );
-               } catch ( er ) {
-                       // Do nothing
-               }
-       }
-       liveSignatures = updatedSignatures;
-}, 60 * 1000 );
-
 /**
  * ContentEditable MediaWiki signature node. This defines the behavior of the 
signature node
  * inserted into the ContentEditable document.
@@ -45,9 +28,6 @@
                // the width changing when using the Sequence.
                this.$element.text( '~~~~' );
        }
-
-       // Keep track for magical text updating
-       liveSignatures.push( this );
 };
 
 /* Inheritance */
@@ -62,11 +42,59 @@
 
 ve.ce.MWSignatureNode.static.primaryCommandName = 'mwSignature';
 
+ve.ce.MWSignatureNode.static.liveSignatures = [];
+
+// Update the timestamp on inserted signatures every minute.
+setInterval( function () {
+       var updatedSignatures, i, sig,
+               liveSignatures = ve.ce.MWSignatureNode.static.liveSignatures;
+
+       updatedSignatures = [];
+       for ( i = 0; i < liveSignatures.length; i++ ) {
+               sig = liveSignatures[ i ];
+               try {
+                       sig.forceUpdate();
+                       updatedSignatures.push( sig );
+               } catch ( er ) {
+                       // Do nothing
+               }
+       }
+       liveSignatures = updatedSignatures;
+}, 60 * 1000 );
+
 /* Methods */
 
 /**
  * @inheritdoc
  */
+ve.ce.MWSignatureNode.prototype.onSetup = function () {
+       // Parent method
+       ve.ce.MWSignatureNode.super.prototype.onSetup.call( this );
+
+       // Keep track for regular updating of timestamp
+       this.constructor.static.liveSignatures.push( this );
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ce.MWSignatureNode.prototype.onTeardown = function () {
+       var index,
+               liveSignatures = this.constructor.static.liveSignatures;
+
+       // Parent method
+       ve.ce.MWSignatureNode.super.prototype.onTeardown.call( this );
+
+       // Stop tracking
+       index = liveSignatures.indexOf( this );
+       if ( index !== -1 ) {
+               liveSignatures.splice( index, 1 );
+       }
+};
+
+/**
+ * @inheritdoc
+ */
 ve.ce.MWSignatureNode.prototype.generateContents = function () {
        var wikitext, signatureNode, api, deferred, xhr;
        // Parsoid doesn't support pre-save transforms. PHP parser doesn't 
support Parsoid's
diff --git a/modules/ve-mw/ui/tools/ve.ui.MWSignatureTool.js 
b/modules/ve-mw/ui/tools/ve.ui.MWSignatureTool.js
index b50081f..f908711 100644
--- a/modules/ve-mw/ui/tools/ve.ui.MWSignatureTool.js
+++ b/modules/ve-mw/ui/tools/ve.ui.MWSignatureTool.js
@@ -5,11 +5,6 @@
  * @license The MIT License (MIT); see LICENSE.txt
  */
 
-var allowsSignatures = $.inArray(
-       new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId(),
-       mw.config.get( 'wgVisualEditorConfig' ).signatureNamespaces
-) !== -1;
-
 /**
  * MediaWiki UserInterface signature tool. This defines the menu button and 
its action.
  *
@@ -36,7 +31,12 @@
 
 ve.ui.toolFactory.register( ve.ui.MWSignatureTool );
 
-if ( allowsSignatures ) {
+if (
+       $.inArray(
+               new mw.Title( mw.config.get( 'wgRelevantPageName' ) 
).getNamespaceId(),
+               mw.config.get( 'wgVisualEditorConfig' ).signatureNamespaces
+       ) !== -1
+) {
        // Command to insert signature node.
        ve.ui.commandRegistry.register(
                new ve.ui.Command( 'mwSignature', 'content', 'insert', {

-- 
To view, visit https://gerrit.wikimedia.org/r/351106
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0596b33e797830f3718f4edbe34075fdaced0831
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to