-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmturk.js
executable file
·51 lines (45 loc) · 2.04 KB
/
mturk.js
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
/**
*
* gup(name) :: retrieves URL parameters if provided
*
* Prepares the page for MTurk on load.
* 1. looks for a form element with id="mturk_form", and sets its METHOD / ACTION
* 1a. All that the task page needs to do is submit the form element when ready
* 2. disables form elements if HIT hasn't been accepted
*
**/
// selector used by jquery to identify your form
var form_selector = "#mturk_form";
// Turkify the captioning page.
$(document).ready(function () {
// function for getting URL parameters
function gup(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else return unescape(results[1]);
}
$(document.body).append('<form id="mturk_form"></form>')
// is assigntmentId is a URL parameter
if((aid = gup("assignmentId"))!="" && $(form_selector).length>0) {
// If the HIT hasn't been accepted yet, disabled the form fields.
if(aid == "ASSIGNMENT_ID_NOT_AVAILABLE") {
$('input,textarea,select').attr("DISABLED", "disabled");
}
// Add a new hidden input element with name="assignmentId" that
// with assignmentId as its value.
var aid_input = $("<input type='hidden' name='assignmentId' value='" + aid + "'>").appendTo($(form_selector));
var time_spent = $("<input type='hidden' id='timeSpent' name='timeSpent' value='0'>").appendTo($(form_selector));
var reward_collected = $("<input type='hidden' id='rewardCollected' name='rewardCollected' value='0'>").appendTo($(form_selector));
var key_presses = $("<input type='hidden' id='keyPresses' name='keyPresses' value='0'>").appendTo($(form_selector));
// Make sure the submit form's method is POST
$(form_selector).attr('method', 'POST');
// Set the Action of the form to the provided "turkSubmitTo" field
if((submit_url=gup("turkSubmitTo"))!="") {
$(form_selector).attr('action', submit_url + '/mturk/externalSubmit');
}
}
});