Inez has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/72113


Change subject: Performance optimizations for ve.ce.ProtectedNode
......................................................................

Performance optimizations for ve.ce.ProtectedNode

* shields are create in mouseenter handler instead of setup handler
* phantoms are created based on the shields collection instead of another one 
call to jQuery.find

Change-Id: I4f0803eadac9914053cb880c4198906f4a05769d
---
M modules/ve/ce/ve.ce.ProtectedNode.js
1 file changed, 34 insertions(+), 21 deletions(-)


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

diff --git a/modules/ve/ce/ve.ce.ProtectedNode.js 
b/modules/ve/ce/ve.ce.ProtectedNode.js
index 329b5bf..a8bc4ca 100644
--- a/modules/ve/ce/ve.ce.ProtectedNode.js
+++ b/modules/ve/ce/ve.ce.ProtectedNode.js
@@ -18,6 +18,7 @@
        this.$phantoms = $( [] );
        this.$shields = $( [] );
        this.isSetup = false;
+       this.areShieldsSetup = false;
 
        // Events
        this.connect( this, {
@@ -65,10 +66,6 @@
  * @method
  */
 ve.ce.ProtectedNode.prototype.onProtectedSetup = function () {
-       var $shield,
-               node = this,
-               $shieldTemplate = this.constructor.static.$shieldTemplate;
-
        // Exit if already setup or not unattached
        if ( this.isSetup || !this.root ) {
                return;
@@ -80,21 +77,6 @@
                .connect( this, { 'change': 'onSurfaceModelChange' } );
        this.getRoot().getSurface().getSurface()
                .connect( this, { 'toolbarPosition': 'positionPhantoms' } );
-
-       // Shields
-       this.$.add( this.$.find( '*' ) ).each( function () {
-               var $this = $( this );
-               if ( this.nodeType === Node.ELEMENT_NODE ) {
-                       if (
-                               ( $this.css( 'float' ) === 'none' || $this.css( 
'float' ) === '' ) &&
-                               !$this.hasClass( 've-ce-protectedNode' )
-                       ) {
-                               return;
-                       }
-                       $shield = $shieldTemplate.clone().appendTo( $this );
-                       node.$shields = node.$shields.add( $shield );
-               }
-       } );
 
        this.isSetup = true;
 };
@@ -155,6 +137,9 @@
  * @method
  */
 ve.ce.ProtectedNode.prototype.onProtectedMouseEnter = function () {
+       if ( !this.areShieldsSetup ) {
+               this.setupShields();
+       }
        if ( !this.root.getSurface().dragging ) {
                this.createPhantoms();
        }
@@ -200,6 +185,34 @@
 };
 
 /**
+ * Setup shields
+ *
+ * @method
+ */
+ve.ce.ProtectedNode.prototype.setupShields = function () {
+       var $shield,
+               node = this,
+               $shieldTemplate = this.constructor.static.$shieldTemplate;
+
+       // Shields
+       this.$.add( this.$.find( '*' ) ).each( function () {
+               var $this = $( this );
+               if ( this.nodeType === Node.ELEMENT_NODE ) {
+                       if (
+                               ( $this.css( 'float' ) === 'none' || $this.css( 
'float' ) === '' ) &&
+                               !$this.hasClass( 've-ce-protectedNode' )
+                       ) {
+                               return;
+                       }
+                       $shield = $shieldTemplate.clone().appendTo( $this );
+                       node.$shields = node.$shields.add( $shield );
+               }
+       } );
+
+       this.areShieldsSetup = true;
+};
+
+/**
  * Creates phantoms
  *
  * @method
@@ -208,7 +221,7 @@
        var $phantomTemplate = this.constructor.static.$phantomTemplate,
                surface = this.root.getSurface();
 
-       this.$.find( '.ve-ce-protectedNode-shield' ).each(
+       this.$shields.each(
                ve.bind( function () {
                        this.$phantoms = this.$phantoms.add(
                                $phantomTemplate.clone().on( 'mousedown', 
ve.bind( this.onPhantomMouseDown, this ) )
@@ -230,7 +243,7 @@
  * @method
  */
 ve.ce.ProtectedNode.prototype.positionPhantoms = function () {
-       this.$.find( '.ve-ce-protectedNode-shield' ).each(
+       this.$shields.each(
                ve.bind( function ( i, element ) {
                        var $shield = $( element ),
                                offset = ve.Element.getRelativePosition(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f0803eadac9914053cb880c4198906f4a05769d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Inez <i...@wikia-inc.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to