Legoktm has uploaded a new change for review.

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

Change subject: Makes sure that the zoom widget is initialized before zooming 
in/out
......................................................................

Makes sure that the zoom widget is initialized before zooming in/out

Initialized lazily the zoom widget

Change-Id: Ia92b41716b3fde4b5e3aeb8c82f5f8e8d012f620
(cherry picked from commit 4a8398ad4b32d72483cd60a203f5496be8538b53)
---
M modules/page/ext.proofreadpage.page.edit.js
1 file changed, 27 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/65/311765/1

diff --git a/modules/page/ext.proofreadpage.page.edit.js 
b/modules/page/ext.proofreadpage.page.edit.js
index 874f9e7..8d7b1fc 100644
--- a/modules/page/ext.proofreadpage.page.edit.js
+++ b/modules/page/ext.proofreadpage.page.edit.js
@@ -30,6 +30,23 @@
        }
 
        /**
+        * Ensure that the zoom system is properly initialized
+     *
+        * @param {Function} callback a function to use after making sure that 
the zoom system is activate
+        */
+       function withImageZoom( callback ) {
+               if ( $zoomImage.data( 'prpZoom' ) ) {
+                       callback();
+                       return;
+               }
+
+               mw.loader.using( 'jquery.prpZoom', function () {
+                       $zoomImage.prpZoom();
+                       callback();
+               } );
+       }
+
+       /**
         * Show or hide header and footer areas
         *
         * @param {string} speed string speed of the toggle. May be 'fast', 
'slow' or undefined
@@ -61,8 +78,6 @@
                                width: ''
                        } );
 
-                       $zoomImage.prpZoom();
-
                        isLayoutHorizontal = false;
 
                } else {
@@ -77,7 +92,6 @@
                                width: '100%'
                        } );
 
-                       $zoomImage.prpZoom();
                        $container.css( {
                                height: $( window ).height() / 3 + 'px'
                        } );
@@ -127,7 +141,9 @@
                                                        action: {
                                                                type: 
'callback',
                                                                execute: 
function () {
-                                                                       
$zoomImage.prpZoom( 'zoomIn' );
+                                                                       
withImageZoom( function () {
+                                                                               
$zoomImage.prpZoom( 'zoomIn' );
+                                                                       } );
                                                                }
                                                        }
                                                },
@@ -139,7 +155,9 @@
                                                        action: {
                                                                type: 
'callback',
                                                                execute: 
function () {
-                                                                       
$zoomImage.prpZoom( 'zoomOut' );
+                                                                       
withImageZoom( function () {
+                                                                               
$zoomImage.prpZoom( 'zoomOut' );
+                                                                       } );
                                                                }
                                                        }
                                                },
@@ -151,7 +169,9 @@
                                                        action: {
                                                                type: 
'callback',
                                                                execute: 
function () {
-                                                                       
$zoomImage.prpZoom( 'reset' );
+                                                                       
withImageZoom( function () {
+                                                                               
$zoomImage.prpZoom( 'reset' );
+                                                                       } );
                                                                }
                                                        }
                                                }
@@ -247,27 +267,12 @@
                }
        }
 
-       /**
-        * Init the zoom system
-        */
-       function initZoom() {
-               mw.loader.using( 'jquery.prpZoom', function () {
-                       $zoomImage.prpZoom();
-               } );
-       }
-
-       $( document ).ready( function () {
+       $( function () {
                initEnvironment();
                setupWikiEditor();
                setupPreferences();
                setupPageQuality();
                addButtons();
-       } );
-
-       // zoom should be init after the page is rendered
-       $( window ).load( function () {
-               initEnvironment();
-               initZoom();
        } );
 
 }( mw, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia92b41716b3fde4b5e3aeb8c82f5f8e8d012f620
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: wmf/1.28.0-wmf.18
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Tpt <thoma...@hotmail.fr>

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

Reply via email to