Index: trunk/extensions/CategoryTree/modules/ext.categoryTree.js |
— | — | @@ -12,41 +12,39 @@ |
13 | 13 | * in CategoryTree.php to avoid users getting stale copies from cache. |
14 | 14 | */ |
15 | 15 | |
16 | | -new ( function( $, mw ) { |
17 | | - /** |
18 | | - * Reference to this |
19 | | - * |
20 | | - * @var {this} |
21 | | - */ |
22 | | - var that = this; |
| 16 | +(function( $, mw ) { |
23 | 17 | |
| 18 | +var categoryTree = { |
24 | 19 | /** |
25 | 20 | * Sets display inline to tree toggle |
26 | 21 | */ |
27 | | - this.showToggles = function() { |
| 22 | + showToggles: function() { |
28 | 23 | $( 'span.CategoryTreeToggle' ).css( 'display', 'inline' ); |
29 | | - }; |
30 | | - |
| 24 | + }, |
| 25 | + |
31 | 26 | /** |
32 | 27 | * Handles clicks on the expand buttons, and calls the appropriate function |
| 28 | + * |
| 29 | + * @context {Element} CategoryTreeToggle |
| 30 | + * @param e {jQuery.Event} |
33 | 31 | */ |
34 | | - this.handleNode = function() { |
| 32 | + handleNode: function( e ) { |
35 | 33 | var $link = $( this ); |
36 | | - if ( $link.data( 'ctState' ) == 'collapsed' ) { |
37 | | - that.expandNode( $link ); |
| 34 | + if ( $link.data( 'ctState' ) === 'collapsed' ) { |
| 35 | + categoryTree.expandNode( $link ); |
38 | 36 | } else { |
39 | | - that.collapseNode( $link ); |
| 37 | + categoryTree.collapseNode( $link ); |
40 | 38 | } |
41 | | - } |
| 39 | + }, |
42 | 40 | |
43 | 41 | /** |
44 | 42 | * Expands a given node (loading it's children if not loaded) |
45 | 43 | * |
46 | 44 | * @param {jQuery} $link |
47 | 45 | */ |
48 | | - this.expandNode = function( $link ) { |
| 46 | + expandNode: function( $link ) { |
49 | 47 | // Show the children node |
50 | | - $children = $link.parents( '.CategoryTreeItem' ) |
| 48 | + var $children = $link.parents( '.CategoryTreeItem' ) |
51 | 49 | .siblings( '.CategoryTreeChildren' ); |
52 | 50 | $children.show(); |
53 | 51 | |
— | — | @@ -56,16 +54,16 @@ |
57 | 55 | .data( 'ctState', 'expanded' ); |
58 | 56 | |
59 | 57 | if ( !$link.data( 'ctLoaded' ) ) { |
60 | | - that.loadChildren( $link, $children ); |
| 58 | + categoryTree.loadChildren( $link, $children ); |
61 | 59 | } |
62 | | - }; |
| 60 | + }, |
63 | 61 | |
64 | 62 | /** |
65 | 63 | * Collapses a node |
66 | 64 | * |
67 | 65 | * @param {jQuery} $link |
68 | 66 | */ |
69 | | - this.collapseNode = function( $link ) { |
| 67 | + collapseNode: function( $link ) { |
70 | 68 | // Hide the children node |
71 | 69 | $link.parents( '.CategoryTreeItem' ) |
72 | 70 | .siblings( '.CategoryTreeChildren' ).hide(); |
— | — | @@ -74,28 +72,28 @@ |
75 | 73 | .html( mw.msg( 'categorytree-expand-bullet' ) ) |
76 | 74 | .attr( 'title', mw.msg( 'categorytree-expand' ) ) |
77 | 75 | .data( 'ctState', 'collapsed' ); |
78 | | - }; |
| 76 | + }, |
79 | 77 | |
80 | 78 | /** |
81 | | - * Loads children for a node |
| 79 | + * Loads children for a node via an HTTP call |
82 | 80 | * |
83 | 81 | * @param {jQuery} $link |
84 | 82 | * @param {jQuery} $children |
85 | 83 | */ |
86 | | - this.loadChildren = function( $link, $children ) { |
| 84 | + loadChildren: function( $link, $children ) { |
87 | 85 | $link.data( 'ctLoaded', true ); |
88 | 86 | $children.html( |
89 | | - '<i class="CategoryTreeNotice">' |
90 | | - + mw.msg( 'categorytree-loading' ) + "</i>" |
| 87 | + $( '<i class="CategoryTreeNotice"></i>' ) |
| 88 | + .text( mw.msg( 'categorytree-loading' ) ) |
91 | 89 | ); |
92 | 90 | |
93 | 91 | var $parentTag = $link.parents( '.CategoryTreeTag' ); |
94 | 92 | |
95 | | - if ( $parentTag.length == 0 ) { |
| 93 | + if ( $parentTag.length === 0 ) { |
96 | 94 | // Probably a CategoryPage |
97 | 95 | $parentTag = $( '<div />' ) |
98 | 96 | .hide() |
99 | | - .data( 'ctOptions', mw.config.get( 'wgCategoryTreePageCategoryOptions' ) ) |
| 97 | + .data( 'ctOptions', mw.config.get( 'wgCategoryTreePageCategoryOptions' ) ); |
100 | 98 | } |
101 | 99 | |
102 | 100 | $.get( |
— | — | @@ -109,7 +107,7 @@ |
110 | 108 | data = data.replace(/^\s+|\s+$/, ''); |
111 | 109 | data = data.replace(/##LOAD##/g, mw.msg( 'categorytree-expand' ) ); |
112 | 110 | |
113 | | - if ( data == '' ) { |
| 111 | + if ( data === '' ) { |
114 | 112 | switch ( $parentTag.data( 'ctMode' ) ) { |
115 | 113 | case 0: |
116 | 114 | data = mw.msg( 'categorytree-no-subcategories' ); |
— | — | @@ -124,32 +122,31 @@ |
125 | 123 | data = mw.msg( 'categorytree-nothing-found' ); |
126 | 124 | } |
127 | 125 | |
128 | | - data = $( '<i class="CategoryTreeNotice" />' ).text( data ); |
| 126 | + data = $( '<i class="CategoryTreeNotice"></i>' ).text( data ); |
129 | 127 | } |
130 | 128 | |
131 | 129 | $children |
132 | 130 | .html( data ) |
133 | 131 | .find( '.CategoryTreeToggle' ) |
134 | | - .click( that.handleNode ); |
135 | | - that.showToggles(); |
| 132 | + .click( categoryTree.handleNode ); |
| 133 | + categoryTree.showToggles(); |
136 | 134 | } ) |
137 | 135 | .error( function() { |
138 | 136 | var $retryLink = $( '<a />' ) |
139 | 137 | .text( mw.msg( 'categorytree-retry' ) ) |
140 | 138 | .attr( 'href', '#' ) |
141 | | - .click( function() { that.loadChildren( $link, $children ) } ); |
| 139 | + .click( function() { categoryTree.loadChildren( $link, $children ); } ); |
142 | 140 | $children |
143 | 141 | .text( mw.msg( 'categorytree-error' ) ) |
144 | 142 | .append( $retryLink ); |
145 | 143 | } ); |
146 | 144 | } |
| 145 | +}; |
147 | 146 | |
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 | +} ); |
153 | 152 | |
154 | | - that.showToggles(); |
155 | | - } ); |
156 | 153 | } )( jQuery, mediaWiki ); |
\ No newline at end of file |