summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE/client/bower_components/jquery.event.drag-new/event.drop/test/interaction.js
blob: 5b0f4f38dc854dfa60b462217bf5159c9b97fb78 (plain)
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
125
126
127
128
129
130
131
132
133
134
;(function(){
	
	module("Mouse Interaction");	
	
	// a simple re-usable test harness object
	var obj = {
		init: function( opts ){
			obj.$drag =	$('<div />')
				.css({
					position: 'absolute',
					top: 0,
					left: 0,
					height: 100,
					width: 100
				})
				.appendTo( document.body )
				.bind("draginit dragstart drag dragend click", opts || {}, function( event ){
					obj[ event.type ] += 1;
				});
			obj.$drop = $('<div />')
				.css({
					position: 'absolute',
					top: 0,
					left: 0,
					height: 100,
					width: 100
				})
				.appendTo( document.body )
				.bind("dropinit dropstart drop dropend",function( event ){
					obj[ event.type ] += 1;																 
				});
			$.extend( obj, { 
				draginit:0, dragstart:0, drag:0, dragend:0, 
				dropinit:0, dropstart:0, drop:0, dropend:0,	
				click:0 
			});
		},
		mouse: function(){
			var start = {
				pageX: Math.round( Math.random() * 90 ) + 5,
				pageY: Math.round( Math.random() * 90 ) + 5
			},
			end = {
				pageX: Math.round( Math.random() * 90 ) + start.pageX,
				pageY: Math.round( Math.random() * 90 ) + start.pageY
			};
			// simulate a complete mouse drag
			obj.$drag
				.fire("mousedown", start )
				.fire("mousemove", end )
				.fire("mouseup", end )
				.fire("click", end );
		},
		done: function(){
			obj.$drag.remove();
			obj.$drop.remove();
			start();
		}
	};	

	asyncTest('Drag and Drop defaults',function(){
		// prep DEFAULT interaction
		obj.init();
		// simulate DEFAULT interaction
		obj.mouse();
		// inspect results	
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.dropinit, 1, "dropinit");
		equals( obj.dropstart, 1, "dropstart");
		equals( obj.drop, 1, "drop");
		equals( obj.dropend, 1, "dropend");
		// continue
		obj.done();
	});
	
	asyncTest('Drag "drop" option (false)',function(){
		// prep interaction
		obj.init({ drop:false });
		// simulate drag
		obj.mouse();
		// inspect results		
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.dropinit, 0, "dropinit");
		equals( obj.dropstart, 0, "dropstart");
		equals( obj.drop, 0, "drop");
		equals( obj.dropend, 0, "dropend");
		// continue
		obj.done();
	});
	
	asyncTest('Drag "drop" option (unmatched)',function(){
		// prep interaction
		obj.init({ drop:'body' });
		// simulate drag
		obj.mouse();
		// inspect results		
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.dropinit, 0, "dropinit");
		equals( obj.dropstart, 0, "dropstart");
		equals( obj.drop, 0, "drop");
		equals( obj.dropend, 0, "dropend");
		// continue
		obj.done();
	});

	asyncTest('Drag "drop" option (matched)',function(){
		// prep interaction
		obj.init({ drop:'div' });
		// simulate drag
		obj.mouse();
		// inspect results		
		equals( obj.draginit, 1, "draginit");
		equals( obj.dragstart, 1, "dragstart");
		equals( obj.drag, 1, "drag");
		equals( obj.dragend, 1, "dragend");
		equals( obj.dropinit, 1, "dropinit");
		equals( obj.dropstart, 1, "dropstart");
		equals( obj.drop, 1, "drop");
		equals( obj.dropend, 1, "dropend");
		// continue
		obj.done();
	});
	
})();