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