forked from jquery-archive/jquery-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect_native.js
More file actions
124 lines (96 loc) · 3.64 KB
/
select_native.js
File metadata and controls
124 lines (96 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* mobile select unit tests
*/
(function($){
module("jquery.mobile.forms.select native");
test( "native menu selections alter the button text", function(){
var select = $( "#native-select-choice-few" ), setAndCheck;
setAndCheck = function(key){
var text;
select.val( key ).selectmenu( 'refresh' );
text = select.find( "option[value='" + key + "']" ).text();
deepEqual( select.parent().find(".ui-btn-text").text(), text );
};
setAndCheck( 'rush' );
setAndCheck( 'standard' );
});
asyncTest( "selecting a value removes the related buttons down state", function(){
var select = $( "#native-select-choice-few" );
$.testHelper.sequence([
function() {
// click the native menu parent button
select.parent().trigger( 'vmousedown' );
},
function() {
ok( select.parent().hasClass("ui-btn-down-c"), "button down class added" );
},
function() {
// trigger a change on the select
select.trigger( "change" );
},
function() {
ok( !select.parent().hasClass("ui-btn-down-c"), "button down class removed" );
start();
}
], 300);
});
// issue https://github.com/jquery/jquery-mobile/issues/2410
test( "adding options and refreshing a custom select defaults the text", function() {
var select = $( "#custom-refresh" ),
button = select.siblings( "a" ).find( ".ui-btn-inner" ),
text = "foo";
deepEqual($.trim(button.text()), "default");
select.find( "option" ).remove(); //remove the loading message
select.append('<option value="1">' + text + '</option>');
select.selectmenu( 'refresh' );
deepEqual($.trim(button.text()), text);
});
// issue 2424
test( "native selects should provide open and close as a no-op", function() {
// exception will prevent test success if undef
$( "#native-refresh" ).selectmenu( 'open' );
$( "#native-refresh" ).selectmenu( 'close' );
ok( true );
});
asyncTest( "The preventFocusZoom option is working as expected", function() {
var zoomoptiondefault = $.mobile.selectmenu.prototype.options.preventFocusZoom;
$.mobile.selectmenu.prototype.options.preventFocusZoom = true;
$(document)
.one("vmousedown.test", function(){
ok( $.mobile.zoom.enabled === false, "zoom is disabled on vmousedown" );
})
.one("mouseup.test", function(){
setTimeout(function() { // This empty setTimeout is to match the work-around for the issue reported in https://github.com/jquery/jquery-mobile/issues/5041
ok( $.mobile.zoom.enabled === true, "zoom is enabled on mouseup" );
$.mobile.selectmenu.prototype.options.preventFocusZoom = zoomoptiondefault;
$(document).unbind(".test");
$( "#select-choice-native" ).selectmenu( "option", "preventFocusZoom", zoomoptiondefault );
start();
}, 0);
});
$( "#select-choice-native" )
.selectmenu( "option", "preventFocusZoom", true )
.parent()
.trigger( "vmousedown" )
.trigger( "mouseup" );
});
asyncTest( "The preventFocusZoom option does not manipulate zoom when it is false", function() {
var zoomstate = $.mobile.zoom.enabled,
zoomoptiondefault = $.mobile.selectmenu.prototype.options.preventFocusZoom;
$(document)
.one("vmousedown.test", function(){
ok( $.mobile.zoom.enabled === zoomstate, "zoom is unaffected on vmousedown" );
})
.one("mouseup.test", function(){
ok( $.mobile.zoom.enabled === zoomstate, "zoom is unaffected on mouseup" );
$(document).unbind(".test");
$( "#select-choice-native" ).selectmenu( "option", "preventFocusZoom", zoomoptiondefault );
start();
});
$( "#select-choice-native" )
.selectmenu( "option", "preventFocusZoom", false )
.parent()
.trigger( "vmousedown" )
.trigger( "mouseup" );
});
})(jQuery);