57430dab2d6eaed68c19c6acb847dec0b82db05b
[samples/web/DeviceMotionCapture.git] / tizen-web-ui-fw / latest / js / src / jquery.mobile.degradeInputs.js
1 (function( $, undefined ) {
2
3 $.mobile.page.prototype.options.degradeInputs = {
4         color: false,
5         date: false,
6         datetime: false,
7         "datetime-local": false,
8         email: false,
9         month: false,
10         number: false,
11         range: "number",
12         search: "text",
13         tel: false,
14         time: false,
15         url: false,
16         week: false
17 };
18
19
20 //auto self-init widgets
21 $.mobile.$document.bind( "pagecreate create", function( e ) {
22
23         var page = $.mobile.closestPageData( $( e.target ) ), options;
24
25         if ( !page ) {
26                 return;
27         }
28
29         options = page.options;
30
31         // degrade inputs to avoid poorly implemented native functionality
32         $( e.target ).find( "input" ).not( page.keepNativeSelector() ).each(function() {
33                 var $this = $( this ),
34                         type = this.getAttribute( "type" ),
35                         optType = options.degradeInputs[ type ] || "text";
36
37                 if ( options.degradeInputs[ type ] ) {
38                         var html = $( "<div>" ).html( $this.clone() ).html(),
39                                 // In IE browsers, the type sometimes doesn't exist in the cloned markup, so we replace the closing tag instead
40                                 hasType = html.indexOf( " type=" ) > -1,
41                                 findstr = hasType ? /\s+type=["']?\w+['"]?/ : /\/?>/,
42                                 repstr = " type=\"" + optType + "\" data-" + $.mobile.ns + "type=\"" + type + "\"" + ( hasType ? "" : ">" );
43
44                         $this.replaceWith( html.replace( findstr, repstr ) );
45                 }
46         });
47
48 });
49
50 })( jQuery );