Skip to content

Commit 692ed50

Browse files
committed
updated tests and reverse to work with jQuery 1.9. Mostly replacing $.fn.live with $.fn.on
1 parent 4d90e4c commit 692ed50

File tree

8 files changed

+145
-86
lines changed

8 files changed

+145
-86
lines changed

event/default/default_pause_test.js

+79-52
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,43 @@ test("default and pause with delegate", function(){
3030

3131
});
3232

33-
test("default and pause with live", function(){
33+
test("default and pause with live or on", function(){
3434
$("#qunit-test-area").html("<div id='foo_default_pause'>hello</div>")
3535

36-
var order = [];
36+
var order = [],
37+
defaultShow = function(){
38+
order.push("default")
39+
},
40+
show = function(ev){
41+
order.push('show')
42+
ev.pause();
43+
setTimeout(function(){
44+
ev.resume();
45+
setTimeout(function(){
46+
start();
47+
same(order,['show','default']);
48+
if($.fn.live){
49+
$("#foo_default_pause").die("show");
50+
$("#foo_default_pause").die("default.show");
51+
} else {
52+
$(document.body).off("default.show");
53+
$(document.body).off("show");
54+
}
55+
56+
},30)
57+
},50)
58+
};
3759
stop();
3860

39-
$("#foo_default_pause").live("default.show", function(){
40-
order.push("default")
41-
});
42-
$("#foo_default_pause").live("show", function(ev){
43-
order.push('show')
44-
ev.pause();
45-
setTimeout(function(){
46-
ev.resume();
47-
setTimeout(function(){
48-
start();
49-
same(order,['show','default'])
50-
$("#foo_default_pause").die("show");
51-
$("#foo_default_pause").die("default.show");
52-
},30)
53-
},50)
54-
});
61+
if( $.fn.live ){
62+
$("#foo_default_pause").live("default.show", defaultShow);
63+
$("#foo_default_pause").live("show", show);
64+
} else {
65+
$(document.body).on("default.show", "#foo_default_pause",defaultShow);
66+
$(document.body).on("show", "#foo_default_pause",show);
67+
}
68+
69+
5570

5671

5772
$("#foo_default_pause").trigger("show")
@@ -62,26 +77,37 @@ test("default and pause with live", function(){
6277
test("triggerAsync", function(){
6378
$("#qunit-test-area").html("<div id='foo_default_pause'>hello</div>")
6479

65-
var order = [];
66-
stop();
67-
68-
$("#foo_default_pause").live("default.show", function(){
69-
order.push("default")
70-
});
71-
72-
$("#foo_default_pause").live("show", function(ev){
73-
order.push('show')
74-
ev.pause();
75-
setTimeout(function(){
76-
ev.resume();
80+
var order = [],
81+
defaultShow = function(){
82+
order.push("default")
83+
},
84+
show = function(ev){
85+
order.push('show')
86+
ev.pause();
7787
setTimeout(function(){
78-
start();
79-
$("#foo_default_pause").die()
80-
same(order,['show','default','async'])
81-
},30)
82-
},50)
83-
});
88+
ev.resume();
89+
setTimeout(function(){
90+
start();
91+
if( $.fn.die ) {
92+
$("#foo_default_pause").die();
93+
} else {
94+
$(document.body).off();
95+
}
96+
97+
same(order,['show','default','async'])
98+
},30)
99+
},50)
100+
};
101+
102+
stop();
84103

104+
if( $.fn.live ){
105+
$("#foo_default_pause").live("default.show", defaultShow);
106+
$("#foo_default_pause").live("show", show);
107+
} else {
108+
$(document.body).on("default.show", "#foo_default_pause",defaultShow);
109+
$(document.body).on("show", "#foo_default_pause",show);
110+
}
85111

86112
$("#foo_default_pause").triggerAsync("show", function(){
87113
order.push("async")
@@ -94,19 +120,20 @@ test("triggerAsync with prevented callback when ev.preventDefault() is called be
94120
var order = [];
95121
stop();
96122

97-
$("#foo_default_pause").live("default.show", function(){
123+
$(document.body).on("default.show","#foo_default_pause", function(){
98124
order.push("default")
99125
});
100126

101-
$("#foo_default_pause").live("show", function(ev){
127+
$(document.body).on("show", "#foo_default_pause", function(ev){
102128
order.push('show');
103129
ev.preventDefault();
104130
ev.pause();
105131
setTimeout(function(){
106132
ev.resume();
107133
setTimeout(function(){
108134
start();
109-
$("#foo_default_pause").die()
135+
$(document.body).off("show");
136+
$(document.body).off("default.show")
110137
same(order,['show','prevented'])
111138
},30)
112139
},50)
@@ -125,11 +152,11 @@ test("triggerAsync with prevented callback when ev.preventDefault() is called af
125152
var order = [];
126153
stop();
127154

128-
$("#foo_default_pause").live("default.show", function(){
155+
$(document.body).on("default.show", "#foo_default_pause",function(){
129156
order.push("default")
130157
});
131158

132-
$("#foo_default_pause").live("show", function(ev){
159+
$(document.body).on("show", "#foo_default_pause",function(ev){
133160
order.push('show');
134161

135162
ev.pause();
@@ -138,7 +165,7 @@ test("triggerAsync with prevented callback when ev.preventDefault() is called af
138165
ev.resume();
139166
setTimeout(function(){
140167
start();
141-
$("#foo_default_pause").die()
168+
$(document.body).off("show").off("default.show")
142169
same(order,['show','prevented'])
143170
},30)
144171
},50)
@@ -158,16 +185,16 @@ test("triggerAsync within another triggerAsync", function(){
158185
var order = [];
159186
stop();
160187

161-
$("#foo_default_pause").live("default.show", function(){
188+
$(document.body).on("default.show", "#foo_default_pause",function(){
162189
order.push("show default")
163190
});
164-
$("#foo_default_pause").live("default.hide", function(){
191+
$(document.body).on("default.hide", "#foo_default_pause", function(){
165192
order.push("hide default")
166193
});
167-
$("#foo_default_pause").live("hide", function(){
194+
$(document.body).on("hide", "#foo_default_pause",function(){
168195
order.push("hide")
169196
});
170-
$("#foo_default_pause").live("show", function(ev){
197+
$(document.body).on("show", "#foo_default_pause",function(ev){
171198
order.push('show');
172199
ev.pause();
173200
$("#foo_default_pause").triggerAsync("hide",function(){
@@ -176,7 +203,7 @@ test("triggerAsync within another triggerAsync", function(){
176203
setTimeout(function(){
177204

178205
start();
179-
$("#foo_default_pause").die()
206+
$(document.body).off()
180207
same(order,['show','hide','hide default',"hide async","show default","show async"])
181208
},30)
182209

@@ -199,16 +226,16 @@ test("triggerAsync within another triggerAsync with prevented callback", functio
199226
var order = [];
200227
stop();
201228

202-
$("#foo_default_pause").live("default.show", function(){
229+
$(document.body).on("default.show", "#foo_default_pause",function(){
203230
order.push("show default")
204231
});
205-
$("#foo_default_pause").live("default.hide", function(){
232+
$(document.body).on("default.hide", "#foo_default_pause", function(){
206233
order.push("hide default")
207234
});
208-
$("#foo_default_pause").live("hide", function(){
235+
$(document.body).on("hide", "#foo_default_pause",function(){
209236
order.push("hide")
210237
});
211-
$("#foo_default_pause").live("show", function(ev){
238+
$(document.body).on("show", "#foo_default_pause", function(ev){
212239
order.push('show');
213240
ev.preventDefault();
214241
ev.pause();
@@ -217,7 +244,7 @@ test("triggerAsync within another triggerAsync with prevented callback", functio
217244
ev.resume();
218245
setTimeout(function(){
219246
start();
220-
$("#foo_default_pause").die()
247+
$(document.body).off()
221248
same(order,['show','hide','hide default',"hide async","show prevented"])
222249
},30)
223250

event/default/default_test.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test("triggering defaults", function(){
6464

6565

6666

67-
test("live on default events", function(){
67+
test("on default events", function(){
6868

6969
$("#qunit-test-area").html(
7070

@@ -76,16 +76,13 @@ test("live on default events", function(){
7676
count3 = 0;
7777
var jq = $();
7878
jq.context = bw[0];
79-
jq.selector = "#wrap1"
80-
jq.live("default.touch", function(){
79+
jq.selector = "#wrap1";
80+
81+
$("#qunit-test-area").on("default.touch","#wrap1", function(){
8182
count1++;
8283
});
8384

84-
//2nd selector
85-
var jq2 = $();
86-
jq2.context = bw[0];
87-
jq2.selector = "#wrap2"
88-
jq2.live("default.touching", function(){
85+
$("#qunit-test-area").on("default.touching", "#wrap2",function(){
8986
count2++;
9087
});
9188

@@ -113,17 +110,17 @@ test("default and live order", function(){
113110
var order = [];
114111
$("#qunit-test-area").html("<div id='foo'></div>")
115112

116-
$("#foo").live("default.show", function(){
113+
$(document.body).on("default.show", "#foo",function(){
117114
order.push("default")
118115
});
119-
$("#foo").live("show", function(){
116+
$(document.body).on("show","#foo", function(){
120117
order.push("show")
121118
});
122119

123120
$("#foo").trigger("show")
124121

125122
same(order, ['show','default'],"show then default")
126-
$("#foo").die()
123+
$(document.body).off()
127124
});
128125

129126

event/drag/drag_test.js

+21-17
Original file line numberDiff line numberDiff line change
@@ -41,46 +41,46 @@ test("dragging an element", function(){
4141

4242
var drags = {}, drops ={};
4343

44-
$('#drag')
45-
.live("dragdown", function(){
44+
$("#qunit-test-area")
45+
.on("dragdown", '#drag',function(){
4646
drags.dragdown = true;
4747
})
48-
.live("draginit", function(){
48+
.on("draginit", '#drag', function(){
4949
drags.draginit = true;
5050
})
51-
.live("dragmove", function(){
51+
.on("dragmove", '#drag', function(){
5252
drags.dragmove = true;
5353
})
54-
.live("dragend", function(){
54+
.on("dragend", '#drag', function(){
5555
drags.dragend = true;
5656
})
57-
.live("dragover", function(){
57+
.on("dragover", '#drag', function(){
5858
drags.dragover = true;
5959
})
60-
.live("dragout", function(){
60+
.on("dragout", '#drag', function(){
6161
drags.dragout = true;
6262
})
63-
.live("dragcleanup", function() {
63+
.on("dragcleanup", '#drag', function() {
6464
drags.dragcleanup = true;
6565
})
6666

67-
$('#drop')
68-
.live("dropinit", function(){
67+
$("#qunit-test-area")
68+
.on("dropinit",'#drop', function(){
6969
drops.dropinit = true;
7070
})
71-
.live("dropover", function(){
71+
.on("dropover",'#drop', function(){
7272
drops.dropover = true;
7373
})
74-
.live("dropout", function(){
74+
.on("dropout",'#drop', function(){
7575
drops.dropout = true;
7676
})
77-
.live("dropmove", function(){
77+
.on("dropmove",'#drop', function(){
7878
drops.dropmove = true;
7979
})
80-
.live("dropon", function(){
80+
.on("dropon",'#drop', function(){
8181
drops.dropon = true;
8282
})
83-
.live("dropend", function(){
83+
.on("dropend",'#drop', function(){
8484
drops.dropend = true;
8585
})
8686

@@ -113,6 +113,7 @@ test("dragging an element", function(){
113113
ok(drops.dropout, "dropout fired correctly")
114114
//div.remove();
115115
start();
116+
$("#qunit-test-area").off()
116117
})
117118
})
118119

@@ -155,7 +156,7 @@ test("drag position", function(){
155156

156157
var drags = {}, drops ={};
157158

158-
$('#drag').live("draginit", function(){
159+
$("#qunit-test-area").on("draginit",'#drag', function(){
159160
drags.draginit = true;
160161
})
161162
var offset = $('#drag').offset();
@@ -167,6 +168,7 @@ test("drag position", function(){
167168
equals(offset.top+20, Math.ceil(offset2.top), "top")
168169
equals(offset.left+20, Math.ceil(offset2.left), "left")
169170
start();
171+
$("#qunit-test-area").off()
170172
})
171173
});
172174

@@ -219,8 +221,10 @@ test("dragdown" , function(){
219221
equals(offset.top+20, Math.ceil(offset2.top), "top")
220222
equals(offset.left+20, Math.ceil(offset2.left), "left")
221223
// IE doesn't respect preventDefault on text inputs (http://www.quirksmode.org/dom/events/click.html)
222-
if(!$.browser.msie)
224+
if(!document.body.attachEvent) {
223225
ok(draginpfocused, "First input was allowed to be focused correctly");
226+
}
227+
224228
//ok(!dragnopreventfocused, "Second input was not allowed to focus");
225229
start();
226230
})

0 commit comments

Comments
 (0)