Skip to content

Commit a677ea7

Browse files
committed
Dev: update jquery.simulate.js to latest version from http://github.com/jquery/jquery-simulate
1 parent fec36fd commit a677ea7

File tree

3 files changed

+97
-39
lines changed

3 files changed

+97
-39
lines changed

tests/jquery.simulate.js

+71-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
/*
2-
* jquery.simulate - simulate browser mouse and keyboard events
3-
* http://jqueryui.com
1+
/*!
2+
* jQuery Simulate v0.0.1 - simulate browser mouse and keyboard events
3+
* https://github.com/jquery/jquery-simulate
44
*
55
* Copyright 2012 jQuery Foundation and other contributors
66
* Released under the MIT license.
77
* http://jquery.org/license
8+
*
9+
* Date: Sun Dec 9 12:15:33 2012 -0500
810
*/
911

10-
;(function( $ ) {
12+
;(function( $, undefined ) {
1113

1214
var rkeyEvent = /^key/,
1315
rmouseEvent = /^(?:mouse|contextmenu)|click/;
@@ -31,7 +33,42 @@ $.simulate = function( elem, type, options ) {
3133
}
3234
};
3335

36+
$.extend( $.simulate, {
37+
38+
keyCode: {
39+
BACKSPACE: 8,
40+
COMMA: 188,
41+
DELETE: 46,
42+
DOWN: 40,
43+
END: 35,
44+
ENTER: 13,
45+
ESCAPE: 27,
46+
HOME: 36,
47+
LEFT: 37,
48+
NUMPAD_ADD: 107,
49+
NUMPAD_DECIMAL: 110,
50+
NUMPAD_DIVIDE: 111,
51+
NUMPAD_ENTER: 108,
52+
NUMPAD_MULTIPLY: 106,
53+
NUMPAD_SUBTRACT: 109,
54+
PAGE_DOWN: 34,
55+
PAGE_UP: 33,
56+
PERIOD: 190,
57+
RIGHT: 39,
58+
SPACE: 32,
59+
TAB: 9,
60+
UP: 38
61+
},
62+
63+
buttonCode: {
64+
LEFT: 0,
65+
MIDDLE: 1,
66+
RIGHT: 2
67+
}
68+
});
69+
3470
$.extend( $.simulate.prototype, {
71+
3572
simulateEvent: function( elem, type, options ) {
3673
var event = this.createEvent( type, options );
3774
this.dispatchEvent( elem, type, event, options );
@@ -56,7 +93,6 @@ $.extend( $.simulate.prototype, {
5693
detail: 0,
5794
screenX: 0,
5895
screenY: 0,
59-
// TODO: default clientX/Y to a position within the target element
6096
clientX: 1,
6197
clientY: 1,
6298
ctrlKey: false,
@@ -101,8 +137,14 @@ $.extend( $.simulate.prototype, {
101137
} else if ( document.createEventObject ) {
102138
event = document.createEventObject();
103139
$.extend( event, options );
104-
// TODO: what is this mapping for?
105-
event.button = { 0:1, 1:4, 2:2 }[ event.button ] || event.button;
140+
// standards event.button uses constants defined here: http://msdn.microsoft.com/en-us/library/ie/ff974877(v=vs.85).aspx
141+
// old IE event.button uses constants defined here: http://msdn.microsoft.com/en-us/library/ie/ms533544(v=vs.85).aspx
142+
// so we actually need to map the standard back to oldIE
143+
event.button = {
144+
0: 1,
145+
1: 4,
146+
2: 2
147+
}[ event.button ] || event.button;
106148
}
107149

108150
return event;
@@ -128,7 +170,10 @@ $.extend( $.simulate.prototype, {
128170
event.initKeyEvent( type, options.bubbles, options.cancelable, options.view,
129171
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
130172
options.keyCode, options.charCode );
131-
// TODO: what is this supporting?
173+
// initKeyEvent throws an exception in WebKit
174+
// see: http://stackoverflow.com/questions/6406784/initkeyevent-keypress-only-works-in-firefox-need-a-cross-browser-solution
175+
// and also https://bugs.webkit.org/show_bug.cgi?id=13368
176+
// fall back to a generic event until we decide to implement initKeyboardEvent
132177
} catch( err ) {
133178
event = document.createEvent( "Events" );
134179
event.initEvent( type, options.bubbles, options.cancelable );
@@ -147,17 +192,14 @@ $.extend( $.simulate.prototype, {
147192
$.extend( event, options );
148193
}
149194

150-
// TODO: can we hook into core's logic?
151-
if ( $.ui.ie || (({}).toString.call( window.opera ) === "[object Opera]") ) {
152-
// TODO: is charCode ever <0 ? Can we just use charCode || keyCode?
195+
if ( !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ) || (({}).toString.call( window.opera ) === "[object Opera]") ) {
153196
event.keyCode = (options.charCode > 0) ? options.charCode : options.keyCode;
154197
event.charCode = undefined;
155198
}
156199

157200
return event;
158201
},
159202

160-
// TODO: does this need type? Can't we just check event.type?
161203
dispatchEvent: function( elem, type, event ) {
162204
if ( elem.dispatchEvent ) {
163205
elem.dispatchEvent( event );
@@ -237,20 +279,31 @@ function findCenter( elem ) {
237279

238280
$.extend( $.simulate.prototype, {
239281
simulateDrag: function() {
240-
var target = this.target,
282+
var i = 0,
283+
target = this.target,
241284
options = this.options,
242285
center = findCenter( target ),
243286
x = Math.floor( center.x ),
244287
y = Math.floor( center.y ),
245288
dx = options.dx || 0,
246289
dy = options.dy || 0,
290+
moves = options.moves || 3,
247291
coord = { clientX: x, clientY: y };
292+
248293
this.simulateEvent( target, "mousedown", coord );
249-
coord = { clientX: x + 1, clientY: y + 1 };
250-
this.simulateEvent( document, "mousemove", coord );
251-
coord = { clientX: x + dx, clientY: y + dy };
252-
this.simulateEvent( document, "mousemove", coord );
253-
this.simulateEvent( document, "mousemove", coord );
294+
295+
for ( ; i < moves ; i++ ) {
296+
x += dx / moves;
297+
y += dy / moves;
298+
299+
coord = {
300+
clientX: Math.round( x ),
301+
clientY: Math.round( y )
302+
};
303+
304+
this.simulateEvent( document, "mousemove", coord );
305+
}
306+
254307
this.simulateEvent( target, "mouseup", coord );
255308
this.simulateEvent( target, "click", coord );
256309
}

tests/unit/resizable/resizable_events.js

+25-21
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ test("start", function() {
2929

3030
});
3131

32-
test("resize", function() {
32+
test( "resize", function() {
3333

34-
expect(9);
34+
expect( 9 );
3535

3636
var count = 0,
3737
handle = ".ui-resizable-se";
3838

3939
$("#resizable1").resizable({
4040
handles: "all",
41-
resize: function(event, ui) {
42-
if (count === 0) {
43-
equal( ui.size.width, 101, "compare width" );
44-
equal( ui.size.height, 101, "compare height" );
41+
resize: function( event, ui ) {
42+
if ( count === 0 ) {
43+
equal( ui.size.width, 125, "compare width" );
44+
equal( ui.size.height, 125, "compare height" );
4545
equal( ui.originalSize.width, 100, "compare original width" );
4646
equal( ui.originalSize.height, 100, "compare original height" );
4747
} else {
@@ -54,15 +54,15 @@ test("resize", function() {
5454
}
5555
});
5656

57-
TestHelpers.resizable.drag(handle, 50, 50);
57+
TestHelpers.resizable.drag( handle, 50, 50 );
5858

59-
equal(count, 2, "resize callback should happen exactly once per size adjustment");
59+
equal( count, 2, "resize callback should happen exactly once per size adjustment" );
6060

6161
});
6262

63-
test("resize (min/max dimensions)", function() {
63+
test( "resize (min/max dimensions)", function() {
6464

65-
expect(5);
65+
expect( 5 );
6666

6767
var count = 0,
6868
handle = ".ui-resizable-se";
@@ -73,7 +73,7 @@ test("resize (min/max dimensions)", function() {
7373
minHeight: 60,
7474
maxWidth: 100,
7575
maxHeight: 100,
76-
resize: function(event, ui) {
76+
resize: function( event, ui ) {
7777
equal( ui.size.width, 60, "compare width" );
7878
equal( ui.size.height, 60, "compare height" );
7979
equal( ui.originalSize.width, 100, "compare original width" );
@@ -82,15 +82,15 @@ test("resize (min/max dimensions)", function() {
8282
}
8383
});
8484

85-
TestHelpers.resizable.drag(handle, -50, -50);
85+
TestHelpers.resizable.drag( handle, -200, -200 );
8686

87-
equal(count, 1, "resize callback should happen exactly once per size adjustment");
87+
equal( count, 1, "resize callback should happen exactly once per size adjustment" );
8888

8989
});
9090

91-
test("resize (containment)", function() {
91+
test( "resize (containment)", function() {
9292

93-
expect(5);
93+
expect( 5 );
9494

9595
var count = 0,
9696
handle = ".ui-resizable-se",
@@ -102,18 +102,22 @@ test("resize (containment)", function() {
102102
$("#resizable1").resizable({
103103
handles: "all",
104104
containment: container,
105-
resize: function(event, ui) {
106-
equal( ui.size.width, 50, "compare width" );
107-
equal( ui.size.height, 50, "compare height" );
105+
resize: function( event, ui ) {
106+
equal( ui.size.width, 10, "compare width" );
107+
equal( ui.size.height, 10, "compare height" );
108108
equal( ui.originalSize.width, 100, "compare original width" );
109109
equal( ui.originalSize.height, 100, "compare original height" );
110110
count++;
111111
}
112112
});
113113

114-
TestHelpers.resizable.drag(handle, -50, -50);
114+
// Prove you can't resize outside containment by dragging southeast corner southeast
115+
TestHelpers.resizable.drag( handle, 100, 100 );
115116

116-
equal(count, 1, "resize callback should happen exactly once per size adjustment");
117+
// Prove you can't resize outside containment by dragging southeast corner northwest
118+
TestHelpers.resizable.drag( handle, -200, -200 );
119+
120+
equal( count, 1, "resize callback should happen exactly once per size adjustment" );
117121

118122
});
119123

@@ -148,7 +152,7 @@ test("stop", function() {
148152

149153
var count = 0,
150154
handle = ".ui-resizable-se";
151-
155+
152156
$("#resizable1").resizable({
153157
handles: "all",
154158
stop: function(event, ui) {

tests/unit/resizable/resizable_test_helpers.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ TestHelpers.resizable = {
33
// this mouseover is to work around a limitation in resizable
44
// TODO: fix resizable so handle doesn't require mouseover in order to be used
55
$( el ).simulate("mouseover").simulate( "drag", {
6+
moves: 2,
67
dx: dx,
78
dy: dy
89
});

0 commit comments

Comments
 (0)