Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js |
— | — | @@ -2,10 +2,12 @@ |
3 | 3 | * AJAX code for Special:MoodBarFeedback |
4 | 4 | */ |
5 | 5 | jQuery( document ).ready( function ( $ ) { |
| 6 | + var formState, filterType, $fbdFiltersCheck; |
| 7 | + |
6 | 8 | /** |
7 | 9 | * Saved form state |
8 | 10 | */ |
9 | | - var formState = { |
| 11 | + formState = { |
10 | 12 | types: [], |
11 | 13 | username: '', |
12 | 14 | myresponse: null, |
— | — | @@ -149,6 +151,8 @@ |
150 | 152 | url: mw.util.wikiScript( 'api' ), |
151 | 153 | data: reqData, |
152 | 154 | success: function ( data ) { |
| 155 | + var comments, len, $ul, moreResults, i; |
| 156 | + |
153 | 157 | // Remove the spinner and restore the "More" link |
154 | 158 | $( '#fbd-list-more' ) |
155 | 159 | .removeClass( 'mw-ajax-loader' ) |
— | — | @@ -160,11 +164,11 @@ |
161 | 165 | return; |
162 | 166 | } |
163 | 167 | |
164 | | - var comments = data.query.moodbarcomments, |
165 | | - len = comments.length, |
166 | | - $ul = $( '#fbd-list' ), |
167 | | - moreResults = false, |
168 | | - i; |
| 168 | + comments = data.query.moodbarcomments; |
| 169 | + len = comments.length; |
| 170 | + $ul = $( '#fbd-list' ); |
| 171 | + moreResults = false; |
| 172 | + |
169 | 173 | if ( len === 0 ) { |
170 | 174 | if ( mode === 'more' ) { |
171 | 175 | showMessage( mw.msg( 'moodbar-feedback-nomore' ) ); |
— | — | @@ -212,6 +216,7 @@ |
213 | 217 | */ |
214 | 218 | function reloadItem( $item, show ) { |
215 | 219 | var cont, request; |
| 220 | + |
216 | 221 | cont = $item.data( 'mbccontinue' ); |
217 | 222 | |
218 | 223 | request = { |
— | — | @@ -227,8 +232,10 @@ |
228 | 233 | request.mbcprop = 'formatted|hidden'; |
229 | 234 | } |
230 | 235 | |
231 | | - $.post( mw.util.wikiScript( 'api' ), request, |
232 | | - function ( data ) { |
| 236 | + $.ajax( { |
| 237 | + url: mw.util.wikiScript( 'api' ), |
| 238 | + data: request, |
| 239 | + success: function ( data ) { |
233 | 240 | if ( data && data.query && data.query.moodbarcomments && |
234 | 241 | data.query.moodbarcomments.length > 0 |
235 | 242 | ) { |
— | — | @@ -240,17 +247,22 @@ |
241 | 248 | $item.find( '.mw-ajax-loader' ).remove(); |
242 | 249 | showItemError( $item ); |
243 | 250 | } |
244 | | - }, 'json' ) |
245 | | - .error( function () { showItemError( $item ); } ); |
| 251 | + }, |
| 252 | + dataType: 'json', |
| 253 | + error: function () { |
| 254 | + showItemError( $item ); |
| 255 | + } |
| 256 | + } ); |
246 | 257 | } |
247 | 258 | |
248 | 259 | /** |
249 | 260 | * Show a hidden comment |
250 | 261 | */ |
251 | 262 | function showHiddenItem(e) { |
252 | | - var $item = $(this).closest( '.fbd-item' ); |
| 263 | + var $item, $spinner; |
253 | 264 | |
254 | | - var $spinner = $( '<span class="mw-ajax-loader"> </span>' ); |
| 265 | + $item = $(this).closest( '.fbd-item' ); |
| 266 | + $spinner = $( '<span class="mw-ajax-loader"> </span>' ); |
255 | 267 | $item.find( '.fbd-item-show' ).empty().append( $spinner ); |
256 | 268 | |
257 | 269 | reloadItem( $item, true ); |
— | — | @@ -276,17 +288,19 @@ |
277 | 289 | * @param $item jQuery item containing the .fbd-item |
278 | 290 | */ |
279 | 291 | function confirmAction( params, $item ) { |
| 292 | + var inlineForm, storedParams, $storedItem; |
280 | 293 | |
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' ) ) |
| 294 | + inlineForm = $( '<span>' ) |
| 295 | + .attr( 'class', 'fbd-item-reason' ) |
| 296 | + .append( $( '<span>' ).text( mw.msg( 'moodbar-action-reason' ) ) ) |
| 297 | + .append( $( '<input>' ).attr({'class':'fbd-action-reason', 'name':'fbd-action-reason'} ) ) |
| 298 | + .append( $( '<button>' ).attr( 'class', 'fbd-action-confirm' ).text( mw.msg( 'moodbar-feedback-action-confirm' ) ) ) |
| 299 | + .append( $( '<button>' ).attr( 'class', 'fbd-action-cancel' ).text( mw.msg( 'moodbar-feedback-action-cancel' ) ) ) |
| 300 | + .append( $( '<span>' ).attr( 'class', 'fbd-item-reason-msg' ) ) |
287 | 301 | .append( $( '<div>' ).attr( 'class', 'fbd-item-reason-msg' ) ); |
288 | 302 | |
289 | | - var storedParams = params; |
290 | | - var $storedItem = $item; |
| 303 | + storedParams = params; |
| 304 | + $storedItem = $item; |
291 | 305 | |
292 | 306 | $item.find( '.fbd-item-hide, .fbd-item-restore, .fbd-item-permalink' ) |
293 | 307 | .empty(); |
— | — | @@ -318,23 +332,26 @@ |
319 | 333 | * @param $item jQuery item containing the .fbd-item |
320 | 334 | */ |
321 | 335 | function doAction( params, $item ) { |
322 | | - var item_id = $item.data( 'mbccontinue' ).split( '|' )[1]; |
| 336 | + var item_id, $spinner; |
323 | 337 | |
324 | | - var errorHandler = function ( error_str ) { |
| 338 | + function errorHandler ( error_str ) { |
325 | 339 | showItemError( $item, error_str ); |
326 | | - }; |
327 | | - |
328 | | - var $spinner = $( '<span class="mw-ajax-loader"> </span>' ); |
| 340 | + } |
| 341 | + |
| 342 | + item_id = $item.data( 'mbccontinue' ).split( '|' )[1]; |
| 343 | + $spinner = $( '<span class="mw-ajax-loader"> </span>' ); |
329 | 344 | $item.find( '.fbd-item-hide' ).empty().append( $spinner ); |
330 | 345 | |
331 | | - $.post( mw.util.wikiScript( 'api' ), |
332 | | - $.extend( { |
| 346 | + $.ajax( { |
| 347 | + type: 'POST', |
| 348 | + url: mw.util.wikiScript( 'api' ), |
| 349 | + data: $.extend( { |
333 | 350 | action: 'feedbackdashboard', |
334 | 351 | token: mw.user.tokens.get( 'editToken' ), |
335 | 352 | item: item_id, |
336 | 353 | format: 'json' |
337 | 354 | }, params ), |
338 | | - function ( response ) { |
| 355 | + success: function ( response ) { |
339 | 356 | if ( response && response.feedbackdashboard ) { |
340 | 357 | if ( response.feedbackdashboard.result === 'success' ) { |
341 | 358 | reloadItem( $item ); |
— | — | @@ -346,8 +363,9 @@ |
347 | 364 | } else { |
348 | 365 | errorHandler(); |
349 | 366 | } |
350 | | - } ) |
351 | | - .error( errorHandler ); |
| 367 | + }, |
| 368 | + error: errorHandler |
| 369 | + } ); |
352 | 370 | } |
353 | 371 | |
354 | 372 | /** |
— | — | @@ -367,6 +385,7 @@ |
368 | 386 | */ |
369 | 387 | function hideItem( e ) { |
370 | 388 | var $item = $(this).closest( '.fbd-item' ); |
| 389 | + |
371 | 390 | closeAllResponders(); // If any are open |
372 | 391 | confirmAction( { mbaction: 'hide' }, $item ); |
373 | 392 | e.preventDefault(); |
— | — | @@ -379,8 +398,8 @@ |
380 | 399 | function closeAllResponders() { |
381 | 400 | |
382 | 401 | $( '.fbd-item' ).each( function () { |
| 402 | + var $link = $( this ).find( '.fbd-respond-link' ); |
383 | 403 | |
384 | | - var $link = $( this ).find( '.fbd-respond-link' ); |
385 | 404 | if ( $link.hasClass( 'responder-expanded' ) ) { |
386 | 405 | |
387 | 406 | $link.find( '.fbd-item-response-expanded' ) |
— | — | @@ -403,6 +422,7 @@ |
404 | 423 | * @param e {jQuery.Event} |
405 | 424 | */ |
406 | 425 | function showResponseForm( e ) { |
| 426 | + var termsLink, ula, inlineForm, $item; |
407 | 427 | |
408 | 428 | if ( $(this).hasClass( 'responder-expanded' ) ) { |
409 | 429 | |
— | — | @@ -411,18 +431,18 @@ |
412 | 432 | } else { |
413 | 433 | |
414 | 434 | // Init terms of use link |
415 | | - var termsLink = mw.html.element ( 'a', { |
416 | | - 'href': mw.msg( 'moodbar-response-url' ), |
417 | | - 'title': mw.msg( 'moodbar-response-link' ), |
418 | | - 'target': '_new' |
419 | | - }, mw.msg( 'moodbar-response-link' ) ); |
| 435 | + termsLink = mw.html.element ( 'a', { |
| 436 | + href: mw.msg( 'moodbar-response-url' ), |
| 437 | + title: mw.msg( 'moodbar-response-link' ), |
| 438 | + target: '_blank' |
| 439 | + }, mw.msg( 'moodbar-response-link' ) ); |
420 | 440 | |
421 | 441 | // ULA |
422 | | - var ula = mw.msg( 'moodbar-response-terms' ) |
| 442 | + ula = mw.msg( 'moodbar-response-terms' ) |
423 | 443 | .replace ( /\$1/g, termsLink ); |
424 | 444 | |
425 | 445 | // Build form |
426 | | - var inlineForm = $( '<div>' ).attr( 'class', 'fbd-response-form' ) |
| 446 | + inlineForm = $( '<div>' ).attr( 'class', 'fbd-response-form' ) |
427 | 447 | .append( |
428 | 448 | $( '<b>' ).text( mw.msg( 'moodbar-response-add' ) ) |
429 | 449 | ).append( |
— | — | @@ -462,7 +482,8 @@ |
463 | 483 | ); |
464 | 484 | |
465 | 485 | // Get the feedbackItem |
466 | | - var $item = $(this).closest( '.fbd-item' ); |
| 486 | + $item = $(this).closest( '.fbd-item' ); |
| 487 | + |
467 | 488 | // Close any open responders prior to opening this one. |
468 | 489 | closeAllResponders(); |
469 | 490 | |
— | — | @@ -650,51 +671,53 @@ |
651 | 672 | |
652 | 673 | // Handle response submit |
653 | 674 | $( '.fbd-response-submit' ).live( 'click', function () { |
654 | | - var $item = $(this).parent().parent(); |
655 | | - var fbResponse = $item.find( '.fbd-response-text' ).val(); |
656 | | - if ( fbResponse ) { |
657 | | - var clientData = $.client.profile(), |
658 | | - item_id = $item.data( 'mbccontinue' ).split( '|' )[1], |
659 | | - resData = { |
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' |
667 | | - }; |
| 675 | + var $item, fbResponse, clientData, item_id, resData, $responseStatus, $responseForm; |
668 | 676 | |
669 | | - var $responseStatus = $( '<div>' ).attr( 'class', 'fbd-ajax-response' ) |
670 | | - .append( $( '<span>' ).attr( 'class','mw-ajax-loader fbd-item-response-icon' ).html( ' ' ) ) |
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' ) ) ) |
674 | | - ); |
| 677 | + $item = $(this).parent().parent(); |
| 678 | + fbResponse = $item.find( '.fbd-response-text' ).val(); |
| 679 | + if ( fbResponse ) { |
| 680 | + clientData = $.client.profile(); |
| 681 | + item_id = $item.data( 'mbccontinue' ).split( '|' )[1]; |
| 682 | + resData = { |
| 683 | + action: 'feedbackdashboardresponse', |
| 684 | + useragent: clientData.name + '/' + clientData.versionNumber, |
| 685 | + system: clientData.platform, |
| 686 | + token: mw.user.tokens.get( 'editToken' ), |
| 687 | + response: fbResponse, |
| 688 | + feedback: item_id, |
| 689 | + format: 'json' |
| 690 | + }; |
675 | 691 | |
676 | | - var $responseForm = $item.find( '.fbd-response-form' ); |
677 | | - $responseForm.empty().append( $responseStatus ); |
| 692 | + $responseStatus = $( '<div>' ).attr( 'class', 'fbd-ajax-response' ) |
| 693 | + .append( $( '<span>' ).attr( 'class','mw-ajax-loader fbd-item-response-icon' ).html( ' ' ) ) |
| 694 | + .append( $( '<div>' ) |
| 695 | + .append( $( '<span>' ).attr( 'class', 'fbd-ajax-heading' ).text( mw.msg( 'response-ajax-action-head' ) ) ) |
| 696 | + .append( $( '<span>' ).attr( 'class', 'fbd-ajax-text' ).text( mw.msg( 'response-ajax-action-body' ) ) ) |
| 697 | + ); |
678 | 698 | |
679 | | - // Send response |
680 | | - $.ajax( { |
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' ) ); |
690 | | - } |
691 | | - }, |
692 | | - error: function ( jqXHR, textStatus, errorThrown ) { |
693 | | - responseMessage( $item, 'error', mw.msg( 'response-ajax-error-head' ), mw.msg( 'response-ajax-error-body' ) ); |
694 | | - }, |
695 | | - dataType: 'json' |
696 | | - } ); |
| 699 | + $responseForm = $item.find( '.fbd-response-form' ); |
| 700 | + $responseForm.empty().append( $responseStatus ); |
697 | 701 | |
698 | | - } |
| 702 | + // Send response |
| 703 | + $.ajax( { |
| 704 | + type: 'POST', |
| 705 | + url: mw.util.wikiScript( 'api' ), |
| 706 | + data: resData, |
| 707 | + success: function (data) { |
| 708 | + // If rejected |
| 709 | + if ( data.error !== undefined ) { |
| 710 | + responseMessage( $item, 'error', mw.msg( 'response-ajax-error-head' ), data.error.info ); |
| 711 | + } else if ( data.feedbackdashboardresponse !== undefined ) { |
| 712 | + responseMessage( $item, 'success', mw.msg( 'response-ajax-success-head' ), mw.msg( 'response-ajax-success-body' ) ); |
| 713 | + } |
| 714 | + }, |
| 715 | + error: function ( jqXHR, textStatus, errorThrown ) { |
| 716 | + responseMessage( $item, 'error', mw.msg( 'response-ajax-error-head' ), mw.msg( 'response-ajax-error-body' ) ); |
| 717 | + }, |
| 718 | + dataType: 'json' |
| 719 | + } ); |
| 720 | + |
| 721 | + } |
699 | 722 | }); |
700 | 723 | |
701 | 724 | $( '#fbd-filters' ).children( 'form' ).submit( function ( e ) { |
— | — | @@ -712,31 +735,32 @@ |
713 | 736 | loadComments( 'more' ); |
714 | 737 | } ); |
715 | 738 | |
716 | | - $( '#fbd-filters-types input[type=checkbox]' ).click( function () { |
| 739 | + $( '#fbd-filters-types input[type="checkbox"]' ).click( function () { |
717 | 740 | var types = getSelectedTypes(); |
718 | 741 | if ( types.length === 0 ) { //check for 0 because onclick it will already have unchecked itself. |
719 | 742 | $(this).prop( 'checked', true); |
720 | 743 | } |
721 | 744 | }); |
722 | 745 | |
723 | | - //only allow one of the secondary filters to be checked |
724 | | - $( 'input[type=checkbox].fbd-filters-check' ).click(function () { |
725 | | - $( 'input[type=checkbox].fbd-filters-check' ).not( this ).prop( 'checked', false ); |
| 746 | + // Only allow one of the secondary filters to be checked |
| 747 | + $fbdFiltersCheck = $( 'input.fbd-filters-check[type="checkbox"]' ).click(function () { |
| 748 | + $fbdFiltersCheck.not( this ).prop( 'checked', false ); |
726 | 749 | }); |
727 | 750 | |
728 | | - $( '#fbd-list' ).delegate( '.fbd-item', 'hover', function () { |
729 | | - $(this).toggleClass( 'fbd-hover' ); |
730 | | - }); |
| 751 | + $( '#fbd-list' ) |
| 752 | + .delegate( '.fbd-item', 'hover', function () { |
| 753 | + $(this).toggleClass( 'fbd-hover' ); |
| 754 | + }) |
| 755 | + .delegate( '.fbd-item', 'mouseleave', function () { |
| 756 | + $(this).removeClass( 'fbd-hover' ); |
| 757 | + }); |
731 | 758 | |
732 | | - $( '#fbd-list' ).delegate( '.fbd-item', 'mouseleave', function () { |
733 | | - $(this).removeClass( 'fbd-hover' ); |
734 | | - }); |
735 | | - |
736 | 759 | //zebra stripe leaderboard |
737 | 760 | $( '.fbd-leaderboard li:nth-child(even)' ).addClass( 'even' ); |
738 | 761 | |
739 | 762 | saveFormState(); |
740 | | - var filterType = $( '#fbd-filters' ).children( 'form' ).data( 'filtertype' ); |
| 763 | + |
| 764 | + filterType = $( '#fbd-filters' ).children( 'form' ).data( 'filtertype' ); |
741 | 765 | // If filtering already happened on the PHP side, don't load the form state from cookies |
742 | 766 | if ( filterType !== 'filtered' ) { |
743 | 767 | // Don't do an AJAX filter if we're on an ID view, or if the form is still blank after loadFromCookies() |