Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -6,7 +6,6 @@ |
7 | 7 | currentTypeId = null, // id of the currently selected type (e.g. 'barnstar' or 'makeyourown') |
8 | 8 | currentSubtypeId = null, // id of the currently selected subtype (e.g. 'original' or 'special') |
9 | 9 | currentTypeOrSubtype = null, // content of the current (sub)type (i.e. an object with title, descr, text, etc.) |
10 | | - previewData = null, // data of the currently previewed thing is set here |
11 | 10 | rememberData = null, // input data to remember when switching types or subtypes |
12 | 11 | emailable = false, |
13 | 12 | gallery = {}; |
— | — | @@ -138,15 +137,11 @@ |
139 | 138 | |
140 | 139 | if ( mw.config.get( 'wikilove-anon' ) === 0 ) $( '#mw-wikilove-anon-warning' ).hide(); |
141 | 140 | |
142 | | - // when the input changes, we want to disable the send button |
143 | | - $( '#mw-wikilove-header' ).change( $.wikiLove.changeInput ); |
144 | | - $( '#mw-wikilove-header' ).keyup( $.wikiLove.changeInput ); |
145 | | - $( '#mw-wikilove-title' ).change( $.wikiLove.changeInput ); |
146 | | - $( '#mw-wikilove-title' ).keyup( $.wikiLove.changeInput ); |
147 | | - $( '#mw-wikilove-image' ).change( $.wikiLove.changeInput ); |
148 | | - $( '#mw-wikilove-image' ).keyup( $.wikiLove.changeInput ); |
149 | | - $( '#mw-wikilove-message' ).change( $.wikiLove.changeInput ); |
150 | | - $( '#mw-wikilove-message' ).keyup( $.wikiLove.changeInput ); |
| 141 | + // When the image changes, we want to reset the preview and error message. |
| 142 | + $( '#mw-wikilove-image' ).change( function() { |
| 143 | + $( '#mw-wikilove-dialog' ).find( '.mw-wikilove-error' ).remove(); |
| 144 | + $( '#mw-wikilove-preview' ).hide(); |
| 145 | + } ); |
151 | 146 | } |
152 | 147 | |
153 | 148 | $dialog.dialog( 'open' ); |
— | — | @@ -200,7 +195,6 @@ |
201 | 196 | |
202 | 197 | $( '#mw-wikilove-add-details' ).show(); |
203 | 198 | $( '#mw-wikilove-preview' ).hide(); |
204 | | - previewData = null; |
205 | 199 | } |
206 | 200 | }, |
207 | 201 | |
— | — | @@ -219,7 +213,6 @@ |
220 | 214 | $( '#mw-wikilove-subtype-description' ).html( currentTypeOrSubtype.descr ); |
221 | 215 | $.wikiLove.updateAllDetails(); |
222 | 216 | $( '#mw-wikilove-preview' ).hide(); |
223 | | - previewData = null; |
224 | 217 | } |
225 | 218 | }, |
226 | 219 | |
— | — | @@ -371,11 +364,11 @@ |
372 | 365 | success: function( data ) { |
373 | 366 | // See if image exists locally or through InstantCommons |
374 | 367 | if ( !data.query.pages[-1] || data.query.pages[-1].imageinfo) { |
375 | | - // Image exists |
| 368 | + // Image exists |
376 | 369 | $.wikiLove.submitPreview(); |
377 | 370 | $.wikiLove.logCustomImageUse( imageTitle, 1 ); |
378 | 371 | } else { |
379 | | - // Image does not exist |
| 372 | + // Image does not exist |
380 | 373 | $.wikiLove.showAddDetailsError( 'wikilove-err-image-bad' ); |
381 | 374 | $.wikiLove.logCustomImageUse( imageTitle, 0 ); |
382 | 375 | $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 ); |
— | — | @@ -399,25 +392,11 @@ |
400 | 393 | }, |
401 | 394 | |
402 | 395 | /* |
403 | | - * After the form is validated, perform preview, and build data for the final AJAX request. |
| 396 | + * After the form is validated, perform preview. |
404 | 397 | */ |
405 | 398 | submitPreview: function() { |
406 | 399 | var text = $.wikiLove.prepareMsg( currentTypeOrSubtype.text || options.defaultText ); |
407 | | - |
408 | 400 | $.wikiLove.doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + text ); |
409 | | - previewData = { |
410 | | - 'header': $( '#mw-wikilove-header' ).val(), |
411 | | - 'text': text, |
412 | | - 'message': $( '#mw-wikilove-message' ).val(), |
413 | | - 'title': $( '#mw-wikilove-title' ).val(), |
414 | | - 'image': $( '#mw-wikilove-image' ).val(), |
415 | | - 'type': currentTypeId |
416 | | - + (currentSubtypeId !== null ? '-' + currentSubtypeId : '') |
417 | | - }; |
418 | | - |
419 | | - if ( $( '#mw-wikilove-notify-checkbox:checked' ).val() && emailable ) { |
420 | | - previewData.email = $.wikiLove.prepareMsg( currentTypeOrSubtype.email ); |
421 | | - } |
422 | 401 | }, |
423 | 402 | |
424 | 403 | showAddDetailsError: function( errmsg ) { |
— | — | @@ -508,41 +487,32 @@ |
509 | 488 | |
510 | 489 | /* |
511 | 490 | * Callback for the preview function. Sets the preview area with the HTML and fades it in. |
512 | | - * It also (re-)enables the send button. |
513 | 491 | */ |
514 | 492 | showPreview: function( html ) { |
515 | 493 | $( '#mw-wikilove-preview-area' ).html( html ); |
516 | 494 | $( '#mw-wikilove-preview' ).fadeIn( 200 ); |
517 | | - $( '#mw-wikilove-button-send' ).button( 'enable' ); |
518 | 495 | }, |
519 | 496 | |
520 | | - changeInput: function() { |
521 | | - if( previewData !== null && |
522 | | - ( previewData.message != $( '#mw-wikilove-message' ).val() |
523 | | - || previewData.title != $( '#mw-wikilove-title' ).val() |
524 | | - || previewData.header != $( '#mw-wikilove-header' ).val() |
525 | | - || previewData.image != $( '#mw-wikilove-image' ).val() |
526 | | - )) { |
527 | | - $( '#mw-wikilove-button-send' ).button( 'disable' ); |
528 | | - } |
529 | | - else { |
530 | | - $( '#mw-wikilove-button-send' ).button( 'enable' ); |
531 | | - } |
532 | | - }, |
533 | | - |
534 | 497 | /* |
535 | 498 | * Handler for the send (final submit) button. |
536 | 499 | * The type sent for statistics is 'typeId-subtypeId' when using subtypes, |
537 | 500 | * or simply 'typeId' otherwise. |
538 | 501 | */ |
539 | 502 | submitSend: function( e ) { |
| 503 | + e.preventDefault(); |
540 | 504 | $( '#mw-wikilove-dialog' ).find( '.mw-wikilove-error' ).remove(); |
541 | | - |
542 | | - if( !$( '#mw-wikilove-button-send' ).button( 'option', 'disabled' ) ) { |
543 | | - e.preventDefault(); |
544 | | - $.wikiLove.doSend( previewData.header, previewData.text, |
545 | | - previewData.message, previewData.type, previewData.email ); |
| 505 | + var submitData = { |
| 506 | + 'header': $( '#mw-wikilove-header' ).val(), |
| 507 | + 'text': $.wikiLove.prepareMsg( currentTypeOrSubtype.text || options.defaultText ), |
| 508 | + 'message': $( '#mw-wikilove-message' ).val(), |
| 509 | + 'type': currentTypeId |
| 510 | + + (currentSubtypeId !== null ? '-' + currentSubtypeId : '') |
| 511 | + }; |
| 512 | + if ( $( '#mw-wikilove-notify-checkbox:checked' ).val() && emailable ) { |
| 513 | + submitData.email = $.wikiLove.prepareMsg( currentTypeOrSubtype.email ); |
546 | 514 | } |
| 515 | + $.wikiLove.doSend( submitData.header, submitData.text, |
| 516 | + submitData.message, submitData.type, submitData.email ); |
547 | 517 | }, |
548 | 518 | |
549 | 519 | /* |
— | — | @@ -674,7 +644,6 @@ |
675 | 645 | $( '#mw-wikilove-gallery a' ).removeClass( 'selected' ); |
676 | 646 | $( this ).addClass( 'selected' ); |
677 | 647 | $( '#mw-wikilove-image' ).val( gallery[$( this ).attr( 'id' )] ); |
678 | | - $.wikiLove.changeInput(); |
679 | 648 | }) |
680 | 649 | ); |
681 | 650 | gallery['mw-wikilove-gallery-img-' + index] = page.title; |