Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
DegradeInput: move to $.mobile.degradeInputs deprecate on page widget
Browse files Browse the repository at this point in the history
  • Loading branch information
arschmitz committed Aug 9, 2013
1 parent 791754f commit 20433c6
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions js/jquery.mobile.degradeInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define( [ "jquery", "./widgets/page" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

$.mobile.page.prototype.options.degradeInputs = {
$.mobile.degradeInputs = {
color: false,
date: false,
datetime: false,
Expand All @@ -23,34 +23,29 @@ $.mobile.page.prototype.options.degradeInputs = {
url: false,
week: false
};
// Backcompat remove in 1.5
$.mobile.page.prototype.options.degradeInputs = $.mobile.degradeInputs;

//auto self-init widgets
// Auto self-init widgets
$.mobile.degradeInputsWithin = function( target ) {

var $target = $( target ),
page = $.mobile.closestPageData( $target ), options;
target = $( target );

if ( !page ) {
return;
}

options = page.options;

// degrade inputs to avoid poorly implemented native functionality
$target.find( "input" ).not( page.keepNativeSelector() ).each(function() {
var $this = $( this ),
// Degrade inputs to avoid poorly implemented native functionality
target.find( "input" ).not( $.mobile.page.prototype.keepNativeSelector() ).each(function() {
var element = $( this ),
type = this.getAttribute( "type" ),
optType = options.degradeInputs[ type ] || "text",
optType = $.mobile.degradeInputs[ type ] || "text",
html, hasType, findstr, repstr;

if ( options.degradeInputs[ type ] ) {
html = $( "<div>" ).html( $this.clone() ).html();
if ( $.mobile.degradeInputs[ type ] ) {
html = $( "<div>" ).html( element.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 ) );
element.replaceWith( html.replace( findstr, repstr ) );
}
});

Expand Down

0 comments on commit 20433c6

Please sign in to comment.