2 * JavaScript for History action
4 jQuery( function ( $ ) {
5 var $historyCompareForm
= $( '#mw-history-compare' ),
7 $lis
= $( '#pagehistory > li' );
11 * @context {Element} input
12 * @param e {jQuery.Event}
14 function updateDiffRadios() {
15 var nextState
= 'before',
28 $inputs
= $li
.find( 'input[type="radio"]' );
29 $oldidRadio
= $inputs
.filter( '[name="oldid"]' ).eq( 0 );
30 $diffRadio
= $inputs
.filter( '[name="diff"]' ).eq( 0 );
32 $li
.removeClass( 'selected between before after' );
34 if ( !$oldidRadio
.length
|| !$diffRadio
.length
) {
38 if ( $oldidRadio
.prop( 'checked' ) ) {
39 $li
.addClass( 'selected after' );
41 } else if ( $diffRadio
.prop( 'checked' ) ) {
42 $li
.addClass( 'selected ' + nextState
);
43 nextState
= 'between';
45 // This list item has neither checked
46 // apply the appropriate class following the previous item.
47 $li
.addClass( nextState
);
54 $lis
.find( 'input[name="diff"], input[name="oldid"]' ).click( updateDiffRadios
);
59 // Prettify url output for HistoryAction submissions,
60 // to cover up action=historysubmit construction.
62 // Ideally we'd use e.target instead of $historySubmitter, but e.target points
63 // to the form element for submit actions, so.
64 $historyCompareForm
.find( '.historysubmit' ).click( function () {
65 $historySubmitter
= $( this );
68 // On submit we clone the form element, remove unneeded fields in the clone
69 // that pollute the query parameter with stuff from the other "use case",
70 // and then submit the clone.
71 // Without the cloning we'd be changing the real form, which is slower, could make
72 // the page look broken for a second in slow browsers and might show the form broken
73 // again when coming back from a "next" page.
74 $historyCompareForm
.submit( function ( e
) {
75 var $copyForm
, $copyRadios
, $copyAction
;
77 if ( $historySubmitter
) {
78 $copyForm
= $historyCompareForm
.clone();
79 $copyRadios
= $copyForm
.find( '#pagehistory > li' ).find( 'input[name="diff"], input[name="oldid"]' );
80 $copyAction
= $copyForm
.find( '> [name="action"]' );
82 // Remove action=historysubmit and ids[..]=..
83 if ( $historySubmitter
.hasClass( 'mw-history-compareselectedversions-button' ) ) {
85 $copyForm
.find( 'input[name^="ids["]:checked' ).prop( 'checked', false );
87 // Remove diff=&oldid=, change action=historysubmit to revisiondelete, remove revisiondelete
88 } else if ( $historySubmitter
.hasClass( 'mw-history-revisiondelete-button' ) ) {
90 $copyAction
.val( $historySubmitter
.attr( 'name' ) );
91 $copyForm
.find( ':submit' ).remove();
94 // IE7 doesn't do submission from an off-DOM clone, so insert hidden into document first
95 // Also remove potentially conflicting id attributes that we don't need anyway
97 .css( 'display', 'none' )
101 .insertAfter( $historyCompareForm
)
105 return false; // Because the submit is special, return false as well.
108 // Continue natural browser handling other wise