-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (36 loc) · 1.14 KB
/
index.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
var translateField = document.getElementById("translate");
var translation = document.getElementById("yoda");
var yodaForm = document.getElementById("yoda-text");
var bubble = document.getElementById("chat-bubble");
var timer = null;
// translateField.onkeydown = function(){
// after three seconds, initiate awkward silence
timer = setTimeout(function(){
bubble.className = 'bubble';
translation.innerHTML = "...";
}, 3000);
// }
yodaForm.onsubmit = function(e){
e.preventDefault();
// clear timeout
if (timer) {
clearTimeout(timer);
timer = null;
}
translation.innerHTML = "Searching for answers, Yoda is....";
var userInput = document.getElementById("translate").value;
$.ajax({
url: "https://yoda.p.mashape.com/yoda?sentence=" + userInput,
success: function(response) {
translation.innerHTML = response;
},
headers: {
"X-Mashape-Key": "OGPgEThqxtmshCpTDZyOUBndDjLLp1Lm0qcjsnpxxdQawmnaj7"
},
error: function(){
translation.innerHTML = "Sorry, but Yoda is out for the day.";
},
timeout: 6000
});
translateField.value = " "
}