Merge "Remove full form of ChangeTags::buildTagFilterSelector"
[lhc/web/wiklou.git] / resources / src / mediawiki / htmlform / datetime.js
1 /*
2 * HTMLForm enhancements:
3 * Add minimal help for date and time fields
4 */
5 ( function ( mw ) {
6
7 mw.hook( 'htmlform.enhance' ).add( function ( $root ) {
8 var supported = {};
9
10 $root
11 .find( 'input.mw-htmlform-datetime-field' )
12 .each( function () {
13 var input,
14 type = this.getAttribute( 'type' );
15
16 if ( type !== 'date' && type !== 'time' && type !== 'datetime' ) {
17 // WTF?
18 return;
19 }
20
21 if ( supported[ type ] === undefined ) {
22 // Assume that if the browser implements validation (so it
23 // rejects "bogus" as a value) then it supports a proper UI too.
24 input = document.createElement( 'input' );
25 input.setAttribute( 'type', type );
26 input.value = 'bogus';
27 supported[ type ] = ( input.value !== 'bogus' );
28 }
29
30 if ( supported[ type ] ) {
31 if ( !this.getAttribute( 'min' ) ) {
32 this.setAttribute( 'min', this.getAttribute( 'data-min' ) );
33 }
34 if ( !this.getAttribute( 'max' ) ) {
35 this.setAttribute( 'max', this.getAttribute( 'data-max' ) );
36 }
37 if ( !this.getAttribute( 'step' ) ) {
38 this.setAttribute( 'step', this.getAttribute( 'data-step' ) );
39 }
40 }
41 } );
42 } );
43
44 }( mediaWiki ) );