-
Notifications
You must be signed in to change notification settings - Fork 0
/
jssource.js
85 lines (78 loc) · 1.99 KB
/
jssource.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
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
var word = ""
var ans = new Array
var counter = 0
$(document).keypress(function(e) {
if(e.which == 13) {
word = $('#givenWord').val();
word = word.toLowerCase();
word = $.trim(word);
word = word.split(" ")[0];
if (counter == 0){
counter++
$.get('preceed_with_an.txt', function(data){
ans = data.split('\n')
console.log("loaded")
processResults();
});
}else{
processResults();
}
}
});
var options = {
callback: function (value) {
word = $('#givenWord').val();
word = word.toLowerCase();
word = $.trim(word);
word = word.split(" ")[0];
word = word.split("-")[0];
if (counter == 0){
counter++
$.get('preceed_with_an.txt', function(data){
ans = data.split('\n')
console.log("loaded")
processResults();
});
}else{
processResults();
}
},
wait: 750,
highlight: true,
allowSubmit: true,
captureLength: 2
}
$("#givenWord").typeWatch( options );
function resizeInput() {
var content =
$(this).val().length > 0 ? $(this).val() : $(this).prop("placeholder");
var widthTester = $("<span>"+content+"</span>").hide();
widthTester.insertAfter($(this));
$(this).css("width",widthTester.width()+"px");
widthTester.remove();
}
$('input[type="text"]')
.keyup(resizeInput)
.each(resizeInput);
$('#givenWord').focus(function() {
setTimeout((function(el) {
var strLength = el.value.length;
return function() {
if(el.setSelectionRange !== undefined) {
el.setSelectionRange(strLength, strLength);
} else {
$(el).val(el.value);
}
}}(this)), 0);
});
function processResults() {
var answer = $("#answer");
for (var i = 0; i < ans.length; i++){
if (ans[i] === word && word != ""){
$(answer).text("An");
break;
}else{
$(answer).text("A");
}
}
}