Krinkle has uploaded a new change for review.

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

Change subject: mediawiki.page.gallery: Clean up $galleries variable
......................................................................

mediawiki.page.gallery: Clean up $galleries variable

Follows-up a50c7c4181.

Instead of initialising it to an empty object and executing wasteful
code in the other functions, keep it undefined until it is defined
and use it conditionally only.

Also:
* Add comment to justify() documentating what the 'this' context is.
* Consolidate window resize handles.
* Return early in resize handle if $galleries hasn't been initialised yet.

Change-Id: Ib93f87e71dacfd1aad8bbb7d5559e999f4f00eb3
---
M resources/src/mediawiki.page/mediawiki.page.gallery.js
1 file changed, 14 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/36/187636/1

diff --git a/resources/src/mediawiki.page/mediawiki.page.gallery.js 
b/resources/src/mediawiki.page/mediawiki.page.gallery.js
index 3658ed8..101fd42 100644
--- a/resources/src/mediawiki.page/mediawiki.page.gallery.js
+++ b/resources/src/mediawiki.page/mediawiki.page.gallery.js
@@ -4,10 +4,15 @@
  */
 ( function ( mw, $ ) {
        // Is there a better way to detect a touchscreen? Current check taken 
from stack overflow.
-       var isTouchScreen = !!( window.ontouchstart !== undefined || 
window.DocumentTouch !== undefined && document instanceof window.DocumentTouch 
),
-               $galleries = $();
+       var $galleries,
+               isTouchScreen = !!( window.ontouchstart !== undefined ||
+                       window.DocumentTouch !== undefined && document 
instanceof window.DocumentTouch
+               );
 
-       // Now on to justification.
+       /**
+        * Perform the layout justification.
+        * @context {HTMLElement} A `ul.mw-gallery-*` element
+        */
        function justify() {
                var lastTop,
                        $img,
@@ -221,6 +226,9 @@
 
        $( function () {
                $( window ).resize( $.debounce( 300, true, function () {
+                       if ( !$galleries ) {
+                               return;
+                       }
                        $galleries.children( 'li' ).each( function () {
                                var imgWidth = $( this ).data( 'imgWidth' ),
                                        imgHeight = $( this ).data( 'imgHeight' 
),
@@ -245,9 +253,9 @@
                                        $imageDiv.height( imgHeight );
                                }
                        } );
-               } ) );
-               $( window ).resize( $.debounce( 300, function () {
+
                        $galleries.each( justify );
-               } ) );
+               } );
        } );
+
 }( mediaWiki, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib93f87e71dacfd1aad8bbb7d5559e999f4f00eb3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

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

Reply via email to