r98702 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98701‎ | r98702 | r98703 >
Date:19:25, 2 October 2011
Author:johnduhart
Status:ok (Comments)
Tags:
Comment:
Followup r98563, improvement to javascript per CR
Modified paths:
  • /trunk/extensions/CategoryTree/modules/ext.categoryTree.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/modules/ext.categoryTree.js
@@ -12,41 +12,39 @@
1313 * in CategoryTree.php to avoid users getting stale copies from cache.
1414 */
1515
16 -new ( function( $, mw ) {
17 - /**
18 - * Reference to this
19 - *
20 - * @var {this}
21 - */
22 - var that = this;
 16+(function( $, mw ) {
2317
 18+var categoryTree = {
2419 /**
2520 * Sets display inline to tree toggle
2621 */
27 - this.showToggles = function() {
 22+ showToggles: function() {
2823 $( 'span.CategoryTreeToggle' ).css( 'display', 'inline' );
29 - };
30 -
 24+ },
 25+
3126 /**
3227 * Handles clicks on the expand buttons, and calls the appropriate function
 28+ *
 29+ * @context {Element} CategoryTreeToggle
 30+ * @param e {jQuery.Event}
3331 */
34 - this.handleNode = function() {
 32+ handleNode: function( e ) {
3533 var $link = $( this );
36 - if ( $link.data( 'ctState' ) == 'collapsed' ) {
37 - that.expandNode( $link );
 34+ if ( $link.data( 'ctState' ) === 'collapsed' ) {
 35+ categoryTree.expandNode( $link );
3836 } else {
39 - that.collapseNode( $link );
 37+ categoryTree.collapseNode( $link );
4038 }
41 - }
 39+ },
4240
4341 /**
4442 * Expands a given node (loading it's children if not loaded)
4543 *
4644 * @param {jQuery} $link
4745 */
48 - this.expandNode = function( $link ) {
 46+ expandNode: function( $link ) {
4947 // Show the children node
50 - $children = $link.parents( '.CategoryTreeItem' )
 48+ var $children = $link.parents( '.CategoryTreeItem' )
5149 .siblings( '.CategoryTreeChildren' );
5250 $children.show();
5351
@@ -56,16 +54,16 @@
5755 .data( 'ctState', 'expanded' );
5856
5957 if ( !$link.data( 'ctLoaded' ) ) {
60 - that.loadChildren( $link, $children );
 58+ categoryTree.loadChildren( $link, $children );
6159 }
62 - };
 60+ },
6361
6462 /**
6563 * Collapses a node
6664 *
6765 * @param {jQuery} $link
6866 */
69 - this.collapseNode = function( $link ) {
 67+ collapseNode: function( $link ) {
7068 // Hide the children node
7169 $link.parents( '.CategoryTreeItem' )
7270 .siblings( '.CategoryTreeChildren' ).hide();
@@ -74,28 +72,28 @@
7573 .html( mw.msg( 'categorytree-expand-bullet' ) )
7674 .attr( 'title', mw.msg( 'categorytree-expand' ) )
7775 .data( 'ctState', 'collapsed' );
78 - };
 76+ },
7977
8078 /**
81 - * Loads children for a node
 79+ * Loads children for a node via an HTTP call
8280 *
8381 * @param {jQuery} $link
8482 * @param {jQuery} $children
8583 */
86 - this.loadChildren = function( $link, $children ) {
 84+ loadChildren: function( $link, $children ) {
8785 $link.data( 'ctLoaded', true );
8886 $children.html(
89 - '<i class="CategoryTreeNotice">'
90 - + mw.msg( 'categorytree-loading' ) + "</i>"
 87+ $( '<i class="CategoryTreeNotice"></i>' )
 88+ .text( mw.msg( 'categorytree-loading' ) )
9189 );
9290
9391 var $parentTag = $link.parents( '.CategoryTreeTag' );
9492
95 - if ( $parentTag.length == 0 ) {
 93+ if ( $parentTag.length === 0 ) {
9694 // Probably a CategoryPage
9795 $parentTag = $( '<div />' )
9896 .hide()
99 - .data( 'ctOptions', mw.config.get( 'wgCategoryTreePageCategoryOptions' ) )
 97+ .data( 'ctOptions', mw.config.get( 'wgCategoryTreePageCategoryOptions' ) );
10098 }
10199
102100 $.get(
@@ -109,7 +107,7 @@
110108 data = data.replace(/^\s+|\s+$/, '');
111109 data = data.replace(/##LOAD##/g, mw.msg( 'categorytree-expand' ) );
112110
113 - if ( data == '' ) {
 111+ if ( data === '' ) {
114112 switch ( $parentTag.data( 'ctMode' ) ) {
115113 case 0:
116114 data = mw.msg( 'categorytree-no-subcategories' );
@@ -124,32 +122,31 @@
125123 data = mw.msg( 'categorytree-nothing-found' );
126124 }
127125
128 - data = $( '<i class="CategoryTreeNotice" />' ).text( data );
 126+ data = $( '<i class="CategoryTreeNotice"></i>' ).text( data );
129127 }
130128
131129 $children
132130 .html( data )
133131 .find( '.CategoryTreeToggle' )
134 - .click( that.handleNode );
135 - that.showToggles();
 132+ .click( categoryTree.handleNode );
 133+ categoryTree.showToggles();
136134 } )
137135 .error( function() {
138136 var $retryLink = $( '<a />' )
139137 .text( mw.msg( 'categorytree-retry' ) )
140138 .attr( 'href', '#' )
141 - .click( function() { that.loadChildren( $link, $children ) } );
 139+ .click( function() { categoryTree.loadChildren( $link, $children ); } );
142140 $children
143141 .text( mw.msg( 'categorytree-error' ) )
144142 .append( $retryLink );
145143 } );
146144 }
 145+};
147146
148 - /**
149 - * Register any click events
150 - */
151 - $( function( $ ) {
152 - $( '.CategoryTreeToggle' ).click( that.handleNode );
 147+// Register click events and show toggle buttons
 148+$( function( $ ) {
 149+ $( '.CategoryTreeToggle' ).click( categoryTree.handleNode );
 150+ categoryTree.showToggles();
 151+} );
153152
154 - that.showToggles();
155 - } );
156153 } )( jQuery, mediaWiki );
\ No newline at end of file

Sign-offs

UserFlagDate
Krinkleinspected16:03, 16 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98563Followup r98500, conversion of the Javascript to use jQuery fully. It also ma...johnduhart21:08, 30 September 2011

Comments

#Comment by Krinkle (talk | contribs)   02:07, 3 October 2011

Looks good! I (or someone else) will review later, but at first sight looks ok. Signing off as inspected, haven't actually ran/tested it yet.

Status & tagging log