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