1
1
/* global alertify, $ */
2
2
3
- define ( [ 'jquery' , 'controllers/tableController' , 'helper/mpc' , 'alertify' , 'alertify_defaults' , 'controllers/confirmationCodes' ] , function ( $ , tableController , mpc , alertify , _ , confirmationCodes ) {
4
-
5
- console . log ( confirmationCodes ) ;
6
- console . log ( confirmationCodes . get_confirmation_code ( ) ) ;
3
+ define ( [ 'jquery' , 'controllers/tableController' , 'controllers/usabilityController' , 'helper/mpc' , 'alertify' , 'alertify_defaults' ] , function ( $ , tableController , usabilityController , mpc , alertify , _ ) {
7
4
8
5
var client = ( function ( ) {
9
6
var SESSION_KEY_ERROR = 'Invalid session number' ;
@@ -27,121 +24,16 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
27
24
discrepancies : SEMANTIC_CELLS
28
25
} ;
29
26
30
- // currently the client width:height ratio is ~ 0.45:1
31
- var MOUSE_PRECISION_WIDTH = 90 ;
32
- var MOUSE_PRECISION_HEIGHT = 200 ;
33
-
34
-
35
- let analytics = {
36
-
37
- validation_errors : {
38
-
39
- SESSION_KEY_ERROR : 0 ,
40
- PARTICIPATION_CODE_ERROR : 0 ,
41
- SESSION_PARTICIPATION_CODE_SERVER_ERROR : 0 ,
42
- UNCHECKED_ERR : 0 ,
43
- ADD_QUESTIONS_ERR : 0 ,
44
- GENERIC_TABLE_ERR : 0 ,
45
- SERVER_ERR : 0 ,
46
- GENERIC_SUBMISSION_ERR : 0 ,
47
- NAN_EMPTY_CELLS : 0 ,
48
- SEMANTIC_CELLS : 0 ,
49
- } ,
50
- mouse_positions : [ ] ,
51
- mouse_clicks : [ ] ,
52
- time_ms : 0 ,
53
- } ;
54
- /*
55
- [ [ [], [], ..., [] ],
56
- [ [], [], ..., [] ],
57
- [ [], [], ..., [] ],
58
- [ [], [], ..., [] ],
59
- ]
60
- */
61
27
62
28
// define mouse_positions as 100x1000 array
63
- for ( var i = 0 ; i < MOUSE_PRECISION_WIDTH ; i ++ ) {
64
- analytics . mouse_positions . push ( [ ] ) ;
65
- analytics . mouse_clicks . push ( [ ] ) ;
66
- for ( var k = 0 ; k < MOUSE_PRECISION_HEIGHT ; k ++ ) {
67
- analytics . mouse_positions [ i ] . push ( 0 )
68
- analytics . mouse_clicks [ i ] . push ( 0 )
69
- }
70
- }
71
29
72
- document . addEventListener ( 'mousemove' , handleMouseMove , false ) ;
73
- document . addEventListener ( 'click' , handleMouseClick , false ) ;
74
- function getPos ( event ) {
75
-
76
- // TODO: make sure this is consistent across browsers
77
- var height ;
78
- var width ;
79
- if ( event . pageX === null && event . clientX !== null ) {
80
- var doc = eventDoc . documentElement ;
81
- var body = eventDoc . body ;
82
-
83
-
84
- event . pageX = event . clientX +
85
- ( doc && doc . scrollLeft || body && body . scrollLeft || 0 ) -
86
- ( doc && doc . clientLeft || body && body . clientLeft || 0 ) ;
87
- event . pageY = event . clientY +
88
- ( doc && doc . scrollTop || body && body . scrollTop || 0 ) -
89
- ( doc && doc . clientTop || body && body . clientTop || 0 ) ;
90
- }
91
- width = window . innerWidth
92
- || document . documentElement . clientWidth
93
- || document . body . clientWidth ;
94
-
95
- height = document . body . scrollHeight ;
96
- return [ event . pageX / width , event . pageY / height ] ;
97
- }
98
-
99
- function handleMouseClick ( event ) {
100
- // y coord should potentially be mult. by 100
101
- // to account for difference in x, y page size
102
-
103
- var pos = getPos ( event ) ;
104
- var x = Math . floor ( pos [ 0 ] * MOUSE_PRECISION_WIDTH ) ;
105
- var y = Math . floor ( pos [ 1 ] * MOUSE_PRECISION_HEIGHT ) ;
106
- //each array stores # of hits at this area
107
- analytics . mouse_clicks [ x ] [ y ] ++ ;
108
- }
109
- function handleMouseMove ( event ) {
110
- // y coord should potentially be mult. by 100
111
- // to account for difference in x, y page size
112
-
113
- var pos = getPos ( event ) ;
114
- var x = Math . floor ( pos [ 0 ] * MOUSE_PRECISION_WIDTH ) ;
115
- var y = Math . floor ( pos [ 1 ] * MOUSE_PRECISION_HEIGHT ) ;
116
- //each array stores # of hits at this area
117
- analytics . mouse_positions [ x ] [ y ] ++ ;
118
- }
119
-
120
- let startDate = new Date ( ) ;
121
- let elapsedTime = 0 ;
122
-
123
- const focus = function ( ) {
124
- startDate = new Date ( ) ;
125
- } ;
126
-
127
- const blur = function ( ) {
128
- const endDate = new Date ( ) ;
129
- const spentTime = endDate . getTime ( ) - startDate . getTime ( ) ;
130
- elapsedTime += spentTime ;
131
- } ;
132
-
133
- const beforeunload = function ( ) {
134
- const endDate = new Date ( ) ;
135
- const spentTime = endDate . getTime ( ) - startDate . getTime ( ) ;
136
- elapsedTime += spentTime ;
137
- analytics [ 'time_ms' ] = elapsedTime ;
138
- // elapsedTime contains the time spent on page in milliseconds
139
- } ;
30
+ document . addEventListener ( 'mousemove' , usabilityController . handleMouseMove , false ) ;
31
+ document . addEventListener ( 'click' , usabilityController . handleMouseClick , false ) ;
140
32
141
33
// TODO EventListeners prolly shouldn't be in this file
142
- window . addEventListener ( 'focus' , focus ) ;
143
- window . addEventListener ( 'blur' , blur ) ;
144
- window . addEventListener ( 'beforeunload' , beforeunload ) ;
34
+ window . addEventListener ( 'focus' , usabilityController . focus ) ;
35
+ window . addEventListener ( 'blur' , usabilityController . blur ) ;
36
+ window . addEventListener ( 'beforeunload' , usabilityController . beforeunload ) ;
145
37
146
38
// TODO: create new view for alerts
147
39
function error ( msg ) {
@@ -295,22 +187,22 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
295
187
var $participationCode = $ ( '#participation-code' ) ;
296
188
if ( ! validateSessionInput ( $participationCode , false ) ) {
297
189
errors = errors . concat ( PARTICIPATION_CODE_ERROR ) ;
298
- analytics . validation_errors [ PARTICIPATION_CODE_ERROR ] ++ ;
190
+ usabilityController . analytics . validation_errors [ PARTICIPATION_CODE_ERROR ] ++ ;
299
191
}
300
192
301
193
// Validate the remaining components after session and
302
194
// and participation code are validated with the server.
303
195
var validateRemainingComponents = function ( result ) {
304
196
if ( ! result ) {
305
197
errors = errors . concat ( SESSION_PARTICIPATION_CODE_SERVER_ERROR ) ;
306
- analytics . validation_errors [ SESSION_PARTICIPATION_CODE_SERVER_ERROR ] ++ ;
198
+ usabilityController . analytics . validation_errors [ SESSION_PARTICIPATION_CODE_SERVER_ERROR ] ++ ;
307
199
}
308
200
309
201
// Verify confirmation check box was checked
310
202
var verifyChecked = $ ( '#verify' ) . is ( ':checked' ) ;
311
203
if ( ! verifyChecked ) {
312
204
errors = errors . concat ( UNCHECKED_ERR ) ;
313
- analytics . validation_errors [ UNCHECKED_ERR ] ++ ;
205
+ usabilityController . analytics . validation_errors [ UNCHECKED_ERR ] ++ ;
314
206
}
315
207
316
208
// Verify additional questions
@@ -336,7 +228,7 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
336
228
337
229
if ( ! questionsValid ) {
338
230
errors = errors . concat ( ADD_QUESTIONS_ERR ) ;
339
- analytics . validation_errors [ ADD_QUESTIONS_ERR ] ++ ;
231
+ usabilityController . analytics . validation_errors [ ADD_QUESTIONS_ERR ] ++ ;
340
232
}
341
233
342
234
// Register semantic discrepancies validator.
@@ -448,10 +340,10 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
448
340
// For now, keeping analytic data separate from submission data
449
341
// analytics is a global var, probably not that chill
450
342
451
- beforeunload ( ) ; // updates time analytic
452
- analytics . time_ms = Math . floor ( analytics . time_ms / 1000 ) ;
343
+ usabilityController . beforeunload ( ) ; // updates time analytic
344
+ usabilityController . analytics . time_ms = Math . floor ( usabilityController . analytics . time_ms / 1000 ) ;
453
345
454
- var analytic_shares = mpc . secretShareValues ( analytics ) ;
346
+ var analytic_shares = mpc . secretShareValues ( usabilityController . analytics ) ;
455
347
var analytic_data = analytic_shares [ 'data' ] ;
456
348
var analytic_mask = analytic_shares [ 'mask' ] ;
457
349
@@ -508,8 +400,6 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
508
400
509
401
success ( 'Submitted data.' ) ;
510
402
convertToHTML ( submitEntries ) ;
511
- // post confirmation or completion code for mturk users to submit to in aws/mturk site
512
- alert ( confirmationCodes . get_confirmation_code ( ) ) ;
513
403
514
404
// Stop loading animation
515
405
la . stop ( ) ;
0 commit comments