Index: trunk/phase3/skins/common/upload.js |
— | — | @@ -35,11 +35,6 @@ |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | | - // Toggle source type |
40 | | - var sourceTypeCheckboxes = document.getElementsByName( 'wpSourceType' ); |
41 | | - for ( var i = 0; i < sourceTypeCheckboxes.length; i++ ) { |
42 | | - sourceTypeCheckboxes[i].onchange = toggleUploadInputs; |
43 | | - } |
44 | 39 | |
45 | 40 | // AJAX wpDestFile warnings |
46 | 41 | if ( wgAjaxUploadDestCheck ) { |
— | — | @@ -86,44 +81,6 @@ |
87 | 82 | }; |
88 | 83 | }; |
89 | 84 | |
90 | | -/** |
91 | | - * Iterate over all upload source fields and disable all except the selected one. |
92 | | - * |
93 | | - * @return emptiness |
94 | | - */ |
95 | | -window.toggleUploadInputs = function() { |
96 | | - // Iterate over all rows with UploadSourceField |
97 | | - var rows; |
98 | | - if ( document.getElementsByClassName ) { |
99 | | - rows = document.getElementsByClassName( 'mw-htmlform-field-UploadSourceField' ); |
100 | | - } else { |
101 | | - // Older browsers don't support getElementsByClassName |
102 | | - rows = new Array(); |
103 | | - |
104 | | - var allRows = document.getElementsByTagName( 'tr' ); |
105 | | - for ( var i = 0; i < allRows.length; i++ ) { |
106 | | - if ( allRows[i].className == 'mw-htmlform-field-UploadSourceField' ) |
107 | | - rows.push( allRows[i] ); |
108 | | - } |
109 | | - } |
110 | | - |
111 | | - for ( var i = 0; i < rows.length; i++ ) { |
112 | | - var inputs = rows[i].getElementsByTagName( 'input' ); |
113 | | - |
114 | | - // Check if this row is selected |
115 | | - var isChecked = true; // Default true in case wpSourceType is not found |
116 | | - for ( var j = 0; j < inputs.length; j++ ) { |
117 | | - if ( inputs[j].name == 'wpSourceType' ) |
118 | | - isChecked = inputs[j].checked; |
119 | | - } |
120 | | - |
121 | | - // Disable all unselected rows |
122 | | - for ( var j = 0; j < inputs.length; j++ ) { |
123 | | - if ( inputs[j].type != 'radio') |
124 | | - inputs[j].disabled = !isChecked; |
125 | | - } |
126 | | - } |
127 | | -}; |
128 | 85 | |
129 | 86 | window.wgUploadWarningObj = { |
130 | 87 | 'responseCache' : { '' : ' ' }, |
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js |
— | — | @@ -3,6 +3,9 @@ |
4 | 4 | * Note that additional code still lives in skins/common/upload.js |
5 | 5 | */ |
6 | 6 | |
| 7 | +/** |
| 8 | + * Add a preview to the upload form |
| 9 | + */ |
7 | 10 | jQuery( function( $ ) { |
8 | 11 | /** |
9 | 12 | * Is the FileAPI available with sufficient functionality? |
— | — | @@ -203,3 +206,24 @@ |
204 | 207 | } ); |
205 | 208 | } |
206 | 209 | } ); |
| 210 | + |
| 211 | +/** |
| 212 | + * Disable all upload source fields except the selected one |
| 213 | + */ |
| 214 | +jQuery( function ( $ ) { |
| 215 | + var rows = $( '.mw-htmlform-field-UploadSourceField' ); |
| 216 | + for ( var i = rows.length; i; i-- ) { |
| 217 | + var row = rows[i - 1]; |
| 218 | + $( 'input[name="wpSourceType"]', row ).change( function () { |
| 219 | + var currentRow = row; // Store current row in our own scope |
| 220 | + return function () { |
| 221 | + if ( this.checked ) { |
| 222 | + // Disable all inputs |
| 223 | + $( 'input[name!="wpSourceType"]', rows ).attr( 'disabled', true ); |
| 224 | + // Re-enable the current one |
| 225 | + $( 'input', currentRow ).attr( 'disabled', false ); |
| 226 | + } |
| 227 | + }; |
| 228 | + }() ); |
| 229 | + } |
| 230 | +} ); |