r108533 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108532‎ | r108533 | r108534 >
Date:19:14, 10 January 2012
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
[MoodBar] Clean up + minor bug fix
* Declare missing dependency on 'user.tokens'
* Use $ instead of $j (deprecated)
* Use <shorttag> for element creation, and <valid></valid> for parsed snippets. jQuery uses a regex to detect <shorttag> and does doc.createElement('tag'). For anything else it uses innerHTML parser which should be given valid html, not shorthand code.
* Various JSLint/JSHint best practices
* Other code conventions (whitespace: like a space between // and the comment, no space between function name and arguments list, one space between operators and their value: `if ( .. ) `, `function ( .. ) `, `for ( .. ) `, and `someThing( .. )`, etc.)
* Function order
* Fix global variable leakage "$link"
* Fix global variable leakage "$item" (2x)
* Fix global variable leakage "$responseForm"
* CSS: One selector per line and space after colon for readability
* Trim trailing whitespace
Modified paths:
  • /trunk/extensions/MoodBar/MoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.css (modified) (history)
  • /trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.css
@@ -3,7 +3,7 @@
44 #fbd-filters {
55 position: absolute;
66 width: 15em;
7 - left: 0px; /* needed for ie6 & ie7 */
 7+ left: 0; /* needed for ie6 & ie7 */
88 }
99
1010 #fbd-filters form {
@@ -18,7 +18,8 @@
1919 margin-top: 0.5em;
2020 }
2121
22 -#fbd-description-text, #fbd-stats {
 22+#fbd-description-text,
 23+#fbd-stats {
2324 padding: 0 0 1em 0;
2425 }
2526
@@ -26,7 +27,7 @@
2728 font-size: 1.2em;
2829 margin: 0;
2930 padding: 0;
30 - border-bottom: solid 1px black;
 31+ border-bottom: 1px solid black;
3132 }
3233
3334 #fbd-filters-types {
@@ -93,8 +94,8 @@
9495 padding: 0;
9596 list-style: none;
9697 }
97 -.fbd-leaderboard li{
98 - margin: 0px;
 98+.fbd-leaderboard li {
 99+ margin: 0;
99100 padding: 2px 10px;
100101 list-style: none;
101102 font-weight:600;
@@ -109,12 +110,12 @@
110111 }
111112
112113 .fbd-leaderboard-top-responders {
113 - margin-top:15px;
 114+ margin-top: 15px;
114115 }
115116
116117 .fbd-leaderboard-top-responders h5 {
117 - border-bottom:1px solid #000000;
118 - padding-bottom:0px;
 118+ border-bottom: 1px solid #000000;
 119+ padding-bottom: 0;
119120 }
120121
121122 /* Tool Tip */
@@ -162,8 +163,8 @@
163164 /* List */
164165
165166 #fbd-list {
166 - margin: 0px 20px 0px 16em;
167 - padding: 0px;
 167+ margin: 0 20px 0 16em;
 168+ padding: 0;
168169 min-height: 20em;
169170 list-style: none;
170171 list-style-image: none; /* ie 7 fix */
@@ -178,15 +179,19 @@
179180 display: none;
180181 }
181182
182 -#fbd-list-more, #fbd-list-newer-older {
 183+#fbd-list-more,
 184+#fbd-list-newer-older {
183185 margin: 1em 0 0 13em;
184186 padding: 0.5em;
185187 background-color: #e8f2f8;
186188 }
187189
188 -#fbd-list-more a, #fbd-list-more span,
189 -#fbd-list-newer a, #fbd-list-older a,
190 -#fbd-list-newer .fbd-page-disabled, #fbd-list-older .fbd-page-disabled {
 190+#fbd-list-more a,
 191+#fbd-list-more span,
 192+#fbd-list-newer a,
 193+#fbd-list-older a,
 194+#fbd-list-newer .fbd-page-disabled,
 195+#fbd-list-older .fbd-page-disabled {
191196 font-size: 1.4em;
192197 background-repeat: no-repeat;
193198 }
@@ -206,7 +211,8 @@
207212 float: left;
208213 }
209214
210 -#fbd-list-newer a, #fbd-list-newer .fbd-page-disabled {
 215+#fbd-list-newer a,
 216+#fbd-list-newer .fbd-page-disabled {
211217 background-position: left center;
212218 padding-left: 20px;
213219 }
@@ -217,8 +223,8 @@
218224 }
219225
220226 .mw-ajax-loader {
221 - /* Undo padding due to it destroying the layout for inline response */
222 - padding: 8px 16px 0px 16px !important;
 227+ /* Undo padding due to it destroying the layout for inline response */
 228+ padding: 8px 16px 0 16px !important;
223229 }
224230
225231 /* The images here are named -ltr instead of -left and -rtl instead of -right
@@ -238,7 +244,8 @@
239245 float: right;
240246 }
241247
242 -#fbd-list-older a, #fbd-list-older .fbd-page-disabled {
 248+#fbd-list-older a,
 249+#fbd-list-older .fbd-page-disabled {
243250 background-position: right center;
244251 padding-right: 20px;
245252 }
@@ -258,7 +265,7 @@
259266 }
260267
261268 .fbd-item {
262 - border-bottom: solid 1px silver;
 269+ border-bottom: 1px solid silver;
263270 position: relative;
264271 padding-top: 0.5em;
265272 padding-right: 1em;
@@ -309,7 +316,7 @@
310317
311318 .fbd-item-response-icon {
312319 float: left;
313 - display: block;
 320+ display: block;
314321 height: 56px;
315322 width: 56px;
316323 background-position: center center;
@@ -326,14 +333,14 @@
327334 }
328335
329336 .fbd-item-response-success {
330 - /* @embed */
 337+ /* @embed */
331338 background-image: url(images/response-success.png);
332339 }
333 -
 340+
334341 .fbd-item-response-error {
335 - /* @embed */
 342+ /* @embed */
336343 background-image: url(images/response-error.png);
337 -}
 344+}
338345
339346 .fbd-ajax-response > div > .fbd-ajax-heading {
340347 font-size: 1.5em;
@@ -378,7 +385,7 @@
379386 }
380387
381388 .fbd-item-userLinks{
382 - font-size: 1em;
 389+ font-size: 1em;
383390 }
384391
385392 .fbd-item-time {
@@ -395,7 +402,7 @@
396403 }
397404
398405 .fbd-response-text {
399 - height: 5em;
 406+ height: 5em;
400407 overflow: hidden;
401408 }
402409
@@ -409,13 +416,13 @@
410417 }
411418
412419 .fbd-response-preview-block {
413 - width:100%; /* ie7 fix */
 420+ width:100%; /* ie7 fix */
414421 }
415422
416423 .fbd-response-wikitext{
417424 background-color: #FDFFE7;
418 - border: 1px solid #FCEB92;
419 - padding: 5px;
 425+ border: 1px solid #FCEB92;
 426+ padding: 5px;
420427 }
421428
422429 .fbd-item-permalink,
@@ -441,7 +448,6 @@
442449 visibility: visible;
443450 }
444451
445 -
446452 .fbd-respond-link {
447453 font-size: 1.1em;
448454 cursor: pointer;
@@ -458,19 +464,21 @@
459465 color: silver;
460466 }
461467 .fbd-response-form {
462 - margin:0em 0px 1em 81px;
 468+ margin: 0em 0 1em 81px;
463469 }
464470 .fbd-response-form b {
465471 font-size: 1em;
466472 }
467 -.fbd-response-form small, .fbd-response-form .small{
 473+.fbd-response-form small,
 474+.fbd-response-form .small{
468475 font-size: 0.8em;
469476 color: #262626;
470477 }
471478 .fbd-response-formNote {
472479 float: right;
473480 }
474 -.fbd-response-submit, .fbd-response-preview {
 481+.fbd-response-submit,
 482+.fbd-response-preview {
475483 float: right;
476484 }
477485 .center {
Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
@@ -1,50 +1,55 @@
22 /**
33 * AJAX code for Special:MoodBarFeedback
44 */
5 -jQuery(function( $ ) {
 5+jQuery( document ).ready( function ( $ ) {
66 /**
77 * Saved form state
88 */
9 - var formState = { types: [], username: '', myresponse: null, showunanswered: null };
10 -
 9+ var formState = {
 10+ types: [],
 11+ username: '',
 12+ myresponse: null,
 13+ showunanswered: null
 14+ };
 15+
1116 /**
12 - * Save the current form state to formState
13 - */
14 - function saveFormState() {
15 - formState.types = getSelectedTypes();
16 - formState.username = $( '#fbd-filters-username' ).val();
17 - formState.myresponse = $( '#fbd-filters-my-response' ).prop( 'checked' ) ? $( '#fbd-filters-my-response' ).val() : null;
18 - formState.showunanswered = $( '#fbd-filters-show-unanswered' ).prop( 'checked' ) ? $( '#fbd-filters-show-unanswered' ).val() : null;
19 - }
20 -
21 - /**
2217 * Figure out which comment type filters have been selected.
2318 * @return array of comment types
2419 */
2520 function getSelectedTypes() {
2621 var types = [];
27 - $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function() {
 22+ $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function () {
2823 if ( $(this).prop( 'checked' ) ) {
2924 types.push( $(this).val() );
3025 }
3126 } );
3227 return types;
3328 }
34 -
 29+
3530 /**
 31+ * Save the current form state to formState
 32+ */
 33+ function saveFormState() {
 34+ formState.types = getSelectedTypes();
 35+ formState.username = $( '#fbd-filters-username' ).val();
 36+ formState.myresponse = $( '#fbd-filters-my-response' ).prop( 'checked' ) ? $( '#fbd-filters-my-response' ).val() : null;
 37+ formState.showunanswered = $( '#fbd-filters-show-unanswered' ).prop( 'checked' ) ? $( '#fbd-filters-show-unanswered' ).val() : null;
 38+ }
 39+
 40+ /**
3641 * Select all comment type filters.
3742 */
3843 function selectAllTypes() {
39 - $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).prop( 'checked', true);
 44+ $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).prop( 'checked', true );
4045 }
4146 /**
4247 * Set the moodbar-feedback-types and moodbar-feedback-username cookies based on formState.
4348 * This function uses the form state saved in formState, so you may want to call saveFormState() first.
4449 */
4550 function setCookies() {
46 - $.cookie( 'moodbar-feedback-types', formState.types.join( '|' ), { 'path': '/', 'expires': 7 } );
 51+ $.cookie( 'moodbar-feedback-types', formState.types.join( '|' ), { path: '/', expires: 7 } );
4752 }
48 -
 53+
4954 /**
5055 * Load the form state from the moodbar-feedback-types and moodbar-feedback-username cookies.
5156 * This assumes the form is currently blank.
@@ -53,14 +58,14 @@
5459 function loadFromCookies() {
5560 var cookieTypes = $.cookie( 'moodbar-feedback-types' ),
5661 changed = false;
57 -
 62+
5863 if ( cookieTypes ) {
5964 // Because calling .indexOf() on an array doesn't work in all browsers,
6065 // we'll use cookieTypes.indexOf( '|valueWereLookingFor' ) . In order for
6166 // that to work, we need to prepend a pipe first.
6267 cookieTypes = '|' + cookieTypes;
63 - $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function() {
64 - if ( !$(this).prop( 'checked' ) && cookieTypes.indexOf( '|' + $(this).val() ) != -1 ) {
 68+ $( '#fbd-filters-type-praise, #fbd-filters-type-confusion, #fbd-filters-type-issues' ).each( function () {
 69+ if ( !$(this).prop( 'checked' ) && cookieTypes.indexOf( '|' + $(this).val() ) !== -1 ) {
6570 $(this).prop( 'checked', true );
6671 changed = true;
6772 }
@@ -70,7 +75,7 @@
7176 }
7277 return changed;
7378 }
74 -
 79+
7580 /**
7681 * Show a message in the box that normally contains the More link.
7782 * This will hide the more link, remove any existing <span>s,
@@ -92,16 +97,16 @@
9398 * Load a set of 20 comments into the list. In 'filter' mode, the list is
9499 * blanked before the new comments are loaded. In 'more' mode, the comments are
95100 * loaded at the end of the existing set.
96 - *
 101+ *
97102 * This function uses the form state saved in formState, so you may want to call saveFormState() first.
98 - *
 103+ *
99104 * @param mode string Either 'filter' or 'more'
100105 */
101106 function loadComments( mode ) {
102107 var limit = 20,
103108 reqData;
104 -
105 - if ( mode == 'filter' ) {
 109+
 110+ if ( mode === 'filter' ) {
106111 $( '#fbd-list' ).empty();
107112 }
108113 // Hide the "More" link and put in a spinner
@@ -114,18 +119,18 @@
115120 .end()
116121 .children( 'span' )
117122 .remove(); // Remove any message added by showMessage()
118 -
 123+
119124 // Build the API request
120 - // FIXME: in 'more' mode, changing the filters then clicking More will use the wrong criteria
 125+ // @todo FIXME: in 'more' mode, changing the filters then clicking More will use the wrong criteria
121126 reqData = {
122 - 'action': 'query',
123 - 'list': 'moodbarcomments',
124 - 'format': 'json',
125 - 'mbcprop': 'formatted',
126 - 'mbclimit': limit + 2 // we drop the first and last result
 127+ format: 'json',
 128+ action: 'query',
 129+ list: 'moodbarcomments',
 130+ mbcprop: 'formatted',
 131+ mbclimit: limit + 2 // we drop the first and last result
127132 };
128 - if ( mode == 'more' ) {
129 - reqData.mbccontinue = $( '#fbd-list').find( 'li:last' ).data( 'mbccontinue' );
 133+ if ( mode === 'more' ) {
 134+ reqData.mbccontinue = $( '#fbd-list' ).find( 'li:last' ).data( 'mbccontinue' );
130135 }
131136 if ( formState.types.length ) {
132137 reqData.mbctype = formState.types.join( '|' );
@@ -139,37 +144,37 @@
140145 if ( formState.showunanswered ) {
141146 reqData.mbcshowunanswered = formState.showunanswered;
142147 }
143 -
 148+
144149 $.ajax( {
145 - 'url': mw.util.wikiScript( 'api' ),
146 - 'data': reqData,
147 - 'success': function( data ) {
 150+ url: mw.util.wikiScript( 'api' ),
 151+ data: reqData,
 152+ success: function ( data ) {
148153 // Remove the spinner and restore the "More" link
149154 $( '#fbd-list-more' )
150155 .removeClass( 'mw-ajax-loader' )
151156 .children( 'a' )
152157 .css( 'visibility', 'visible' ); // Undo visibility: hidden;
153 -
 158+
154159 if ( !data || !data.query || !data.query.moodbarcomments ) {
155160 showMessage( mw.msg( 'moodbar-feedback-ajaxerror' ) );
156161 return;
157162 }
158 -
 163+
159164 var comments = data.query.moodbarcomments,
160165 len = comments.length,
161166 $ul = $( '#fbd-list' ),
162167 moreResults = false,
163168 i;
164169 if ( len === 0 ) {
165 - if ( mode == 'more' ) {
 170+ if ( mode === 'more' ) {
166171 showMessage( mw.msg( 'moodbar-feedback-nomore' ) );
167172 } else {
168173 showMessage( mw.msg( 'moodbar-feedback-noresults' ) );
169174 }
170175 return;
171176 }
172 -
173 - if ( mode == 'more' ) {
 177+
 178+ if ( mode === 'more' ) {
174179 // Drop the first element because it duplicates the last shown one
175180 comments.shift();
176181 len--;
@@ -179,158 +184,159 @@
180185 len = limit;
181186 moreResults = true;
182187 }
183 -
184 - for ( i = 0; i < len; i++ ) {
 188+
 189+ for ( i = 0; i < len; i+= 1 ) {
185190 $ul.append( comments[i].formatted );
186191 }
187 -
 192+
188193 if ( !moreResults ) {
189 - if ( mode == 'more' ) {
 194+ if ( mode === 'more' ) {
190195 showMessage( mw.msg( 'moodbar-feedback-nomore' ) );
191196 } else {
192197 $( '#fbd-list-more' ).hide();
193198 }
194199 }
195200 },
196 - 'error': function( jqXHR, textStatus, errorThrown ) {
 201+ error: function ( jqXHR, textStatus, errorThrown ) {
197202 $( '#fbd-list-more' ).removeClass( 'mw-ajax-loader' );
198 - showMessage( mw.msg( 'moodbar-feedback-ajaxerror' ) );
 203+ showMessage( mw.msg( 'moodbar-feedback-ajaxerror' ) );
199204 },
200 - 'dataType': 'json'
 205+ dataType: 'json'
201206 } );
202207 }
203 -
 208+
204209 /**
205210 * Reload a comment, showing hidden comments if necessary
206211 * @param $item jQuery item containing the .fbd-item
207212 * @param show Set to true to show the comment despite its hidden status
208213 */
209214 function reloadItem( $item, show ) {
210 - var cont = $item.data('mbccontinue');
211 -
212 - var request = {
213 - 'action' : 'query',
214 - 'list' : 'moodbarcomments',
215 - 'format' : 'json',
216 - 'mbcprop' : 'formatted',
217 - 'mbclimit' : 1,
218 - 'mbccontinue' : cont
 215+ var cont, request;
 216+ cont = $item.data( 'mbccontinue' );
 217+
 218+ request = {
 219+ action: 'query',
 220+ list: 'moodbarcomments',
 221+ format: 'json',
 222+ mbcprop: 'formatted',
 223+ mbclimit: 1,
 224+ mbccontinue: cont
219225 };
220 -
 226+
221227 if ( show ) {
222228 request.mbcprop = 'formatted|hidden';
223229 }
224 -
225 - $.post( mw.util.wikiScript('api'), request,
226 - function( data ) {
 230+
 231+ $.post( mw.util.wikiScript( 'api' ), request,
 232+ function ( data ) {
227233 if ( data && data.query && data.query.moodbarcomments &&
228234 data.query.moodbarcomments.length > 0
229235 ) {
230 - var $content = $j(data.query.moodbarcomments[0].formatted);
231 - $item.replaceWith($content);
 236+ var $content = $( data.query.moodbarcomments[0].formatted );
 237+ $item.replaceWith( $content );
232238 } else {
233239 // Failure, just remove the link.
234 - $item.find('.fbd-item-show').remove();
235 - $item.find('.mw-ajax-loader').remove();
 240+ $item.find( '.fbd-item-show' ).remove();
 241+ $item.find( '.mw-ajax-loader' ).remove();
236242 showItemError( $item );
237243 }
238244 }, 'json' )
239 - .error( function() { showItemError( $item ); } );
 245+ .error( function () { showItemError( $item ); } );
240246 }
241 -
 247+
242248 /**
243249 * Show a hidden comment
244250 */
245251 function showHiddenItem(e) {
246 - var $item = $(this).closest('.fbd-item');
247 -
248 - var $spinner = $('<span class="mw-ajax-loader">&nbsp;</span>');
249 - $item.find('.fbd-item-show').empty().append( $spinner );
250 -
 252+ var $item = $(this).closest( '.fbd-item' );
 253+
 254+ var $spinner = $( '<span class="mw-ajax-loader">&nbsp;</span>' );
 255+ $item.find( '.fbd-item-show' ).empty().append( $spinner );
 256+
251257 reloadItem( $item, true );
252 -
 258+
253259 e.preventDefault();
254260 }
255 -
 261+
256262 /**
257263 * Show an error on an individual item
258264 * @param $item The .fbd-item to show the message on
259265 * @param message The message to show (currently ignored)
260266 */
261267 function showItemError( $item, message ) {
262 - $item.find('.mw-ajax-loader').remove();
263 - $('<div class="error"/>')
264 - .text( mw.msg('moodbar-feedback-action-error') )
265 - .prependTo($item);
 268+ $item.find( '.mw-ajax-loader' ).remove();
 269+ $( '<div class="error"></div>' )
 270+ .text( mw.msg( 'moodbar-feedback-action-error' ) )
 271+ .prependTo( $item );
266272 }
267 -
 273+
268274 /**
269275 * Do this before administrative action to confirm action and provide reason
270 - * @param params to store action paramaters
 276+ * @param params to store action paramaters
271277 * @param $item jQuery item containing the .fbd-item
272278 */
273 - function confirmAction(params, $item){
274 -
275 - var inlineForm = $('<span>').attr('class', 'fbd-item-reason')
276 - .append( $('<span>').text(mw.msg( 'moodbar-action-reason' )) )
277 - .append( $('<input />').attr({'class':'fbd-action-reason', 'name':'fbd-action-reason'}) )
278 - .append( $('<button>').attr('class', 'fbd-action-confirm').text( mw.msg('moodbar-feedback-action-confirm')) )
279 - .append( $('<button>').attr('class', 'fbd-action-cancel').text( mw.msg('moodbar-feedback-action-cancel')) )
280 - .append( $('<span>').attr('class', 'fbd-item-reason-msg') )
281 - .append( $('<div>').attr('class', 'fbd-item-reason-msg') );
 279+ function confirmAction( params, $item ) {
282280
 281+ var inlineForm = $( '<span>' ).attr( 'class', 'fbd-item-reason' )
 282+ .append( $( '<span>' ).text(mw.msg( 'moodbar-action-reason' )) )
 283+ .append( $( '<input>' ).attr({'class':'fbd-action-reason', 'name':'fbd-action-reason'}) )
 284+ .append( $( '<button>' ).attr( 'class', 'fbd-action-confirm' ).text( mw.msg( 'moodbar-feedback-action-confirm' )) )
 285+ .append( $( '<button>' ).attr( 'class', 'fbd-action-cancel' ).text( mw.msg( 'moodbar-feedback-action-cancel' )) )
 286+ .append( $( '<span>' ).attr( 'class', 'fbd-item-reason-msg' ) )
 287+ .append( $( '<div>' ).attr( 'class', 'fbd-item-reason-msg' ) );
 288+
283289 var storedParams = params;
284290 var $storedItem = $item;
285 -
286 - $item.find('.fbd-item-hide, .fbd-item-restore, .fbd-item-permalink')
 291+
 292+ $item.find( '.fbd-item-hide, .fbd-item-restore, .fbd-item-permalink' )
287293 .empty();
288 -
289 - $item.find('.fbd-item-message')
 294+
 295+ $item.find( '.fbd-item-message' )
290296 .append(inlineForm);
291 -
292 - $('.fbd-action-confirm').click( function() {
293 - storedParams.reason = $storedItem.find('.fbd-action-reason').val();
294 -
295 - if( storedParams.reason ) {
296 - doAction(storedParams, $storedItem);
 297+
 298+ $( '.fbd-action-confirm' ).click( function () {
 299+ storedParams.reason = $storedItem.find( '.fbd-action-reason' ).val();
 300+
 301+ if ( storedParams.reason ) {
 302+ doAction( storedParams, $storedItem );
297303 } else {
298 - inlineMessage($storedItem.find('.fbd-item-reason'), mw.msg( 'moodbar-action-reason-required' ), function() {
 304+ inlineMessage( $storedItem.find( '.fbd-item-reason' ), mw.msg( 'moodbar-action-reason-required' ), function () {
299305 reloadItem( $storedItem, true );
300 - });
 306+ });
301307 }
302 -
 308+
303309 });
304 - $('.fbd-action-cancel').click( function() {
 310+ $( '.fbd-action-cancel' ).click( function () {
305311 reloadItem( $storedItem, true );
306312 });
307 -
 313+
308314 }
309 -
 315+
310316 /**
311317 * Execute an action on an item
312318 * @param params contains action parameters
313319 * @param $item jQuery item containing the .fbd-item
314320 */
315321 function doAction( params, $item ) {
316 - var item_id = $item.data('mbccontinue').split('|')[1];
317 -
318 - var errorHandler = function(error_str) {
 322+ var item_id = $item.data( 'mbccontinue' ).split( '|' )[1];
 323+
 324+ var errorHandler = function ( error_str ) {
319325 showItemError( $item, error_str );
320326 };
321 -
322 - var $spinner = $('<span class="mw-ajax-loader">&nbsp;</span>');
323 - $item.find('.fbd-item-hide').empty().append( $spinner );
324 -
325 - $.post( mw.util.wikiScript('api'),
 327+
 328+ var $spinner = $( '<span class="mw-ajax-loader">&nbsp;</span>' );
 329+ $item.find( '.fbd-item-hide' ).empty().append( $spinner );
 330+
 331+ $.post( mw.util.wikiScript( 'api' ),
326332 $.extend( {
327 - 'action' : 'feedbackdashboard',
328 - 'token' : mw.user.tokens.get('editToken'),
329 - 'item' : item_id,
330 - 'format' : 'json'
 333+ action: 'feedbackdashboard',
 334+ token: mw.user.tokens.get( 'editToken' ),
 335+ item: item_id,
 336+ format: 'json'
331337 }, params ),
332 - function(response) {
 338+ function ( response ) {
333339 if ( response && response.feedbackdashboard ) {
334 - if ( response.feedbackdashboard.result == 'success' ) {
 340+ if ( response.feedbackdashboard.result === 'success' ) {
335341 reloadItem( $item );
336342 } else {
337343 errorHandler( response.feedbackdashboard.error );
@@ -343,178 +349,180 @@
344350 } )
345351 .error( errorHandler );
346352 }
347 -
 353+
348354 /**
349355 * Restore a hidden item to full visibility (event handler)
 356+ * @param e {jQuery.Event}
350357 */
351 - function restoreItem(e) {
352 - var $item = $(this).closest('.fbd-item');
353 -
354 - confirmAction( { 'mbaction' : 'restore' }, $item );
 358+ function restoreItem( e ) {
 359+ var $item = $(this).closest( '.fbd-item' );
 360+
 361+ confirmAction( { mbaction: 'restore' }, $item );
355362 e.preventDefault();
356363 }
357 -
 364+
358365 /**
359366 * Hide a item from view (event handler)
 367+ * @param e {jQuery.Event}
360368 */
361 - function hideItem(e) {
362 - var $item = $(this).closest('.fbd-item');
363 - closeAllResponders(); //if any are open
364 - confirmAction( { 'mbaction' : 'hide' }, $item );
 369+ function hideItem( e ) {
 370+ var $item = $(this).closest( '.fbd-item' );
 371+ closeAllResponders(); // If any are open
 372+ confirmAction( { mbaction: 'hide' }, $item );
365373 e.preventDefault();
366374 }
367 -
 375+
368376 /**
369377 * Method to close all responders.
370378 * Remove all .fbd-response-form from the dashboard
371379 */
372380 function closeAllResponders() {
373 -
374 - $( '.fbd-item').each(function(index, value){
375 -
376 - $link = $( this ).find('.fbd-respond-link');
377 - if( $link.hasClass('responder-expanded') ) {
378 -
379 - $link.find('.fbd-item-response-expanded')
380 - .addClass('fbd-item-response-collapsed')
381 - .removeClass('fbd-item-response-expanded')
 381+
 382+ $( '.fbd-item' ).each( function () {
 383+
 384+ var $link = $( this ).find( '.fbd-respond-link' );
 385+ if ( $link.hasClass( 'responder-expanded' ) ) {
 386+
 387+ $link.find( '.fbd-item-response-expanded' )
 388+ .addClass( 'fbd-item-response-collapsed' )
 389+ .removeClass( 'fbd-item-response-expanded' )
382390 .end()
383 - .find('.fbd-item-response-collapsed')
 391+ .find( '.fbd-item-response-collapsed' )
384392 .parent()
385 - .removeClass('responder-expanded');
 393+ .removeClass( 'responder-expanded' );
386394 //remove disabled prop to prevent memory leaks in IE < 9
387 - $( '.fbd-response-preview, .fbd-response-submit').removeProp('disabled');
388 - $( this ).find('.fbd-response-form').remove();
389 - }
 395+ $( '.fbd-response-preview, .fbd-response-submit' ).removeProp( 'disabled' );
 396+ $( this ).find( '.fbd-response-form' ).remove();
 397+ }
390398 });
391399 }
392 -
 400+
393401 /**
394402 * Show the Response form for the item
395403 * Build the response form elements once
396 - *
 404+ * @param e {jQuery.Event}
397405 */
398 - function showResponseForm(e){
399 -
400 - if( $(this).hasClass('responder-expanded') ) {
401 -
402 - closeAllResponders();
403 -
404 - } else {
405 -
406 - //init terms of use link
407 - var termsLink = mw.html.element ('a', {
 406+ function showResponseForm( e ) {
 407+
 408+ if ( $(this).hasClass( 'responder-expanded' ) ) {
 409+
 410+ closeAllResponders();
 411+
 412+ } else {
 413+
 414+ // Init terms of use link
 415+ var termsLink = mw.html.element ( 'a', {
408416 'href': mw.msg( 'moodbar-response-url' ),
409417 'title': mw.msg( 'moodbar-response-link' ),
410418 'target': '_new'
411419 }, mw.msg( 'moodbar-response-link' ) );
412 -
413 - //ULA
 420+
 421+ // ULA
414422 var ula = mw.msg( 'moodbar-response-terms' )
415423 .replace ( /\$1/g, termsLink );
416 -
417 - //build form
418 - var inlineForm = $('<div>').attr( 'class', 'fbd-response-form' )
 424+
 425+ // Build form
 426+ var inlineForm = $( '<div>' ).attr( 'class', 'fbd-response-form' )
419427 .append(
420 - $('<b>').text( mw.msg( 'moodbar-response-add' ) )
 428+ $( '<b>' ).text( mw.msg( 'moodbar-response-add' ) )
421429 ).append(
422 - $('<small>').attr( 'class', 'fbd-text-gray' ).text( ' (' + mw.msg( 'moodbar-response-desc' ) + ') ' )
 430+ $( '<small>' ).attr( 'class', 'fbd-text-gray' ).text( ' (' + mw.msg( 'moodbar-response-desc' ) + ') ' )
423431 ).append(
424 - $('<div>').attr( 'class', 'fbd-response-formNote' )
425 - .append($('<small>')
 432+ $( '<div>' ).attr( 'class', 'fbd-response-formNote' )
 433+ .append( $( '<small>' )
426434 .append(
427 - $('<span>').attr( 'class', 'fbd-response-charCount' )
 435+ $( '<span>' ).attr( 'class', 'fbd-response-charCount' )
428436 ).append(
429 - $('<span>').text( mw.msg( 'moodbar-form-note-dynamic' ).replace( /\$1/g, "" ) )
 437+ $( '<span>' ).text( mw.msg( 'moodbar-form-note-dynamic' ).replace( /\$1/g, "" ) )
430438 )
431439 )
432440 ).append(
433 - $('<textarea>').attr( { 'class':'fbd-response-text', 'name':'fbd-response-text' } )
 441+ $( '<textarea>' ).attr( { 'class':'fbd-response-text', 'name':'fbd-response-text' } )
434442 ).append(
435 - $('<div />').attr('class', 'fbd-response-preview-spinner')
436 - .append($('<span />').attr('class', 'mw-ajax-loader')
 443+ $( '<div>' ).attr( 'class', 'fbd-response-preview-spinner' )
 444+ .append( $( '<span>' ).attr( 'class', 'mw-ajax-loader' )
437445 //hack the .mw-ajax-loader styles beacuse they are horrible for reuse
438 - .css({ 'top':'0px','padding':'16px', 'display':'block', 'width':'32px' }).html('&nbsp;')
439 - ).hide()
 446+ .css({ 'top':'0px','padding':'16px', 'display':'block', 'width':'32px' }).html( '&nbsp;' )
 447+ ).hide()
440448 ).append(
441 - $('<div />').attr('class', 'fbd-response-preview-block')
 449+ $( '<div>' ).attr( 'class', 'fbd-response-preview-block' )
442450 .append(
443 - $('<div />').attr('class', 'fbd-response-wikitext').hide())
 451+ $( '<div>' ).attr( 'class', 'fbd-response-wikitext' ).hide())
444452 .append(
445 - $('<div>').attr('class', 'ula small').html( ula ).hide())
 453+ $( '<div>' ).attr( 'class', 'ula small' ).html( ula ).hide())
446454 ).append(
447 - $('<button>').attr( 'class', 'fbd-response-submit' ).html( mw.msg( 'moodbar-response-btn' ) + '&nbsp;<span class="fbd-item-send-response-icon"></span>' )
 455+ $( '<button>' ).attr( 'class', 'fbd-response-submit' ).html( mw.msg( 'moodbar-response-btn' ) + '&nbsp;<span class="fbd-item-send-response-icon"></span>' )
448456 .prop( 'disabled', true ).hide()
449457 ).append(
450 - $('<button>').attr('class', 'fbd-response-preview-back').text( mw.msg( 'response-back-text' ) ).hide()
 458+ $( '<button>' ).attr( 'class', 'fbd-response-preview-back' ).text( mw.msg( 'response-back-text' ) ).hide()
451459 ).append(
452 - $('<button>').attr( 'class', 'fbd-response-preview').text ( mw.msg( 'response-preview-text' ) ).prop( 'disabled', true )
 460+ $( '<button>' ).attr( 'class', 'fbd-response-preview' ).text ( mw.msg( 'response-preview-text' ) ).prop( 'disabled', true )
453461 ).append(
454 - $('<div>').attr( 'style', 'clear:both' )
 462+ $( '<div>' ).attr( 'style', 'clear:both' )
455463 );
456 -
457 - //get the feedbackItem
458 - var $item = $(this).closest('.fbd-item');
459 - //close any open responders prior to opening this one.
 464+
 465+ // Get the feedbackItem
 466+ var $item = $(this).closest( '.fbd-item' );
 467+ // Close any open responders prior to opening this one.
460468 closeAllResponders();
461 -
462 - $(this).find('.fbd-item-response-collapsed')
463 - .addClass('fbd-item-response-expanded')
464 - .removeClass('fbd-item-response-collapsed')
 469+
 470+ $(this).find( '.fbd-item-response-collapsed' )
 471+ .addClass( 'fbd-item-response-expanded' )
 472+ .removeClass( 'fbd-item-response-collapsed' )
465473 .end()
466 - .find('.fbd-item-response-expanded')
 474+ .find( '.fbd-item-response-expanded' )
467475 .parent()
468 - .addClass('responder-expanded');
 476+ .addClass( 'responder-expanded' );
469477
470478 $item.append(inlineForm)
471 - .find('.fbd-response-text')
472 - .NobleCount('.fbd-response-charCount', {
 479+ .find( '.fbd-response-text' )
 480+ .NobleCount( '.fbd-response-charCount', {
473481 max_chars:5000,
474482 /*
475483 * Callbacks:
476484 * function on_negative: called when text field is negative in remaining characters.
477 - * @param t_obj is the text object. need to pass to the callback to add modifiers.
 485+ * @param t_obj is the text object. need to pass to the callback to add modifiers.
478486 */
479 - on_negative: function( t_obj ) {
 487+ on_negative: function ( t_obj ) {
480488 $( t_obj )
481489 .prev()
482 - .find('span')
483 - .addClass('red-bold');
 490+ .find( 'span' )
 491+ .addClass( 'red-bold' );
484492 },
485493 /*
486494 * function on_positive: called when text field has available remaining characters.
487 - * @param t_obj is the text object. need to pass to the callback to add modifiers.
 495+ * @param t_obj is the text object. need to pass to the callback to add modifiers.
488496 */
489 - on_positive: function( t_obj ) {
 497+ on_positive: function ( t_obj ) {
490498 $( t_obj )
491499 .prev()
492 - .find('span')
493 - .removeClass('red-bold');
 500+ .find( 'span' )
 501+ .removeClass( 'red-bold' );
494502 }
495503 })
496504 .end()
497 - .find('.fbd-response-text')
498 - .keyup( function(event) {
499 - validateResponse($item);
 505+ .find( '.fbd-response-text' )
 506+ .keyup( function ( e ) {
 507+ validateResponse( $item );
500508 })
501509 .elastic()
502510 .end()
503 - .find('.fbd-response-preview')
 511+ .find( '.fbd-response-preview' )
504512 .click (function () {
505513 //toggle preview
506514 $item = $(this).parent().parent();
507 - $item.find('.fbd-response-preview, .fbd-response-text').hide();
508 - $item.find('.fbd-response-submit, .fbd-response-preview-back, .ula').show();
509 - var wikitext = $item.find('.fbd-response-text').val();
510 - wikitext = wikitext.replace(/~{3,5}/g, '') + "\n\n~~~~"; //remove and add signature for
511 - parseWikiText($item, wikitext);
 515+ $item.find( '.fbd-response-preview, .fbd-response-text' ).hide();
 516+ $item.find( '.fbd-response-submit, .fbd-response-preview-back, .ula' ).show();
 517+ var wikitext = $item.find( '.fbd-response-text' ).val();
 518+ wikitext = wikitext.replace( /~{3,5}/g, '' ) + "\n\n~~~~"; // Remove and add signature for
 519+ parseWikiText( $item, wikitext );
512520 });
513 - }
 521+ }
514522 e.preventDefault();
515523 }
516524
517 - function parseWikiText($item, wikitext) {
518 - $item.find('.fbd-response-preview-spinner').show();
 525+ function parseWikiText( $item, wikitext ) {
 526+ $item.find( '.fbd-response-preview-spinner' ).show();
519527 $.ajax({
520528 url: mw.util.wikiScript( 'api' ),
521529 data: {
@@ -527,22 +535,22 @@
528536 },
529537 dataType: 'json',
530538 type: 'POST',
531 - success: function( data ) {
 539+ success: function ( data ) {
532540 $item
533 - .find('.fbd-response-preview-spinner') //fadeout spinner
 541+ .find( '.fbd-response-preview-spinner' ) // Fadeout spinner
534542 .hide()
535543 .end()
536 - .find('.fbd-response-wikitext')
 544+ .find( '.fbd-response-wikitext' )
537545 .html( data.parse.text['*'] )
538546 .fadeIn()
539547 .end();
540548 },
541 - error: function() {
542 - //handle error
543 - //fadeout spinner
 549+ error: function () {
 550+ // Handle error
 551+ // @todo: Fadeout spinner
544552 }
545553 });
546 - }
 554+ }
547555
548556 /**
549557 * Toggle submit / preview button from enabled to disabled
@@ -550,15 +558,15 @@
551559 * @param $item jQuery item containing the .fbd-item
552560 * Require at least 1 character and limit to 5000
553561 */
554 - function validateResponse($item) {
555 - var response = $.trim( $item.find('.fbd-response-text').val() );
556 - if( response.length > 0 && response.length <= 5000 ) {
557 - $item.find( '.fbd-response-submit, .fbd-response-preview').prop('disabled', false);
 562+ function validateResponse( $item ) {
 563+ var response = $.trim( $item.find( '.fbd-response-text' ).val() );
 564+ if ( response.length > 0 && response.length <= 5000 ) {
 565+ $item.find( '.fbd-response-submit, .fbd-response-preview' ).prop( 'disabled', false);
558566 } else {
559 - $item.find( '.fbd-response-submit, .fbd-response-preview').prop('disabled', true);
 567+ $item.find( '.fbd-response-submit, .fbd-response-preview' ).prop( 'disabled', true);
560568 }
561569 }
562 -
 570+
563571 /**
564572 * Generic inline message, with fadeout
565573 * @param $el Element to display message inside
@@ -569,7 +577,7 @@
570578 $el.empty()
571579 .text( msg )
572580 .delay(2000)
573 - .fadeOut('slow', callback);
 581+ .fadeOut( 'slow', callback);
574582 }
575583 /**
576584 * Set status message for Send Response
@@ -578,161 +586,161 @@
579587 * @param head Heading text to be displayed
580588 * @param body Body text to be displayed
581589 */
582 - function responseMessage ($el, type, head, body) {
 590+ function responseMessage( $el, type, head, body ) {
583591 $el
584 - .find('.mw-ajax-loader')
585 - .addClass('fbd-item-response-' + type)
586 - .removeClass('mw-ajax-loader')
 592+ .find( '.mw-ajax-loader' )
 593+ .addClass( 'fbd-item-response-' + type )
 594+ .removeClass( 'mw-ajax-loader' )
587595 .end()
588 - .find('.fbd-ajax-heading')
589 - .text( head )
 596+ .find( '.fbd-ajax-heading' )
 597+ .text( head )
590598 .end()
591 - .find('.fbd-ajax-text')
 599+ .find( '.fbd-ajax-text' )
592600 .html( body )
593601 .end();
594 - setTimeout(function(){
595 - reloadItem($el, true);
 602+ setTimeout( function () {
 603+ reloadItem( $el, true );
596604 }, 2000);
597605 }
598 - /* Display tooltip for response concurrency notification
 606+
 607+ /**
 608+ * Display tooltip for response concurrency notification
599609 * @param $item Feedback item
600 - */
601 - function loadToolTip($item) {
602 - var tooltip = $('<div>').attr('class', 'fbd-tooltip-overlay-wrap')
 610+ */
 611+ function loadToolTip( $item ) {
 612+ var tooltip = $( '<div>' ).attr( 'class', 'fbd-tooltip-overlay-wrap' )
603613 .append(
604 - $('<div>').attr('class', 'fbd-tooltip-overlay')
 614+ $( '<div>' ).attr( 'class', 'fbd-tooltip-overlay' )
605615 .append(
606 - $('<div>').attr('class', 'fbd-tooltip-pointy')
 616+ $( '<div>' ).attr( 'class', 'fbd-tooltip-pointy' )
607617 ).append(
608 - $('<div>').attr('class', 'fbd-tooltip-title')
609 - .text( mw.msg( 'response-concurrency-notification' ) )
 618+ $( '<div>' ).attr( 'class', 'fbd-tooltip-title' )
 619+ .text( mw.msg( 'response-concurrency-notification' ) )
610620 .prepend(
611 - $('<span>').attr('class', 'fbd-tooltip-close').text('X')
 621+ $( '<span>' ).attr( 'class', 'fbd-tooltip-close' ).text( 'X' )
612622 )
613623 )
614624 );
615625 $item.append( tooltip );
616 - //close event, closure remembers object
 626+ // Close event, closure remembers object
617627 $( '.fbd-tooltip-close' )
618 - .live( 'click' , function() {
 628+ .live( 'click' , function () {
619629 tooltip.remove();
620630 });
621 - setTimeout( function() {
622 - tooltip.fadeOut(function(tooltip){
 631+ setTimeout( function () {
 632+ tooltip.fadeOut(function ( tooltip ) {
623633 tooltip.remove();
624634 });
625 - }, 1500 );
 635+ }, 1500 );
626636
627637 }
 638+
628639 // On-load stuff
629 -
630 - $('.fbd-item-show a').live( 'click', showHiddenItem );
631 -
632 - $('.fbd-item-hide a').live( 'click', hideItem );
633 -
634 - $('.fbd-item-restore').live( 'click', restoreItem );
635 -
636 - $('.fbd-respond-link').live ('click', showResponseForm );
637 -
638 - //handle preview back button
639 - $('.fbd-response-preview-back').live('click', function(){
640 - $item = $(this).parent().parent();
641 - $item.find('.fbd-response-submit, .fbd-response-wikitext, .fbd-response-preview-back, .ula').hide();
642 - $item.find('.fbd-response-preview, .fbd-response-text').show();
 640+ $( '.fbd-item-show a' ).live( 'click', showHiddenItem );
 641+ $( '.fbd-item-hide a' ).live( 'click', hideItem );
 642+ $( '.fbd-item-restore' ).live( 'click', restoreItem );
 643+ $( '.fbd-respond-link' ).live ( 'click', showResponseForm );
 644+
 645+ // Handle preview back button
 646+ $( '.fbd-response-preview-back' ).live( 'click', function () {
 647+ var $item = $(this).parent().parent();
 648+ $item.find( '.fbd-response-submit, .fbd-response-wikitext, .fbd-response-preview-back, .ula' ).hide();
 649+ $item.find( '.fbd-response-preview, .fbd-response-text' ).show();
643650 });
644651
645 - //handle response submit
646 - $('.fbd-response-submit').live('click', function () {
647 - $item = $(this).parent().parent();
648 - var fbResponse = $item.find('.fbd-response-text').val();
649 - if( fbResponse ){
 652+ // Handle response submit
 653+ $( '.fbd-response-submit' ).live( 'click', function () {
 654+ var $item = $(this).parent().parent();
 655+ var fbResponse = $item.find( '.fbd-response-text' ).val();
 656+ if ( fbResponse ) {
650657 var clientData = $.client.profile(),
651 - item_id = $item.data('mbccontinue').split('|')[1],
 658+ item_id = $item.data( 'mbccontinue' ).split( '|' )[1],
652659 resData = {
653 - 'action':'feedbackdashboardresponse',
654 - 'useragent': clientData.name + '/' + clientData.versionNumber,
655 - 'system': clientData.platform,
656 - 'token': mw.user.tokens.get( 'editToken' ),
657 - 'response': fbResponse,
658 - 'feedback': item_id,
659 - 'format':'json'
 660+ action: 'feedbackdashboardresponse',
 661+ useragent: clientData.name + '/' + clientData.versionNumber,
 662+ system: clientData.platform,
 663+ token: mw.user.tokens.get( 'editToken' ),
 664+ response: fbResponse,
 665+ feedback: item_id,
 666+ format: 'json'
660667 };
661 -
662 - var $responseStatus = $('<div />').attr('class', 'fbd-ajax-response')
663 - .append($('<span />').attr('class','mw-ajax-loader fbd-item-response-icon').html('&nbsp;') )
664 - .append($('<div />')
665 - .append($('<span />').attr('class', 'fbd-ajax-heading').text( mw.msg( 'response-ajax-action-head' ) ) )
666 - .append($('<span />').attr('class', 'fbd-ajax-text').text( mw.msg( 'response-ajax-action-body' ) ) )
 668+
 669+ var $responseStatus = $( '<div>' ).attr( 'class', 'fbd-ajax-response' )
 670+ .append( $( '<span>' ).attr( 'class','mw-ajax-loader fbd-item-response-icon' ).html( '&nbsp;' ) )
 671+ .append( $( '<div>' )
 672+ .append( $( '<span>' ).attr( 'class', 'fbd-ajax-heading' ).text( mw.msg( 'response-ajax-action-head' ) ) )
 673+ .append( $( '<span>' ).attr( 'class', 'fbd-ajax-text' ).text( mw.msg( 'response-ajax-action-body' ) ) )
667674 );
668675
669 - $responseForm = $item.find('.fbd-response-form');
 676+ var $responseForm = $item.find( '.fbd-response-form' );
670677 $responseForm.empty().append( $responseStatus );
671678
672 - //send response
 679+ // Send response
673680 $.ajax( {
674 - 'type': 'POST',
675 - 'url': mw.util.wikiScript( 'api' ),
676 - 'data': resData,
677 - 'success': function (data) {
678 - if('error' in data) { //if rejected
679 - responseMessage ($item, 'error', mw.msg( 'response-ajax-error-head' ), data.error.info );
680 - } else if('feedbackdashboardresponse' in data) { //if successful
681 - responseMessage ($item, 'success', mw.msg( 'response-ajax-success-head' ), mw.msg( 'response-ajax-success-body' ) );
 681+ type: 'POST',
 682+ url: mw.util.wikiScript( 'api' ),
 683+ data: resData,
 684+ success: function (data) {
 685+ // If rejected
 686+ if ( data.error !== undefined ) {
 687+ responseMessage( $item, 'error', mw.msg( 'response-ajax-error-head' ), data.error.info );
 688+ } else if ( data.feedbackdashboardresponse !== undefined ) {
 689+ responseMessage( $item, 'success', mw.msg( 'response-ajax-success-head' ), mw.msg( 'response-ajax-success-body' ) );
682690 }
683691 },
684 - 'error': function( jqXHR, textStatus, errorThrown ) {
685 - responseMessage ($item, 'error', mw.msg( 'response-ajax-error-head' ), mw.msg( 'response-ajax-error-body' ) );
 692+ error: function ( jqXHR, textStatus, errorThrown ) {
 693+ responseMessage( $item, 'error', mw.msg( 'response-ajax-error-head' ), mw.msg( 'response-ajax-error-body' ) );
686694 },
687 - 'dataType': 'json'
 695+ dataType: 'json'
688696 } );
689 -
 697+
690698 }
691 - });
 699+ });
692700
693 - $( '#fbd-filters' ).children( 'form' ).submit( function( e ) {
 701+ $( '#fbd-filters' ).children( 'form' ).submit( function ( e ) {
694702 e.preventDefault();
695703 saveFormState();
696704 setCookies();
697705 loadComments( 'filter' );
698706 } );
699 -
700 - $( '#fbd-list-more' ).children( 'a' ).click( function( e ) {
 707+
 708+ $( '#fbd-list-more' ).children( 'a' ).click( function ( e ) {
701709 e.preventDefault();
702710 // We don't call saveFormState() here because we want to use the state of the form
703711 // at the time it was last filtered. Otherwise, you would see strange behavior if
704712 // you changed the form state then clicked More.
705713 loadComments( 'more' );
706714 } );
707 -
708 - $( '#fbd-filters-types input[type=checkbox]' ).click( function() {
 715+
 716+ $( '#fbd-filters-types input[type=checkbox]' ).click( function () {
709717 var types = getSelectedTypes();
710 - if(types.length === 0) { //check for 0 because onclick it will already have unchecked itself.
711 - $(this).prop('checked', true);
 718+ if ( types.length === 0 ) { //check for 0 because onclick it will already have unchecked itself.
 719+ $(this).prop( 'checked', true);
712720 }
713721 });
714 -
 722+
715723 //only allow one of the secondary filters to be checked
716 - $( 'input[type=checkbox].fbd-filters-check').click(function(){
 724+ $( 'input[type=checkbox].fbd-filters-check' ).click(function () {
717725 $( 'input[type=checkbox].fbd-filters-check' ).not( this ).prop( 'checked', false );
718726 });
719727
720 - $( '#fbd-list' ).delegate( '.fbd-item', 'hover', function (){
721 - $(this).toggleClass('fbd-hover');
 728+ $( '#fbd-list' ).delegate( '.fbd-item', 'hover', function () {
 729+ $(this).toggleClass( 'fbd-hover' );
722730 });
723731
724 - $( '#fbd-list' ).delegate( '.fbd-item', 'mouseleave', function (){
725 - $(this).removeClass('fbd-hover');
 732+ $( '#fbd-list' ).delegate( '.fbd-item', 'mouseleave', function () {
 733+ $(this).removeClass( 'fbd-hover' );
726734 });
727735
728736 //zebra stripe leaderboard
729 - $('.fbd-leaderboard li:nth-child(even)').addClass('even');
 737+ $( '.fbd-leaderboard li:nth-child(even)' ).addClass( 'even' );
730738
731739 saveFormState();
732740 var filterType = $( '#fbd-filters' ).children( 'form' ).data( 'filtertype' );
733741 // If filtering already happened on the PHP side, don't load the form state from cookies
734 - if ( filterType != 'filtered' ) {
 742+ if ( filterType !== 'filtered' ) {
735743 // Don't do an AJAX filter if we're on an ID view, or if the form is still blank after loadFromCookies()
736 - if ( loadFromCookies() && filterType != 'id' ) {
 744+ if ( loadFromCookies() && filterType !== 'id' ) {
737745 saveFormState();
738746 loadComments( 'filter' );
739747 }
Index: trunk/extensions/MoodBar/MoodBar.php
@@ -189,6 +189,7 @@
190190 'scripts' => 'ext.moodBar.dashboard/ext.moodBar.dashboard.js',
191191 'dependencies' => array(
192192 'mediawiki.util',
 193+ 'user.tokens',
193194 'jquery.NobleCount',
194195 'jquery.elastic'
195196 ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r108552[MoodBar] More clean up...krinkle21:27, 10 January 2012

Comments

#Comment by Catrope (talk | contribs)   19:31, 10 January 2012
-jQuery(function( $ ) {	
+jQuery( document ).ready( function ( $ ) {

Any particular reason why you're doing this?

-				for ( i = 0; i < len; i++ ) {
+
+				for ( i = 0; i < len; i+= 1 ) {

Oh please, I'd really like for this not to become an enforced convention. There's nothing unclear about using i++ by itself in a for loop like that. It's also spaced incorrectly, BTW.

Marking OK.

#Comment by Krinkle (talk | contribs)   21:16, 10 January 2012
Any particular reason why you're doing this?

Nope, bad copy paste by me. Intended to make a IIFE closure for $, mw, undefined (since all three are used, and the latter two are used as globals), but failed to do so.

Oh please, I'd really like for this not to become an enforced convention. There's nothing unclear about using i++ by itself in a for loop like that.

Fine by me, added it as disabled filter in JSLint per recommended JSLint settings here

Status & tagging log