Skip to content

Commit 1559478

Browse files
committed
Issue jquery-archive#2654 - 'degradeInputs' plugin doesn't trigger on 'create' events; modified plugin and added tests
1 parent 349daaf commit 1559478

File tree

3 files changed

+127
-3
lines changed

3 files changed

+127
-3
lines changed

js/jquery.mobile.degradeInputs.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ $.mobile.page.prototype.options.keepNative = ":jqmData(role='none'), :jqmData(ro
2727

2828

2929
//auto self-init widgets
30-
$( document ).bind( "pagecreate enhance", function( e ){
30+
$( document ).bind( "pagecreate create", function( e ){
3131

32-
var page = $( e.target ).data( "page" ),
33-
o = page.options;
32+
var o = $.mobile.page.prototype.options;
3433

3534
// degrade inputs to avoid poorly implemented native functionality
3635
$( e.target ).find( "input" ).not( o.keepNative ).each(function() {
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* degradeInputs unit tests
3+
*/
4+
5+
(function($){
6+
module('jquery.mobile.slider.js', {
7+
setup: function() {
8+
$('#test-container').html("");
9+
}
10+
});
11+
12+
test('input type color should not degrade when "create" event is triggered', function(){
13+
$('#test-container').html('<input type="color" />').trigger("create");
14+
15+
same($('#test-container input').attr("type"), "color");
16+
});
17+
18+
test('input type date should not degrade when "create" event is triggered', function(){
19+
$('#test-container').html('<input type="date" />').trigger("create");
20+
21+
same($('#test-container input').attr("type"), "date");
22+
});
23+
24+
test('input type datetime should not degrade when "create" event is triggered', function(){
25+
$('#test-container').html('<input type="datetime" />').trigger("create");
26+
27+
same($('#test-container input').attr("type"), "datetime");
28+
});
29+
30+
test('input type datetime-local should not degrade when "create" event is triggered', function(){
31+
$('#test-container').html('<input type="datetime-local" />').trigger("create");
32+
33+
same($('#test-container input').attr("type"), "datetime-local");
34+
});
35+
36+
test('input type email should not degrade when "create" event is triggered', function(){
37+
$('#test-container').html('<input type="email" />').trigger("create");
38+
39+
same($('#test-container input').attr("type"), "email");
40+
});
41+
42+
test('input type month should not degrade when "create" event is triggered', function(){
43+
$('#test-container').html('<input type="month" />').trigger("create");
44+
45+
same($('#test-container input').attr("type"), "month");
46+
});
47+
48+
test('input type number should not degrade when "create" event is triggered', function(){
49+
$('#test-container').html('<input type="number" />').trigger("create");
50+
51+
same($('#test-container input').attr("type"), "number");
52+
});
53+
54+
test('input type range should degrade to number when "create" event is triggered', function(){
55+
$('#test-container').html('<input type="range" />').trigger("create");
56+
57+
same($('#test-container input').attr("type"), "number");
58+
});
59+
60+
test('input type search should degrade to text when "create" event is triggered', function(){
61+
$('#test-container').html('<input type="search" />').trigger("create");
62+
63+
same($('#test-container input').attr("type"), "text");
64+
});
65+
66+
test('input type tel should not degrade when "create" event is triggered', function(){
67+
$('#test-container').html('<input type="tel" />').trigger("create");
68+
69+
same($('#test-container input').attr("type"), "tel");
70+
});
71+
72+
test('input type time should not degrade when "create" event is triggered', function(){
73+
$('#test-container').html('<input type="time" />').trigger("create");
74+
75+
same($('#test-container input').attr("type"), "time");
76+
});
77+
78+
test('input type url should not degrade when "create" event is triggered', function(){
79+
$('#test-container').html('<input type="url" />').trigger("create");
80+
81+
same($('#test-container input').attr("type"), "url");
82+
});
83+
84+
test('input type week should not degrade when "create" event is triggered', function(){
85+
$('#test-container').html('<input type="week" />').trigger("create");
86+
87+
same($('#test-container input').attr("type"), "week");
88+
});
89+
90+
})(jQuery);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Degrade Inputs Test Suite</title>
7+
8+
<script src="../../../js/jquery.js"></script>
9+
<script src="../jquery.setNameSpace.js"></script>
10+
<script src="../../../js/"></script>
11+
<script src="../../../tests/jquery.testHelper.js"></script>
12+
13+
14+
<link rel="stylesheet" href="../../../themes/default/"/>
15+
<link rel="stylesheet" href="../../../external/qunit.css"/>
16+
<script src="../../../external/qunit.js"></script>
17+
18+
<script src="degradeInputs.js"></script>
19+
</head>
20+
<body>
21+
22+
<h1 id="qunit-header">jQuery Mobile Degrade Inputs Test Suite</h1>
23+
<h2 id="qunit-banner"></h2>
24+
<h2 id="qunit-userAgent"></h2>
25+
<ol id="qunit-tests">
26+
</ol>
27+
28+
<div id="foo" data-nstest-role="page">
29+
30+
<div id="test-container">
31+
</div>
32+
33+
</div>
34+
35+
</html>

0 commit comments

Comments
 (0)