Permalink
Browse files

DegradeInputs: Remove code supporting an IE8 bug that is no longer

reproducible with current code.
  • Loading branch information...
arschmitz committed May 5, 2015
1 parent f995b91 commit 5d5bcf1e07fb53f368245b75f8534c9ac75a6ec6
Showing with 22 additions and 38 deletions.
  1. +5 −20 js/degradeInputs.js
  2. +17 −18 tests/unit/degrade-inputs/degradeInputs.js
View
@@ -9,7 +9,7 @@
//>>label: Degrade Inputs
//>>group: Utilities
//>>description: Changes input type to another after custom enhancements are made (ex. range > numeric).
//>>description: Degrades HTM5 input types to compatible HTML4 ones.
//>>docs: http://api.jquerymobile.com/jQuery.mobile.degradeInputsWithin/
( function( factory ) {
@@ -27,19 +27,8 @@
} )( function( $ ) {
$.mobile.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
search: "text"
};
// Auto self-init widgets
@@ -48,20 +37,16 @@ $.mobile.degradeInputsWithin = function( target ) {
// Degrade inputs to avoid poorly implemented native functionality
target.find( "input" ).not( $.mobile.keepNative ).each( function() {
var html, hasType, findstr, repstr,
var html, findstr, repstr,
element = $( this ),
type = this.getAttribute( "type" ),
optType = $.mobile.degradeInputs[ type ] || "text";
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 ? "" : ">" );
findstr = /\s+type=["']?\w+['"]?/;
repstr = " type=\"" + optType + "\" data-" + $.mobile.ns + "type=\"" + type + "\"";
element.replaceWith( html.replace( findstr, repstr ) );
}
@@ -8,49 +8,49 @@ module( "jquery.mobile.degradeInputs.js" );
test( "degradeInputs works on page init", function() {
expect( 3 );
strictEqual( $( "#degrade-range").attr( "type" ), "number",
strictEqual( $( "#degrade-range" ).attr( "type" ), "number",
"Range inputs are degrade to type number" );
strictEqual( $( "#degrade-search").attr( "type" ), "text",
strictEqual( $( "#degrade-search" ).attr( "type" ), "text",
"Search inputs degrade to type text" );
strictEqual( $( "#degrade-color").attr( "type" ), "color",
strictEqual( $( "#degrade-color" ).attr( "type" ), "color",
"setting an input type to false cause no degradation of that type" );
} );
test( "degradeInputs works on page enhance", function() {
expect( 6 );
strictEqual( $( "#enhance-degrade-range").attr( "type" ), "range",
strictEqual( $( "#enhance-degrade-range" ).attr( "type" ), "range",
"Range inputs not in a page are ignored on inital page load" );
strictEqual( $( "#enhance-degrade-search").attr( "type" ), "search",
strictEqual( $( "#enhance-degrade-search" ).attr( "type" ), "search",
"Search inputs not in a page are ignored on inital page load" );
strictEqual( $( "#enhance-degrade-color").attr( "type" ), "color",
strictEqual( $( "#enhance-degrade-color" ).attr( "type" ), "color",
"setting an input type to false cause no degradation of that type" );
$( "#enhance-container" ).enhance();
strictEqual( $( "#enhance-degrade-range").attr( "type" ), "number",
strictEqual( $( "#enhance-degrade-range" ).attr( "type" ), "number",
"Range inputs are degrade to type number" );
strictEqual( $( "#enhance-degrade-search").attr( "type" ), "text",
strictEqual( $( "#enhance-degrade-search" ).attr( "type" ), "text",
"Search inputs degrade to type text" );
strictEqual( $( "#enhance-degrade-color").attr( "type" ), "color",
strictEqual( $( "#enhance-degrade-color" ).attr( "type" ), "color",
"setting an input type to false cause no degradation of that type" );
} );
test( "degradeInputsWithin", function() {
expect( 6 );
strictEqual( $( "#degrade-within-range").attr( "type" ), "range",
strictEqual( $( "#degrade-within-range" ).attr( "type" ), "range",
"Range inputs not in a page are ignored on inital page load" );
strictEqual( $( "#degrade-within-search").attr( "type" ), "search",
strictEqual( $( "#degrade-within-search" ).attr( "type" ), "search",
"Search inputs not in a page are ignored on inital page load" );
strictEqual( $( "#degrade-within-color").attr( "type" ), "color",
strictEqual( $( "#degrade-within-color" ).attr( "type" ), "color",
"setting an input type to false cause no degradation of that type" );
$.mobile.degradeInputsWithin( $( "#degrade-within-container" ) );
strictEqual( $( "#degrade-within-range").attr( "type" ), "number",
strictEqual( $( "#degrade-within-range" ).attr( "type" ), "number",
"Range inputs are degrade to type number" );
strictEqual( $( "#degrade-within-search").attr( "type" ), "text",
strictEqual( $( "#degrade-within-search" ).attr( "type" ), "text",
"Search inputs degrade to type text" );
strictEqual( $( "#degrade-within-color").attr( "type" ), "color",
strictEqual( $( "#degrade-within-color" ).attr( "type" ), "color",
"setting an input type to false cause no degradation of that type" );
} );
@@ -75,8 +75,7 @@ test( "degradeInputs - custom values", function() {
$.mobile.degradeInputs.range = "custom";
$.mobile.degradeInputsWithin( $( "#custom-degrade" ) );
strictEqual( $( "#custom-range-type" ).attr( "type" ), "custom",
"degradeInputs with custom types works")
"degradeInputs with custom types works" );
} );
} )( jQuery );
} )( jQuery );

0 comments on commit 5d5bcf1

Please sign in to comment.