mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +00:00
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
|
//>>description: Degrades inputs to another type after custom enhancements are made.
|
|
//>>label: Degrade Inputs
|
|
|
|
define( [ "jquery", "jquery.mobile.page" ], function( $ ) {
|
|
//>>excludeEnd("jqmBuildExclude");
|
|
(function( $, undefined ) {
|
|
|
|
$.mobile.page.prototype.options.degradeInputs = {
|
|
color: false,
|
|
date: false,
|
|
datetime: false,
|
|
"datetime-local": false,
|
|
email: false,
|
|
month: false,
|
|
number: false,
|
|
range: "number",
|
|
search: "text",
|
|
tel: false,
|
|
time: false,
|
|
url: false,
|
|
week: false
|
|
};
|
|
|
|
|
|
//auto self-init widgets
|
|
$( document ).bind( "pagecreate create", function( e ){
|
|
|
|
var page = $.mobile.closestPageData($(e.target)), options;
|
|
|
|
if( !page ) {
|
|
return;
|
|
}
|
|
|
|
options = page.options;
|
|
|
|
// degrade inputs to avoid poorly implemented native functionality
|
|
$( e.target ).find( "input" ).not( page.keepNativeSelector() ).each(function() {
|
|
var $this = $( this ),
|
|
type = this.getAttribute( "type" ),
|
|
optType = options.degradeInputs[ type ] || "text";
|
|
|
|
if ( options.degradeInputs[ type ] ) {
|
|
var html = $( "<div>" ).html( $this.clone() ).html(),
|
|
// In IE browsers, the type sometimes doesn't exist in the cloned markup, so we replace the closing tag instead
|
|
hasType = html.indexOf( " type=" ) > -1,
|
|
findstr = hasType ? /\s+type=["']?\w+['"]?/ : /\/?>/,
|
|
repstr = " type=\"" + optType + "\" data-" + $.mobile.ns + "type=\"" + type + "\"" + ( hasType ? "" : ">" );
|
|
|
|
$this.replaceWith( html.replace( findstr, repstr ) );
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
})( jQuery );
|
|
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
|
});
|
|
//>>excludeEnd("jqmBuildExclude");
|