2011-07-26 17:49:10 +00:00
|
|
|
/*
|
2011-07-26 20:04:36 +00:00
|
|
|
* jQuery Mobile Framework : "degradeInputs" plugin - degrades inputs to another type after custom enhancements are made.
|
2011-07-26 17:49:10 +00:00
|
|
|
* Copyright (c) jQuery Project
|
|
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
|
* http://jquery.org/license
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
(function( $, undefined ) {
|
|
|
|
|
|
|
|
|
|
$.mobile.page.prototype.options.degradeInputs = {
|
|
|
|
|
color: false,
|
|
|
|
|
date: false,
|
|
|
|
|
datetime: false,
|
|
|
|
|
"datetime-local": false,
|
|
|
|
|
email: false,
|
|
|
|
|
month: false,
|
|
|
|
|
number: false,
|
|
|
|
|
range: "number",
|
2011-08-19 02:01:58 +00:00
|
|
|
search: "text",
|
2011-07-26 17:49:10 +00:00
|
|
|
tel: false,
|
|
|
|
|
time: false,
|
|
|
|
|
url: false,
|
|
|
|
|
week: false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//auto self-init widgets
|
2011-10-13 20:21:47 +00:00
|
|
|
$( document ).bind( "pagecreate create", function( e ){
|
2011-10-14 22:33:50 +00:00
|
|
|
|
|
|
|
|
var page = $(e.target).closest(':jqmData(role="page")').data("page"), options;
|
|
|
|
|
|
|
|
|
|
if( !page ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options = page.options;
|
|
|
|
|
|
2011-07-26 17:49:10 +00:00
|
|
|
// degrade inputs to avoid poorly implemented native functionality
|
2011-10-13 22:50:29 +00:00
|
|
|
$( e.target ).find( "input" ).not( page.keepNativeSelector() ).each(function() {
|
2011-07-26 17:49:10 +00:00
|
|
|
var $this = $( this ),
|
|
|
|
|
type = this.getAttribute( "type" ),
|
2011-10-14 22:33:50 +00:00
|
|
|
optType = options.degradeInputs[ type ] || "text";
|
2011-07-26 17:49:10 +00:00
|
|
|
|
2011-10-14 22:33:50 +00:00
|
|
|
if ( options.degradeInputs[ type ] ) {
|
2011-09-23 23:17:22 +00:00
|
|
|
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 ) );
|
2011-07-26 17:49:10 +00:00
|
|
|
}
|
|
|
|
|
});
|
2011-10-14 22:33:50 +00:00
|
|
|
|
2011-07-26 17:49:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})( jQuery );
|