-
Notifications
You must be signed in to change notification settings - Fork 0
/
interrogate.old.js
executable file
·144 lines (129 loc) · 4.07 KB
/
interrogate.old.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
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
135
136
137
138
139
140
141
142
143
144
// JavaScript Document
function addLine(div,ul,text,ellipsis){
li = document.createElement("LI");
li.className = "chatLine";
ul.appendChild(li);
li.scrollIntoView();
if(ul.offsetHeight >= div.offsetHeight && flag !== true){
ul.style.height = div.offsetHeight + "px";
flag = true;
}
if (ellipsis){
li.innerHTML = "...";
setTimeout(function(){setLiText(li,text)},750);
}
else{
li.innerHTML = "DETECTIVE: " + text;
}
}
function getHint(){
if ($("#hintPrompt").css("display") != "none"){
$("#hintPrompt").fadeToggle();
$("#hintContent").fadeToggle();
}
}
function initChat(){
cookieDict = $.cookie();
if (isEmpty(cookieDict)){
$.cookie("artie-level","1");
$.cookie("judd-level","1");
}
// $.ajax({
// url: "init.php",
// type: "post",
// success: function(){
// console.log('chat data initiated...')
// },
// error: function(jqXHR, textStatus, errorThrown){
// alert(errorThrown);
// setTimeout('updateChat()', 3000);
// }
// })
}
function isEmpty(ob){
for(var i in ob){ return false;}
return true;
}
function setLiText(li,text){
li.innerHTML = text;
}
function setScroll(){
var box = $(".prisonerResponse")[0]; //selector returns whole set. just get the first one.
box.scrollTop = box.scrollHeight;
}
function updatePrompt(promptText){
$("#hintContent").css("display","none");
$("#hintPrompt").css("display","block");
$("#hintPrompt").html('Click here for a new hint.');
$('#hintContent').html(promptText);
}
function updateChat(obj){
var divs = $(".prisonerResponse"),
uls = $(".responseList"),
inputs = $(".userInput");
flag = false;
prisoner = obj.id;
// identify the correct prisoner box
if (obj.id == "artie"){
i = 0;
}
else if (obj.id == "judd"){
i = 1;
}
var div = divs[i],
ul = uls[i],
input = inputs[i],
li;
obj.onkeypress = function(e){
var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
if (charCode == 13) {
// read the openness level from the html data
// var level = div.getAttribute('data-level');
var key = prisoner + '-level';
var level = $.cookie(key);
console.log($.cookie());
console.log(level);
// read the input text
inputText = input.value;
// do ajax
$.ajax({
url: "prisonerResponse",
type: "post",
contentType:"application/json",
dataType:"json",
data: JSON.stringify({'prisoner':prisoner,'q':inputText,'level':level}),
success: function(response){
console.log(response);
// var promptText = $(xml).find('prompt').text();
// if (promptText){
// updatePrompt(promptText,inputText);
// }
// // add the player's own comment to the narrative stream
// addLine(div,ul,inputText,false);
// // // add the response to the narrative stream
// setTimeout(function(){addLine(div,ul,responseText,true)},750);
// // // if we've advanced a level, darken the red border
// var newLevel = $(xml).find('level').text();
// if (parseInt(newLevel,10) > parseInt(level,10)){
// console.log(newLevel + ' ' + level);
// border = $(div).css("border-color");
// match = border.match(/(\d\.*\d*)\)/);
// opacity = parseFloat(match[1]);
// console.log(opacity);
// opacity += .1;
// console.log(opacity);
// $(div).css("border-color","rgba(255, 0, 0, " + opacity + ")");
// console.log('css changed');
// $(div).attr("data-level",newLevel);
// }
},
error: function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
setTimeout('updateChat()', 3000);
}
})
// return ($(xml).find('response').text());
input.value = "";
}
}
}