Jdlrobson has uploaded a new change for review.

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

Change subject: Hygiene: Refactor insertion of survey panel
......................................................................

Hygiene: Refactor insertion of survey panel

Repurpose the function and document it so code is easier to follow.

Change-Id: I815fb8c8e450acc6b0f2778d437c905bcf86b663
---
M resources/ext.quicksurveys.init/init.js
1 file changed, 20 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys 
refs/changes/40/236040/1

diff --git a/resources/ext.quicksurveys.init/init.js 
b/resources/ext.quicksurveys.init/init.js
index a698763..5062ee1 100644
--- a/resources/ext.quicksurveys.init/init.js
+++ b/resources/ext.quicksurveys.init/init.js
@@ -1,5 +1,5 @@
 ( function ( $ ) {
-       var survey, $bodyContent, $place,
+       var survey,
                $panel = $( '<div class="ext-qs-loader-bar 
mw-ajax-loader"></div>' ),
                enabledSurveys = mw.config.get( 'wgEnabledQuickSurveys' ),
                isMainPage = mw.config.get( 'wgIsMainPage' ),
@@ -22,6 +22,24 @@
                } );
        } else {
                showSurvey();
+       }
+
+       /**
+        * Insert the quick survey panel into the article either (in priority 
order)
+        * before the first instance of a thumbnail,
+        * before the first instance of a heading
+        * or at the end of the article when no headings nor thumbnails exist
+        * @param {jQuery.Object} $panel
+        */
+       function insertPanel( $panel ) {
+               var $bodyContent = $( '.mw-content-ltr, .mw-content-rtl' ),
+                       $place = $bodyContent.find( '> .thumb, > h1, > h2, > 
h3, > h4, > h5, > h6' ).eq( 0 );
+
+               if ( $place.length ) {
+                       $panel.insertBefore( $place );
+               } else {
+                       $panel.appendTo( $bodyContent );
+               }
        }
 
        /**
@@ -52,14 +70,7 @@
                if ( availableSurveys.length ) {
                        // Get a random available survey
                        survey = availableSurveys[ Math.floor( Math.random() * 
availableSurveys.length ) ];
-                       $bodyContent = $( '.mw-content-ltr, .mw-content-rtl' );
-                       $place = $bodyContent.find( '> .thumb, > h1, > h2, > 
h3, > h4, > h5, > h6' ).eq( 0 );
-
-                       if ( $place.length ) {
-                               $panel.insertBefore( $place );
-                       } else {
-                               $panel.appendTo( $bodyContent );
-                       }
+                       insertPanel( $panel );
                        // survey.module contains i18n messages
                        mw.loader.using( [ 'ext.quicksurveys.views', 
survey.module ] ).done( function () {
                                var panel,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I815fb8c8e450acc6b0f2778d437c905bcf86b663
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: dev
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

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

Reply via email to