EBernhardson (WMF) has submitted this change and it was merged.

Change subject: Slightly better abide to MW jshint & coding standards; add 
docblock
......................................................................


Slightly better abide to MW jshint & coding standards; add docblock

Change-Id: I4df027cf04659a9add142236f35efe9e64a6212e
---
M includes/api/ApiFlow.php
M modules/base/ext.flow.base.js
M modules/discussion/forms.js
M modules/discussion/init.js
M modules/discussion/paging.js
M modules/discussion/ui-functions.js
M modules/discussion/ui.js
7 files changed, 467 insertions(+), 364 deletions(-)

Approvals:
  EBernhardson (WMF): Verified; Looks good to me, approved



diff --git a/includes/api/ApiFlow.php b/includes/api/ApiFlow.php
index 46f0379..b5c9289 100644
--- a/includes/api/ApiFlow.php
+++ b/includes/api/ApiFlow.php
@@ -155,6 +155,7 @@
        }
 
        public function getExamples() {
+               // @todo: fill out an example
                 return array(
                         ''
                         => ''
diff --git a/modules/base/ext.flow.base.js b/modules/base/ext.flow.base.js
index b14542f..a1bc40f 100644
--- a/modules/base/ext.flow.base.js
+++ b/modules/base/ext.flow.base.js
@@ -1,23 +1,33 @@
-( function($, mw) {
-$( function() {
+( function ( $, mw ) {
+$( function () {
 mw.flow = {
        'api' : {
-               'executeAction' : function( workflowParam, action, options, 
render ) {
-                       var api = new mw.Api();
-                       var deferredObject = $.Deferred();
+               /**
+                * Execute a Flow action, fires API call.
+                *
+                * @param {object} workflowParam API parameters
+                * @param {string} action Action performed
+                * @param {object} options Additional API parameters (API key 
'params')
+                * @param {bool} render
+                * @return {Deferred}
+                */
+               'executeAction' : function ( workflowParam, action, options, 
render ) {
+                       var api = new mw.Api(),
+                               deferredObject = $.Deferred();
 
-                       api.post(
-                               $.extend(
-                                       {
-                                               'action' : 'flow',
-                                               'flowaction' : action,
-                                               'gettoken' : 'gettoken'
-                                       },
-                                       workflowParam
+                       api
+                               .post(
+                                       $.extend(
+                                               {
+                                                       'action' : 'flow',
+                                                       'flowaction' : action,
+                                                       'gettoken' : 'gettoken'
+                                               },
+                                               workflowParam
+                                       )
                                )
-                       )
-                               .done( function(data) {
-                                       request = {
+                               .done( function ( data ) {
+                                       var request = {
                                                'action' : 'flow',
                                                'flowaction' : action,
                                                'params' : $.toJSON( options ),
@@ -31,21 +41,27 @@
                                        }
 
                                        api.post( request )
-                                               .done( function( ) {
+                                               .done( function () {
                                                        
deferredObject.resolve.apply( this, arguments );
                                                } )
-                                               .fail( function( ) {
+                                               .fail( function () {
                                                        
deferredObject.reject.apply( this, arguments );
                                                } );
                                } )
-                               .fail(function( ) {
-                                       deferredObject.reject.apply( this, 
arguments);
+                               .fail( function () {
+                                       deferredObject.reject.apply( this, 
arguments );
                                } );
 
                        return deferredObject.promise();
                },
 
-               'read' : function( pageName, workflowId, options ) {
+               /**
+                * @param {string} pageName
+                * @param {string} workflowId
+                * @param {object} options API parameters
+                * @return {Deferred}
+                */
+               'read' : function ( pageName, workflowId, options ) {
                        var api = new mw.Api();
 
                        return api.get(
@@ -59,22 +75,29 @@
                        );
                },
 
-               'readBlock' : function( pageName, topicId, blockName, options ) 
{
+               /**
+                * @param {string} pageName
+                * @param {string} topicId
+                * @param {string} blockName
+                * @param {object} options API parameters
+                * @return {Deferred}
+                */
+               'readBlock' : function ( pageName, topicId, blockName, options 
) {
                        var deferredObject = $.Deferred();
 
                        mw.flow.api.read( pageName, topicId, options )
-                               .done( function(output) {
+                               .done( function ( output ) {
                                        // Immediate failure modes
                                        if (
-                                               ! output.query ||
-                                               ! output.query.flow ||
+                                               !output.query ||
+                                               !output.query.flow ||
                                                output.query.flow._element !== 
'block'
                                        ) {
                                                deferredObject.fail( 
'invalid-result', 'Unable to understand the API result' );
                                                return;
                                        }
 
-                                       $.each( output.query.flow, function( 
index, block ) {
+                                       $.each( output.query.flow, function ( 
index, block ) {
                                                // Looping through each block
                                                if ( block['block-name'] === 
blockName ) {
                                                        // Return this block
@@ -85,30 +108,48 @@
                                        deferredObject.fail( 'invalid-result', 
'Unable to find the '+
                                                blockName+' block in the API 
result' );
                                } )
-                               .fail( function() {
+                               .fail( function () {
                                        deferredObject.fail( arguments );
                                } );
 
                        return deferredObject.promise();
                },
 
-               'readTopicList' : function( pageName, workflowId, options ) {
+               /**
+                * @param {string} pageName
+                * @param {string} workflowId
+                * @param {object} options API parameters
+                * @return {Deferred}
+                */
+               'readTopicList' : function ( pageName, workflowId, options ) {
                        return mw.flow.api.readBlock( pageName, workflowId, 
'topic_list', options );
                },
 
-               'readTopic' : function( pageName, topicId, options ) {
+               /**
+                * @param {string} pageName
+                * @param {string} topicId
+                * @param {object} options API parameters
+                * @return {Deferred}
+                */
+               'readTopic' : function ( pageName, topicId, options ) {
                        return mw.flow.api.readBlock( pageName, topicId, 
'topic', options );
                },
 
-               'generateTopicAction' : function( actionName, parameterList, 
promiseFilterCallback ) {
-                       return function( workflowId ) {
-                               var deferredObject = $.Deferred();
+               /**
+                * @param {string} actionName
+                * @param {object} parameterList
+                * @param {function} promiseFilterCallback
+                * @return {function}
+                */
+               'generateTopicAction' : function ( actionName, parameterList, 
promiseFilterCallback ) {
+                       return function ( workflowId ) {
+                               var deferredObject = $.Deferred(),
+                                       requestParams = {},
+                                       paramIndex = 1,
+                                       requestArguments = arguments,
+                                       newDeferredObject;
 
-                               var requestParams = {};
-                               var paramIndex = 1;
-                               var requestArguments = arguments;
-
-                               $.each( parameterList, function( key, value ) {
+                               $.each( parameterList, function ( key, value ) {
                                        requestParams[value] = 
requestArguments[paramIndex];
                                        paramIndex++;
                                } );
@@ -121,31 +162,33 @@
                                        { 'topic' :
                                                requestParams
                                        }, true
-                               ).done( function(data) {
+                               ).done( function ( data ) {
+                                       var output;
+
                                        if ( data.flow[actionName].errors ) {
-                                               deferredObject.reject( 
'block-errors', data.flow['reply'].errors );
+                                               deferredObject.reject( 
'block-errors', data.flow.reply.errors );
                                                return;
                                        }
 
                                        if (
-                                               ! data.flow ||
-                                               ! data.flow[actionName] ||
-                                               ! data.flow[actionName].result 
||
-                                               ! 
data.flow[actionName].result['topic']
+                                               !data.flow ||
+                                               !data.flow[actionName] ||
+                                               !data.flow[actionName].result ||
+                                               
!data.flow[actionName].result.topic
                                        ) {
                                                deferredObject.reject( 
'invalid-result', 'Unable to find appropriate section in result' );
                                                return;
                                        }
-                                       var output = 
data.flow[actionName].result['topic'];
+                                       output = 
data.flow[actionName].result.topic;
 
                                        deferredObject.resolve( output, data );
                                } )
-                               .fail( function( ) {
+                               .fail( function () {
                                        deferredObject.reject.apply( this, 
arguments );
                                } );
 
                                if ( promiseFilterCallback ) {
-                                       var newDeferredObject = 
promiseFilterCallback( deferredObject.promise() );
+                                       newDeferredObject = 
promiseFilterCallback( deferredObject.promise() );
                                        if ( newDeferredObject ) {
                                                deferredObject = 
newDeferredObject;
                                        }
@@ -155,7 +198,13 @@
                        };
                },
 
-               'newTopic' : function( workflowParam, title, content ) {
+               /**
+                * @param {object} workflowParam
+                * @param {string} title
+                * @param {string} content
+                * @return {Deferred}
+                */
+               'newTopic' : function ( workflowParam, title, content ) {
                        var deferredObject = $.Deferred();
 
                        mw.flow.api.executeAction(
@@ -167,26 +216,28 @@
                                                'content' : content
                                        }
                                }, true
-                       ).done( function(data) {
+                       ).done( function ( data ) {
+                               var output;
+
                                if ( data.flow['new-topic'].errors ) {
                                        deferredObject.reject( 'block-errors', 
data.flow['new-topic'].errors );
                                        return;
                                }
 
                                if (
-                                       ! data.flow ||
-                                       ! data.flow['new-topic'] ||
-                                       ! data.flow['new-topic'].result ||
-                                       ! 
data.flow['new-topic'].result['topic_list']
+                                       !data.flow ||
+                                       !data.flow['new-topic'] ||
+                                       !data.flow['new-topic'].result ||
+                                       
!data.flow['new-topic'].result.topic_list
                                ) {
                                        deferredObject.reject( 
'invalid-result', 'Unable to find appropriate section in result' );
                                        return;
                                }
-                               var output = 
data.flow['new-topic'].result['topic_list'];
+                               output = 
data.flow['new-topic'].result.topic_list;
 
                                deferredObject.resolve( output, data );
                        } )
-                       .fail( function( ) {
+                       .fail( function () {
                                deferredObject.reject.apply( this, arguments );
                        } );
 
@@ -195,7 +246,10 @@
        }
 };
 
-// Now add all the individual actions
+/**
+ * @param {string} workflowId
+ * @return {Deferred}
+ */
 mw.flow.api.reply = mw.flow.api.generateTopicAction(
        'reply',
        [
@@ -204,6 +258,10 @@
        ]
 );
 
+/**
+ * @param {string} workflowId
+ * @return {Deferred}
+ */
 mw.flow.api.changeTitle = mw.flow.api.generateTopicAction(
        'edit-title',
        [
@@ -211,6 +269,10 @@
        ]
 );
 
+/**
+ * @param {string} workflowId
+ * @return {Deferred}
+ */
 mw.flow.api.editPost = mw.flow.api.generateTopicAction(
        'edit-post',
        [
@@ -218,5 +280,5 @@
                'content'
        ]
 );
-});
-})( jQuery, mediaWiki );
\ No newline at end of file
+} );
+} )( jQuery, mediaWiki );
diff --git a/modules/discussion/forms.js b/modules/discussion/forms.js
index aabcd25..c9df8dd 100644
--- a/modules/discussion/forms.js
+++ b/modules/discussion/forms.js
@@ -1,12 +1,12 @@
-( function( $, mw ) {
-$(document).on( 'flow_init', function( e ) {
-       $container = $( e.target );
-       $container.find('form.flow-reply-form').flow( 'setupEmptyDisabler',
+( function ( $, mw ) {
+$( document ).on( 'flow_init', function ( e ) {
+       var $container = $( e.target );
+       $container.find( 'form.flow-reply-form' ).flow( 'setupEmptyDisabler',
                ['.flow-reply-content'],
                '.flow-reply-submit'
        );
 
-       $('form.flow-newtopic-form').flow( 'setupEmptyDisabler',
+       $( 'form.flow-newtopic-form' ).flow( 'setupEmptyDisabler',
                [
                        '.flow-newtopic-title',
                        '.flow-newtopic-content'
@@ -18,7 +18,7 @@
        $container.flow( 'setupFormHandler',
                '.flow-newtopic-submit',
                mw.flow.api.newTopic,
-               function() {
+               function () {
                        $form = $(this).closest( '.flow-newtopic-form' );
 
                        var workflowParam = $container.flow( 
'getWorkflowParameters' );
@@ -27,17 +27,16 @@
 
                        return [ workflowParam, title, content ];
                },
-               function( workflowParam, title, content ) {
+               function ( workflowParam, title, content ) {
                        return title && content;
                },
-               function( promise ) {
+               function ( promise ) {
                        promise
-                               .done( function( output ) {
-                                       $form = $(this).closest( 
'.flow-newtopic-form' );
-
-                                       var $newRegion = $( output.rendered )
-                                               .hide()
-                                               .insertAfter( $form );
+                               .done( function ( output ) {
+                                       var $form = $( this ).closest( 
'.flow-newtopic-form' ),
+                                               $newRegion = $( output.rendered 
)
+                                                       .hide()
+                                                       .insertAfter( $form );
 
                                        $newRegion.trigger( 'flow_init' );
 
@@ -50,7 +49,7 @@
        $container.flow( 'setupFormHandler',
                '.flow-reply-submit',
                mw.flow.api.reply,
-               function() {
+               function () {
                        $form = $(this).closest( '.flow-reply-form' );
 
                        var workflowId = $( this ).flow( 'getTopicWorkflowId' );
@@ -63,19 +62,18 @@
 
                        return [ workflowId, replyToId, content ];
                },
-               function( workflowId, replyTo, content ) {
+               function ( workflowId, replyTo, content ) {
                        return content;
                },
-               function( promise ) {
+               function ( promise ) {
                        promise
-                               .done( function( output ) {
-                                       var $replyContainer = $(this)
-                                               .closest( 
'.flow-post-container' )
-                                               .children( '.flow-post-replies' 
);
-
-                                       var $newRegion = $( output.rendered )
-                                               .hide()
-                                               .prependTo( $replyContainer );
+                               .done( function ( output ) {
+                                       var $replyContainer = $( this )
+                                                       .closest( 
'.flow-post-container' )
+                                                       .children( 
'.flow-post-replies' ),
+                                               $newRegion = $( output.rendered 
)
+                                                       .hide()
+                                                       .prependTo( 
$replyContainer );
 
                                        $newRegion.trigger( 'flow_init' );
 
@@ -86,13 +84,13 @@
 
        // Overload 'edit post' link.
        $container.find( '.flow-action-edit-post a' )
-               .click( function(e) {
+               .click( function ( e ) {
                        e.preventDefault();
-                       var $postContainer = $(this).closest( '.flow-post' );
-                       var $contentContainer = $postContainer.find( 
'.flow-post-content' );
-                       var workflowId = $( this ).flow( 'getTopicWorkflowId' );
-                       var pageName = $(this).closest( '.flow-container' 
).data( 'page-title' );
-                       var postId = $postContainer.data( 'post-id' );
+                       var $postContainer = $( this ).closest( '.flow-post' ),
+                               $contentContainer = $postContainer.find( 
'.flow-post-content' ),
+                               workflowId = $( this ).flow( 
'getTopicWorkflowId' ),
+                               pageName = $( this ).closest( '.flow-container' 
).data( 'page-title' ),
+                               postId = $postContainer.data( 'post-id' );
 
                        if ( $postContainer.find( '.flow-edit-post-form' 
).length ) {
                                return;
@@ -108,12 +106,12 @@
                                        }
                                }
                        )
-                               .done( function( data ) {
-                                       if ( ! data[0] || data[0]['post-id'] != 
postId ) {
+                               .done( function ( data ) {
+                                       if ( !data[0] || data[0]['post-id'] !== 
postId ) {
                                                console.dir( data );
-                                               var $errorDiv = $( '<div/>' )
+                                               $( '<div/>' )
                                                        .addClass( 'flow-error' 
)
-                                                       .text( mw.msg( 
'flow-error-other') )
+                                                       .text( mw.msg( 
'flow-error-other' ) )
                                                        .hide()
                                                        .insertAfter( 
$contentContainer )
                                                        .slideDown();
@@ -140,10 +138,10 @@
                                                                                
.addClass( 'flow-cancel-link' )
                                                                                
.addClass( 'mw-ui-destructive' )
                                                                                
.attr( 'href', '#' )
-                                                                               
.click( function(e) {
+                                                                               
.click( function ( e ) {
                                                                                
        e.preventDefault();
                                                                                
        $postForm.slideUp( 'fast',
-                                                                               
                function() {
+                                                                               
                function () {
                                                                                
                        $contentContainer.show();
                                                                                
                        $postForm.remove();
                                                                                
                }
@@ -166,35 +164,35 @@
                                        $postContainer.flow( 'setupFormHandler',
                                                '.flow-edit-post-submit',
                                                mw.flow.api.editPost,
-                                               function() {
+                                               function () {
                                                        var content = 
$postForm.find( '.flow-edit-post-content' ).val();
 
                                                        return [ workflowId, 
postId, content ];
                                                },
-                                               function( workflowId, postId, 
content ) {
+                                               function ( workflowId, postId, 
content ) {
                                                        return content;
                                                },
-                                               function( promise ) {
-                                                       promise.done( 
function(output) {
+                                               function ( promise ) {
+                                                       promise.done( function 
( output ) {
                                                                
$contentContainer
                                                                        .empty()
                                                                        .append(
-                                                                               
$(output.rendered)
-                                                                               
        .find('.flow-post-content')
+                                                                               
$( output.rendered )
+                                                                               
        .find( '.flow-post-content' )
                                                                                
        .children()
                                                                        );
                                                                } );
                                                }
                                        );
 
-                                       $('form.flow-edit-post-form').flow( 
'setupEmptyDisabler',
+                                       $( 'form.flow-edit-post-form' ).flow( 
'setupEmptyDisabler',
                                                [
                                                        
'.flow-edit-post-content'
                                                ],
                                                '.flow-edit-post-submit'
                                        );
                                } )
-                               .fail( function() {
+                               .fail( function () {
                                        var $errorDiv = $( '<div/>' )
                                                .addClass( 'flow-error' )
                                                .hide();
@@ -208,32 +206,32 @@
 
        // Overload 'edit title' link.
        $container.find( '.flow-action-edit-title a' )
-               .click( function(e) {
+               .click( function ( e ) {
                        e.preventDefault();
 
-                       var $topicContainer = $(this).closest( 
'.flow-topic-container' );
-                       var $titleBar = $topicContainer.find( 
'.flow-topic-title' );
-                       var oldTitle = $topicContainer.data( 'title' );
+                       var $topicContainer = $( this ).closest( 
'.flow-topic-container' ),
+                               $titleBar = $topicContainer.find( 
'.flow-topic-title' ),
+                               oldTitle = $topicContainer.data( 'title' ),
+                               $titleEditForm = $( '<form />' );
 
                        $titleBar.find( '.flow-realtitle' )
                                .hide();
 
-                       var $titleEditForm = $( '<form />' );
                        $titleEditForm
                                .addClass( 'flow-edit-title-form' )
                                .append(
-                                       $('<input />')
+                                       $( '<input />' )
                                                .addClass( 
'flow-edit-title-textbox' )
                                                .attr( 'type', 'text' )
                                                .val( oldTitle )
                                )
                                .append(
-                                       $('<a/>')
+                                       $( '<a/>' )
                                                .addClass( 'flow-cancel-link' )
                                                .addClass( 'mw-ui-destructive' )
                                                .attr( 'href', '#' )
                                                .text( mw.msg( 'flow-cancel' ) )
-                                               .click( function(e) {
+                                               .click( function ( e ) {
                                                        e.preventDefault();
                                                        $titleBar.children( 
'form' )
                                                                .remove();
@@ -248,7 +246,7 @@
                                                .addClass( 'mw-ui-button' )
                                                .addClass( 'mw-ui-primary' )
                                                .attr( 'type', 'submit' )
-                                               .val( 
mw.msg('flow-edit-title-submit' ) )
+                                               .val( mw.msg( 
'flow-edit-title-submit' ) )
                                )
                                .appendTo( $titleBar )
                                .find( '.flow-edit-title-textbox' )
@@ -258,17 +256,17 @@
                                $titleEditForm.flow( 'setupFormHandler',
                                        '.flow-edit-title-submit',
                                        mw.flow.api.changeTitle,
-                                       function() {
-                                               workflowId = 
$topicContainer.data( 'topic-id' );
-                                               content = $titleEditForm.find( 
'.flow-edit-title-textbox' ).val();
+                                       function () {
+                                               var workflowId = 
$topicContainer.data( 'topic-id' ),
+                                                       content = 
$titleEditForm.find( '.flow-edit-title-textbox' ).val();
 
                                                return [ workflowId, content ];
                                        },
-                                       function( workflowId, content ) {
+                                       function ( workflowId, content ) {
                                                return content && true;
                                        },
-                                       function( promise ) {
-                                               promise.done(function( output ) 
{
+                                       function ( promise ) {
+                                               promise.done( function ( output 
) {
                                                        $titleBar.find( 
'.flow-realtitle' )
                                                                .empty()
                                                                .text( 
output.rendered )
@@ -281,4 +279,4 @@
                                        } );
                } );
 } );
-} )( jQuery, mediaWiki );
\ No newline at end of file
+} )( jQuery, mediaWiki );
diff --git a/modules/discussion/init.js b/modules/discussion/init.js
index 5d789b1..055ce90 100644
--- a/modules/discussion/init.js
+++ b/modules/discussion/init.js
@@ -1,5 +1,5 @@
-( function($, mw) {
-       $( function() {
+( function ( $, mw ) {
+       $( function () {
                $( '.flow-container' ).trigger( 'flow_init' );
-       });
+       } );
 } )( jQuery, mediaWiki );
diff --git a/modules/discussion/paging.js b/modules/discussion/paging.js
index eba7bd4..456dac8 100644
--- a/modules/discussion/paging.js
+++ b/modules/discussion/paging.js
@@ -1,5 +1,9 @@
-( function( $, mw ) {
-       var getPagingLink = function( data ) {
+( function ( $, mw ) {
+       /**
+        * @param {object} data
+        * @returns {jQuery}
+        */
+       var getPagingLink = function ( data ) {
                var direction = data.direction,
                        offset = data.offset,
                        limit = data.limit;
@@ -11,60 +15,60 @@
                        .data( 'offset', offset )
                        .data( 'limit', limit )
                        .append(
-                               $('<a/>')
+                               $( '<a/>' )
                                        .attr( 'href', '#' )
-                                       .text( mw.msg( 'flow-paging-'+direction 
) )
+                                       .text( mw.msg( 'flow-paging-' + 
direction ) )
                        );
        };
 
-       $( document ).on( 'flow_init', function( e ) {
-               $(this).find( '.flow-paging a' ).click( function(e) {
+       $( document ).on( 'flow_init', function () {
+               $( this ).find( '.flow-paging a' ).click( function ( e ) {
                        e.preventDefault();
-                       var $pagingLinkDiv = $(this).closest('.flow-paging')
-                               .addClass( 'flow-paging-loading' );
+                       var $pagingLinkDiv = $( this ).closest( '.flow-paging' )
+                                       .addClass( 'flow-paging-loading' ),
 
-                       var offset = $pagingLinkDiv.data( 'offset' );
-                       var direction = $pagingLinkDiv.data( 'direction' );
-                       var limit = $pagingLinkDiv.data( 'limit' );
-                       var workflowId = $(this).flow( 'getTopicWorkflowId' );
-                       var pageName = $(this).closest( '.flow-container' 
).data( 'page-title' );
-                       var requestLimit;
+                               offset = $pagingLinkDiv.data( 'offset' ),
+                               direction = $pagingLinkDiv.data( 'direction' ),
+                               limit = $pagingLinkDiv.data( 'limit' ),
+                               workflowId = $( this ).flow( 
'getTopicWorkflowId' ),
+                               pageName = $( this ).closest( '.flow-container' 
).data( 'page-title' ),
 
-                       // One more for paging forward.
-                       requestLimit = limit + 1;
+                               // One more for paging forward.
+                               requestLimit = limit + 1,
 
-                       var request = {
-                               'topic_list' : {
-                                       'offset-dir' : direction,
-                                       'offset-id' : offset,
-                                       'limit' : requestLimit,
-                                       'render' : true
-                               }
-                       };
+                               request = {
+                                       'topic_list' : {
+                                               'offset-dir' : direction,
+                                               'offset-id' : offset,
+                                               'limit' : requestLimit,
+                                               'render' : true
+                                       }
+                               };
 
                        mw.flow.api.readTopicList( pageName, workflowId, 
request )
-                               .done( function( data ) {
-                                       var nextPage, prevPage;
-                                       var topics = [];
-                                       $.each( data, function( k, v ) {
-                                               if ( k - 0 == k ) {
+                               .done( function ( data ) {
+                                       var topics = [],
+                                               $output = $( '<div/>' ),
+                                               $replaceContent;
+
+                                       $.each( data, function ( k, v ) {
+                                               if ( k - 0 === k ) {
                                                        topics.push( v );
                                                }
                                        } );
 
-                                       var $output = $('<div/>');
 
-                                       if ( direction == 'rev' && 
data.paging.rev ) {
+                                       if ( direction === 'rev' && 
data.paging.rev ) {
                                                $output.append(
                                                        getPagingLink(
                                                                data.paging.rev
                                                        )
                                                );
                                        }
-                                       $.each( topics, function( k, topic ) {
+                                       $.each( topics, function ( k, topic ) {
                                                $output.append( topic.rendered 
);
                                        } );
-                                       if ( direction == 'fwd' && 
data.paging.fwd ) {
+                                       if ( direction === 'fwd' && 
data.paging.fwd ) {
                                                $output.append(
                                                        getPagingLink(
                                                                data.paging.fwd
@@ -72,12 +76,12 @@
                                                );
                                        }
 
-                                       var $replaceContent = 
$output.children();
+                                       $replaceContent = $output.children();
                                        $pagingLinkDiv.next( '.flow-error' 
).remove();
                                        $pagingLinkDiv.replaceWith( 
$replaceContent );
                                        $replaceContent.trigger( 'flow_init' );
                                } )
-                               .fail( function() {
+                               .fail( function () {
                                        $( '<div/>' )
                                                .flow( 'showError', arguments )
                                                .insertAfter( $pagingLinkDiv );
@@ -85,25 +89,26 @@
                } );
        } );
 
-       $( function() {
-               var $window = $(window);
+       $( function () {
+               var $window = $( window );
                $window
-                       .scroll( function(e) {
-                               $( '.flow-paging-fwd' ).each( function() {
-                                       var $pagingLinkDiv = $( this );
+                       .scroll( function () {
+                               $( '.flow-paging-fwd' ).each( function () {
+                                       var $pagingLinkDiv = $( this ),
+
+                                               // Trigger infinite scroll when 
the user is half a screenlength
+                                               // away from the end.
+                                               windowEnd = $window.scrollTop() 
+ ( 1.5 * $window.height() );
+
                                        if ( $pagingLinkDiv.hasClass( 
'flow-paging-loading' ) ) {
                                                // Already loading
                                                return;
                                        }
 
-                                       // Trigger infinite scroll when the 
user is half a screenlength
-                                       //  away from the end.
-                                       var windowEnd = $window.scrollTop() + 
(1.5 * $window.height() );
-
                                        if ( $pagingLinkDiv.position().top < 
windowEnd ) {
-                                               
$pagingLinkDiv.find('a').click();
+                                               $pagingLinkDiv.find( 'a' 
).click();
                                        }
                                } );
                        } );
        } );
-} )( jQuery, mediaWiki );
\ No newline at end of file
+} )( jQuery, mediaWiki );
diff --git a/modules/discussion/ui-functions.js 
b/modules/discussion/ui-functions.js
index 592a8ce..ed97a53 100644
--- a/modules/discussion/ui-functions.js
+++ b/modules/discussion/ui-functions.js
@@ -1,188 +1,224 @@
-( function($, mw) {
+( function ( $, mw ) {
        $.fn.extend( true, {
-               'flow' : function() {
+               /**
+                * @param {string} funcName Name of _flow method
+                * @param {mixed} arguments Arguments to respective _flow method
+                * @return {mixed}
+                */
+               'flow' : function ( funcName /* [, argument[, argument[, ...]]] 
*/) {
                        var args = Array.prototype.slice.call( arguments );
-                       var funcName = args.shift();
+                       args.shift();
+
                        return this._flow[funcName].apply( this, args );
                },
 
                '_flow' : {
-               'setupEmptyDisabler' : function( fieldSelectors, submitSelector 
) {
-                       var $form = this;
-                       var validateFunction = function( $container ) {
-                               var isOk = true;
+                       /**
+                        * Checks on every keyup if all fieldSelectors are 
filled out and
+                        * (if so) enabled submitSelector.
+                        *
+                        * @param {array} fieldSelectors Array of jQuery 
selector strings
+                        * @param {string} submitSelector jQuery selector string
+                        * @return {jQuery}
+                        */
+                       'setupEmptyDisabler' : function ( fieldSelectors, 
submitSelector ) {
+                               var $form = this,
+                                       validateFunction = function ( 
$container ) {
+                                               var isOk = true;
 
-                               $.each( fieldSelectors, function() {
-                                       // I have no idea why "toString()" is 
necessary
-                                       if ( ! $container.find( this.toString() 
).val() ) {
-                                               isOk = false;
-                                       }
-                               } );
+                                               $.each( fieldSelectors, 
function () {
+                                                       // I have no idea why 
"toString()" is necessary
+                                                       if ( !$container.find( 
this.toString() ).val() ) {
+                                                               isOk = false;
+                                                               return false; 
// break
+                                                       }
+                                               } );
 
-                               if ( isOk ) {
-                                       $container.find( submitSelector )
-                                               .removeAttr( 'disabled' );
-                               } else {
-                                       $container.find( submitSelector )
-                                               .attr( 'disabled', 'disabled' );
-                               }
-                       };
+                                               if ( isOk ) {
+                                                       $container.find( 
submitSelector )
+                                                               .removeAttr( 
'disabled' );
+                                               } else {
+                                                       $container.find( 
submitSelector )
+                                                               .attr( 
'disabled', 'disabled' );
+                                               }
+                                       };
 
-                       $.each( fieldSelectors, function() {
-                                       $form.find(this.toString())
-                                               .not('.flow-disabler')
-                                               .keyup( function(e) {
-                                                       $container = 
$(e.target).closest( $form );
+                               $.each( fieldSelectors, function () {
+                                       $form.find( this.toString() )
+                                               .not( '.flow-disabler' )
+                                               .keyup( function ( e ) {
+                                                       var $container = $( 
e.target ).closest( $form );
                                                        validateFunction( 
$container );
                                                } )
-                                               .addClass('flow-disabler');
+                                               .addClass( 'flow-disabler' );
                                } );
 
-                       $form.each( function() {
-                               validateFunction( $container );
-                       } );
-
-                       return $form;
-               },
-
-               'setupFormHandler' : function(
-                       submitSelector,
-                       submitFunction,
-                       loadParametersCallback,
-                       validateCallback,
-                       promiseCallback
-               ) {
-                       var $container = this;
-
-                       $container.find( submitSelector )
-                               .click( function(e) {
-                                       e.preventDefault();
-                                       var $button = $( this );
-                                       var $form = $button.closest( 'form' );
-
-                                       $form.find( '.flow-error' )
-                                               .remove();
-
-                                       var params = 
loadParametersCallback.apply( this );
-
-                                       if ( validateCallback && ! 
validateCallback.apply( this, params ) ) {
-                                               $button.attr( 'disabled', 
'disabled' );
-                                               console.log( "Validate callback 
failed" );
-                                               return;
-                                       }
-
-                                       $button.hide();
-                                       var $spinner = $( '<div/>' )
-                                               .addClass( 
'flow-loading-indicator' )
-                                               .insertAfter( $button );
-                                       var deferredObject = $.Deferred();
-
-                                       if ( promiseCallback ) {
-                                               promiseCallback( 
deferredObject.promise() );
-                                       }
-
-                                       submitFunction.apply( this, params )
-                                               .done( function(output) {
-                                                       $spinner.remove();
-                                                       $button.show();
-                                                       $form.find( 
'.flow-cancel-link' )
-                                                               .click();
-
-                                                       
deferredObject.resolve.apply( $button, arguments );
-                                               } )
-                                               .fail( function( ) {
-                                                       $spinner.remove();
-                                                       $button.show();
-
-                                                       var $errorDiv = 
$('<div/>').flow( 'showError', arguments );
-                                                       var $disclaimer = 
$form.find( '.flow-disclaimer' );
-                                                       if ( $disclaimer.length 
) {
-                                                               
$errorDiv.insertBefore( $disclaimer );
-                                                       } else {
-                                                               $form.append( 
$errorDiv );
-                                                       }
-
-                                                       
deferredObject.reject.apply( $button, arguments );
-                                               } );
+                               $form.each( function () {
+                                       validateFunction( $( this ) );
                                } );
 
-                       return $container;
-               },
+                               return $form;
+                       },
 
-               'getTopicWorkflowId' : function( ) {
-                       var $element = this;
-                       var $topicContainer = $element.closest( 
'.flow-topic-container' );
-                       var $container = $element.closest( '.flow-container' );
+                       /**
+                        * @param {string} submitSelector jQuery selector 
string to capture submit button
+                        * @param {function} submitFunction Function to execute 
when submitting form
+                        * @param {function} loadParametersCallback Function to 
load parameters to be submitted
+                        * @param {function} validateCallback Function to 
validate parameters to be submitted
+                        * @param {function} promiseCallback Callback to be 
executed when form is submitted
+                        * @return {jQuery}
+                        */
+                       'setupFormHandler' : function (
+                               submitSelector,
+                               submitFunction,
+                               loadParametersCallback,
+                               validateCallback,
+                               promiseCallback
+                       ) {
+                               var $container = this;
 
-                       if ( $topicContainer.length ) {
-                               return $topicContainer.data( 'topic-id' );
-                       } else if ( $container.length ) {
-                               return $container.data( 'workflow-id' );
-                       } else {
-                               console.dirxml( $element[0] );
-                               throw new Error( "Unable to get a workflow ID" 
);
-                       }
-               },
+                               $container.find( submitSelector )
+                                       .click( function ( e ) {
+                                               e.preventDefault();
 
-               'getWorkflowParameters' : function( ) {
-                       var $container = this.closest( '.flow-container' );
-                       var workflowStatus = $container.data( 
'workflow-existence' );
+                                               var $button = $( this ),
+                                                       $form = 
$button.closest( 'form' ),
+                                                       params = 
loadParametersCallback.apply( this ),
+                                                       $spinner = $( '<div/>' 
),
+                                                       deferredObject = 
$.Deferred();
 
-                       if ( workflowStatus == 'new' ) {
-                               return {
-                                       'page' : $container.data( 'page-title' )
-                               };
-                       } else if ( workflowStatus == 'existing' ) {
-                               return {
-                                       'workflow' : $container.data( 
'workflow-id' )
-                               };
-                       } else {
-                               throw new Error( "Unknown workflow status " + 
workflowStatus );
-                       }
-               },
+                                               $form.find( '.flow-error' )
+                                                       .remove();
 
-               'showError' : function( errorArgs ) {
-                       var $errorDiv = this;
+                                               if ( validateCallback && 
!validateCallback.apply( this, params ) ) {
+                                                       $button.attr( 
'disabled', 'disabled' );
+                                                       console.log( 'Validate 
callback failed' );
+                                                       return;
+                                               }
 
-                       $errorDiv
-                               .addClass( 'flow-error' )
-                               .hide()
-                               .slideDown( 'fast' );
+                                               $button.hide();
+                                               $spinner
+                                                       .addClass( 
'flow-loading-indicator' )
+                                                       .insertAfter( $button );
 
-                       var apiExceptionPrefix = 'internal_api_error';
-                       if ( errorArgs[0] == 'http' ) {
-                               // HTTP error occurred
-                               $errorDiv.html( mw.message( 'flow-error-http' 
).text() );
-                       } else if ( errorArgs[0].substr( 0, 
apiExceptionPrefix.length ) == apiExceptionPrefix ) {
-                               $errorDiv.html( mw.message( 
'flow-error-external', errorArgs[1].error.info ).text() );
-                               console.dir( errorArgs[1] );
-                       } else if ( errorArgs[0] == 'block-errors' ) {
-                               var errors = [];
-                               $.each( errorArgs[1], function( block, 
blockErrors ) {
-                                       $.each( blockErrors, function( field, 
errorMsg ) {
-                                               errors.push( errorMsg );
-                                       } );
-                               } );
+                                               if ( promiseCallback ) {
+                                                       promiseCallback( 
deferredObject.promise() );
+                                               }
 
-                               if ( errors.length == 1 ) {
-                                       $errorDiv.html( mw.message( 
'flow-error-external', errors.pop() ).text() );
-                               } else if ( errors.length > 1 ) {
-                                       var $errorList = $( '<ul/>' );
-                                       $.each( errors, function( k, error ) {
-                                               $( '<li />' ).text( error )
-                                                       .appendTo( $errorList );
+                                               submitFunction.apply( this, 
params )
+                                                       .done( function ( 
output ) {
+                                                               
$spinner.remove();
+                                                               $button.show();
+                                                               $form.find( 
'.flow-cancel-link' )
+                                                                       
.click();
+
+                                                               
deferredObject.resolve.apply( $button, arguments );
+                                                       } )
+                                                       .fail( function () {
+                                                               var $errorDiv = 
$( '<div/>' ).flow( 'showError', arguments ),
+                                                                       
$disclaimer = $form.find( '.flow-disclaimer' );
+
+                                                               
$spinner.remove();
+                                                               $button.show();
+
+                                                               if ( 
$disclaimer.length ) {
+                                                                       
$errorDiv.insertBefore( $disclaimer );
+                                                               } else {
+                                                                       
$form.append( $errorDiv );
+                                                               }
+
+                                                               
deferredObject.reject.apply( $button, arguments );
+                                                       } );
                                        } );
 
-                                       $errorDiv.html( mw.message( 
'flow-error-external-multi', $errorList.html() ).text() );
+                               return $container;
+                       },
+
+                       /**
+                        * @return {string}
+                        */
+                       'getTopicWorkflowId' : function () {
+                               var $element = this,
+                                       $topicContainer = $element.closest( 
'.flow-topic-container' ),
+                                       $container = $element.closest( 
'.flow-container' );
+
+                               if ( $topicContainer.length ) {
+                                       return $topicContainer.data( 'topic-id' 
);
+                               } else if ( $container.length ) {
+                                       return $container.data( 'workflow-id' );
                                } else {
-                                       $errorDiv.html( mw.message( 
'flow-error-other' ) );
+                                       console.dirxml( $element[0] );
+                                       throw new Error( 'Unable to get a 
workflow ID' );
                                }
-                       } else {
-                               $errorDiv.html( mw.message( 'flow-error-other' 
).text() );
-                               console.dir( errorArgs );
-                       }
+                       },
 
-                       return $errorDiv;
+                       /**
+                        * @return {object}
+                        */
+                       'getWorkflowParameters' : function () {
+                               var $container = this.closest( 
'.flow-container' ),
+                                       workflowStatus = $container.data( 
'workflow-existence' );
+
+                               if ( workflowStatus === 'new' ) {
+                                       return {
+                                               'page' : $container.data( 
'page-title' )
+                                       };
+                               } else if ( workflowStatus === 'existing' ) {
+                                       return {
+                                               'workflow' : $container.data( 
'workflow-id' )
+                                       };
+                               } else {
+                                       throw new Error( 'Unknown workflow 
status ' + workflowStatus );
+                               }
+                       },
+
+                       /**
+                        * @param {array} errorArgs
+                        * @returns {jQuery}
+                        */
+                       'showError' : function ( errorArgs ) {
+                               var $errorDiv = this,
+                                       apiExceptionPrefix = 
'internal_api_error',
+                                       errors = [],
+                                       $errorList = $( '<ul/>' );
+
+                               $errorDiv
+                                       .addClass( 'flow-error' )
+                                       .hide()
+                                       .slideDown( 'fast' );
+
+                               if ( errorArgs[0] === 'http' ) {
+                                       // HTTP error occurred
+                                       $errorDiv.html( mw.message( 
'flow-error-http' ).text() );
+                               } else if ( errorArgs[0].substr( 0, 
apiExceptionPrefix.length ) === apiExceptionPrefix ) {
+                                       $errorDiv.html( mw.message( 
'flow-error-external', errorArgs[1].error.info ).text() );
+                                       console.dir( errorArgs[1] );
+                               } else if ( errorArgs[0] === 'block-errors' ) {
+                                       $.each( errorArgs[1], function ( block, 
blockErrors ) {
+                                               $.each( blockErrors, function ( 
field, errorMsg ) {
+                                                       errors.push( errorMsg );
+                                               } );
+                                       } );
+
+                                       if ( errors.length === 1 ) {
+                                               $errorDiv.html( mw.message( 
'flow-error-external', errors.pop() ).text() );
+                                       } else if ( errors.length > 1 ) {
+                                               $.each( errors, function ( k, 
error ) {
+                                                       $( '<li />' ).text( 
error )
+                                                               .appendTo( 
$errorList );
+                                               } );
+
+                                               $errorDiv.html( mw.message( 
'flow-error-external-multi', $errorList.html() ).text() );
+                                       } else {
+                                               $errorDiv.html( mw.message( 
'flow-error-other' ) );
+                                       }
+                               } else {
+                                       $errorDiv.html( mw.message( 
'flow-error-other' ).text() );
+                                       console.dir( errorArgs );
+                               }
+
+                               return $errorDiv;
+                       }
                }
-       } } );
-} )( jQuery, mediaWiki );
\ No newline at end of file
+       } );
+} )( jQuery, mediaWiki );
diff --git a/modules/discussion/ui.js b/modules/discussion/ui.js
index ea2978a..9fe824b 100644
--- a/modules/discussion/ui.js
+++ b/modules/discussion/ui.js
@@ -1,32 +1,33 @@
-( function( $, mw ) {
-       $(document).on( 'flow_init', function( e ) {
-               $container = $( e.target );
+( function ( $, mw ) {
+       $( document ).on( 'flow_init', function ( e ) {
+               var $container = $( e.target );
+
                // Set up menus
                $container.find( '.flow-post-actions, .flow-topic-actions' )
-                       .click( function(e) {
-                               $(this).children( '.flow-post-actionbox, 
.flow-topic-actionbox, .flow-actionbox-pokey' )
+                       .click( function () {
+                               $( this ).children( '.flow-post-actionbox, 
.flow-topic-actionbox, .flow-actionbox-pokey' )
                                        .show();
                        } )
-                       .find('li')
-                       .click( function(e) {
-                               $(this).closest('.flow-topic-actions, 
.flow-post-actions')
+                       .find( 'li' )
+                       .click( function () {
+                               $( this ).closest( '.flow-topic-actions, 
.flow-post-actions' )
                                        .children( '.flow-post-actionbox, 
.flow-topic-actionbox, .flow-actionbox-pokey' )
                                        .fadeOut();
                        } );
 
                // Set up timestamp on-hover
                $container.find( '.flow-topic-datestamp, .flow-datestamp' )
-                       .hover(function() {
-                               $(this).children( '.flow-agotime' ).toggle()
-                               $(this).children( '.flow-utctime' ).toggle()
+                       .hover( function () {
+                               $( this ).children( '.flow-agotime' ).toggle();
+                               $( this ).children( '.flow-utctime' ).toggle();
                        } );
 
                // Set up reply form
                $container.find( '.flow-reply-form textarea' )
                        .addClass( 'flow-reply-box-closed' )
-                       .click( function(e) {
-                               $(this).removeClass( 'flow-reply-box-closed' );
-                               $(this).closest( 'form' )
+                       .click( function () {
+                               $( this ).removeClass( 'flow-reply-box-closed' 
);
+                               $( this ).closest( 'form' )
                                        .children( '.flow-post-form-extras' )
                                        .show();
                        } );
@@ -39,33 +40,33 @@
                        .addClass( 'flow-cancel-link' )
                        .addClass( 'mw-ui-destructive' )
                        .text( mw.msg( 'flow-cancel' ) )
-                       .click( function(e) {
+                       .click( function ( e ) {
                                e.preventDefault();
-                               $(this).closest( '.flow-post-form-extras' )
-                                       .slideUp( 'fast', function() {
-                                               $(this).closest( 
'.flow-reply-form' )
+                               $( this ).closest( '.flow-post-form-extras' )
+                                       .slideUp( 'fast', function () {
+                                               $( this ).closest( 
'.flow-reply-form' )
                                                        .find( 'textarea' )
                                                                .addClass( 
'flow-reply-box-closed' )
-                                                               .val('')
+                                                               .val( '' )
                                                                .end()
                                                        .find( '.flow-error' )
                                                                .remove();
-                                       });
+                                       } );
                        } )
-                       .insertBefore( $container.find('.flow-reply-form 
input[type=submit]') );
+                       .insertBefore( $container.find( '.flow-reply-form 
input[type=submit]' ) );
 
                // Set up new topic form
                $container.find( '.flow-newtopic-step2' ).hide();
                $container.find( '.flow-newtopic-title' )
                        .addClass( 'flow-newtopic-start' )
                        .attr( 'placeholder', mw.msg( 
'flow-newtopic-start-placeholder' ) )
-                       .click( function(e) {
-                               if ( ! $(this).hasClass('flow-newtopic-start' ) 
) {
+                       .click( function () {
+                               if ( !$( this ).hasClass( 'flow-newtopic-start' 
) ) {
                                        return;
                                }
                                $( '.flow-newtopic-step2' )
                                        .show();
-                               $(this)
+                               $( this )
                                        .removeClass( 'flow-newtopic-start' )
                                        .attr( 'placeholder', mw.msg( 
'flow-newtopic-title-placeholder' ) );
                                $( '.flow-newtopic-submit' )
@@ -77,11 +78,12 @@
                        .addClass( 'flow-cancel-link' )
                        .addClass( 'mw-ui-destructive' )
                        .text( mw.msg( 'flow-cancel' ) )
-                       .click( function(e) {
+                       .click( function ( e ) {
                                e.preventDefault();
-                               var $form = $(this).closest( 
'form.flow-newtopic-form' );
+                               var $form = $( this ).closest( 
'form.flow-newtopic-form' );
+
                                $( '.flow-newtopic-step2' )
-                                       .slideUp( 'fast', function() {
+                                       .slideUp( 'fast', function () {
                                                $form.find( 
'.flow-newtopic-title' )
                                                        .val( '' )
                                                        .attr( 'placeholder', 
mw.msg( 'flow-newtopic-start-placeholder' ) )
@@ -92,16 +94,15 @@
                                                        .remove();
                                        } );
                        } )
-                       .insertBefore( $container.find('.flow-newtopic-form 
input[type=submit]') );
+                       .insertBefore( $container.find( '.flow-newtopic-form 
input[type=submit]' ) );
 
                // Set up folding
                $container.find( '.flow-topic-opener' )
-                       .click( function(e) {
-                               var $topicContainer = 
$(this).closest('.flow-topic-container')
-                                       .toggleClass( 'flow-topic-closed' );
-
-                               var $hideElement = 
$(this).closest('.flow-topic-container')
-                                       .children( '.flow-post-container' );
+                       .click( function () {
+                               var $topicContainer = $( this ).closest( 
'.flow-topic-container' )
+                                               .toggleClass( 
'flow-topic-closed' ),
+                                       $hideElement = $( this ).closest( 
'.flow-topic-container' )
+                                               .children( 
'.flow-post-container' );
 
                                        if ( $topicContainer.hasClass( 
'flow-topic-closed' ) ) {
                                                $hideElement.slideUp();
@@ -111,10 +112,10 @@
                        } );
        } );
 
-       $('body')
-               .click( function(e) {
-                       if ( $(e.target)
-                               .closest('.flow-post-actions, 
.flow-topic-actions' )
+       $( 'body' )
+               .click( function ( e ) {
+                       if ( $( e.target )
+                               .closest( '.flow-post-actions, 
.flow-topic-actions' )
                                .length === 0
                        ) {
                                $( '.flow-post-actionbox, 
.flow-topic-actionbox, .flow-actionbox-pokey' )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4df027cf04659a9add142236f35efe9e64a6212e
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: EBernhardson (WMF) <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Werdna <agarr...@wikimedia.org>

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

Reply via email to