Merging resourceloader branch into trunk. Full documentation is at http://www.mediawi...
[lhc/web/wiklou.git] / resources / mediawiki / legacy / mediawiki.legacy.htmlform.js
1 /*
2 * Legacy emulation for the now depricated skins/common/htmlform.js
3 */
4
5 ( function( $, mw ) {
6
7 /* Extension */
8
9 $.extend( true, mw.legacy, {
10
11 /* Global Variables */
12
13 'htmlforms': {
14 'selectOrOtherSelectChanged': function( e ) {
15 var select;
16 if ( !e ) {
17 e = window.event;
18 }
19 if ( e.target ) {
20 select = e.target;
21 } else if ( e.srcElement ) {
22 select = e.srcElement;
23 }
24 // Defeat Safari bug
25 if ( select.nodeType == 3 ) {
26 select = select.parentNode;
27 }
28 var id = select.id;
29 var textbox = document.getElementById( id + '-other' );
30 if ( select.value == 'other' ) {
31 textbox.disabled = false;
32 } else {
33 textbox.disabled = true;
34 }
35 }
36 }
37 } );
38
39 /* Initialization */
40
41 $( document ).ready( function() {
42 // Find select-or-other fields
43 $( 'select .mw-htmlform-select-or-other' ).each( function() {
44 $(this).change( function() { mw.legacy.htmlforms.selectOrOtherSelectChanged(); } );
45 // Use a fake event to update it.
46 mw.legacy.htmlforms.selectOrOtherSelectChanged( { 'target': $(this).get( 0 ) } );
47 } );
48 } );
49
50 } )( jQuery, mediaWiki );