r91041 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91040‎ | r91041 | r91042 >
Date:01:31, 29 June 2011
Author:kaldari
Status:ok
Tags:
Comment:
partial revert of r90955 - Erik wants us to do this differently - implementing just-in-time construction of WikiLove (on Send rather than Preview), also reset preview when image is changed
Modified paths:
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -6,7 +6,6 @@
77 currentTypeId = null, // id of the currently selected type (e.g. 'barnstar' or 'makeyourown')
88 currentSubtypeId = null, // id of the currently selected subtype (e.g. 'original' or 'special')
99 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
1110 rememberData = null, // input data to remember when switching types or subtypes
1211 emailable = false,
1312 gallery = {};
@@ -138,15 +137,11 @@
139138
140139 if ( mw.config.get( 'wikilove-anon' ) === 0 ) $( '#mw-wikilove-anon-warning' ).hide();
141140
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+ } );
151146 }
152147
153148 $dialog.dialog( 'open' );
@@ -200,7 +195,6 @@
201196
202197 $( '#mw-wikilove-add-details' ).show();
203198 $( '#mw-wikilove-preview' ).hide();
204 - previewData = null;
205199 }
206200 },
207201
@@ -219,7 +213,6 @@
220214 $( '#mw-wikilove-subtype-description' ).html( currentTypeOrSubtype.descr );
221215 $.wikiLove.updateAllDetails();
222216 $( '#mw-wikilove-preview' ).hide();
223 - previewData = null;
224217 }
225218 },
226219
@@ -371,11 +364,11 @@
372365 success: function( data ) {
373366 // See if image exists locally or through InstantCommons
374367 if ( !data.query.pages[-1] || data.query.pages[-1].imageinfo) {
375 - // Image exists
 368+ // Image exists
376369 $.wikiLove.submitPreview();
377370 $.wikiLove.logCustomImageUse( imageTitle, 1 );
378371 } else {
379 - // Image does not exist
 372+ // Image does not exist
380373 $.wikiLove.showAddDetailsError( 'wikilove-err-image-bad' );
381374 $.wikiLove.logCustomImageUse( imageTitle, 0 );
382375 $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 );
@@ -399,25 +392,11 @@
400393 },
401394
402395 /*
403 - * After the form is validated, perform preview, and build data for the final AJAX request.
 396+ * After the form is validated, perform preview.
404397 */
405398 submitPreview: function() {
406399 var text = $.wikiLove.prepareMsg( currentTypeOrSubtype.text || options.defaultText );
407 -
408400 $.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 - }
422401 },
423402
424403 showAddDetailsError: function( errmsg ) {
@@ -508,41 +487,32 @@
509488
510489 /*
511490 * Callback for the preview function. Sets the preview area with the HTML and fades it in.
512 - * It also (re-)enables the send button.
513491 */
514492 showPreview: function( html ) {
515493 $( '#mw-wikilove-preview-area' ).html( html );
516494 $( '#mw-wikilove-preview' ).fadeIn( 200 );
517 - $( '#mw-wikilove-button-send' ).button( 'enable' );
518495 },
519496
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 -
534497 /*
535498 * Handler for the send (final submit) button.
536499 * The type sent for statistics is 'typeId-subtypeId' when using subtypes,
537500 * or simply 'typeId' otherwise.
538501 */
539502 submitSend: function( e ) {
 503+ e.preventDefault();
540504 $( '#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 );
546514 }
 515+ $.wikiLove.doSend( submitData.header, submitData.text,
 516+ submitData.message, submitData.type, submitData.email );
547517 },
548518
549519 /*
@@ -674,7 +644,6 @@
675645 $( '#mw-wikilove-gallery a' ).removeClass( 'selected' );
676646 $( this ).addClass( 'selected' );
677647 $( '#mw-wikilove-image' ).val( gallery[$( this ).attr( 'id' )] );
678 - $.wikiLove.changeInput();
679648 })
680649 );
681650 gallery['mw-wikilove-gallery-img-' + index] = page.title;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90955Added functionality to disable the sending of WikiLove when the input has cha...janpaul12313:28, 28 June 2011
r90961Entered input is now remembered when selecting a different type or subtype, f...janpaul12314:35, 28 June 2011

Status & tagging log