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