-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
349 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,22 @@ | ||
<html> | ||
<head> | ||
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen"> | ||
<script type = "application/javascript"> | ||
var conversationIndex = 1; | ||
var watsonContext = ""; | ||
function loadJSON(){ | ||
|
||
var questionText = document.getElementById('input').value; | ||
var dialog = new Object(); | ||
dialog.newQuestion = questionText; | ||
|
||
var qTOAdd = document.createDocumentFragment(); | ||
var qNnewDiv = document.createElement('div'); | ||
qNnewDiv.id = 'q'+conversationIndex; | ||
qNnewDiv.className = 'conversationQuestion'; | ||
var qtext = document.createElement('div'); | ||
qtext.innerHTML=questionText; | ||
qNnewDiv.appendChild(qtext); | ||
qTOAdd.appendChild(qNnewDiv); | ||
|
||
document.getElementById("conversation").appendChild(qTOAdd); | ||
|
||
|
||
//var data_file = "api/talktome?question="+questionText; | ||
if (!Object.is(watsonContext,"")) { | ||
dialog.context=watsonContext; | ||
} | ||
var http_request = new XMLHttpRequest(); | ||
try{ | ||
// Opera 8.0+, Firefox, Chrome, Safari | ||
http_request = new XMLHttpRequest(); | ||
|
||
}catch (e){ | ||
// Internet Explorer Browsers | ||
try{ | ||
http_request = new ActiveXObject("Msxml2.XMLHTTP"); | ||
|
||
}catch (e) { | ||
|
||
try{ | ||
http_request = new ActiveXObject("Microsoft.XMLHTTP"); | ||
}catch (e){ | ||
// Something went wrong | ||
alert("Your browser broke!"); | ||
return false; | ||
} | ||
|
||
} | ||
} | ||
|
||
http_request.onreadystatechange = function(){ | ||
|
||
if (http_request.readyState == 4 ){ | ||
// Javascript function JSON.parse to parse JSON data | ||
var jsonObj = JSON.parse(http_request.responseText); | ||
console.log(jsonObj); | ||
var toAdd = document.createDocumentFragment(); | ||
//for(var i = 0; i < jsonObj.length; i++) { | ||
// var obj = jsonObj[i]; | ||
var newDiv = document.createElement('div'); | ||
newDiv.id = 'r'+conversationIndex; | ||
conversationIndex++; | ||
newDiv.className = 'conversation'; | ||
var text = document.createElement('div'); | ||
text.innerHTML=jsonObj.text; | ||
newDiv.appendChild(text); | ||
//var divConversationContext = document.getElementById('conversation_context'); | ||
//divConversationContext.value=jsonObj.context; | ||
watsonContext =jsonObj.context; | ||
|
||
toAdd.appendChild(newDiv); | ||
// } | ||
|
||
|
||
document.getElementById("conversation").appendChild(toAdd); | ||
|
||
document.getElementById('input').value=""; | ||
} | ||
} | ||
var url = "https://eofwatsonsdkusage.mybluemix.net/api/talkdutchtowebsite"; | ||
http_request.open("POST", url, true); | ||
http_request.setRequestHeader("Content-type", "application/json"); | ||
//http_request.open("GET", data_file, true); | ||
http_request.send(JSON.stringify(dialog)); | ||
} | ||
|
||
</script> | ||
<script type = "application/javascript"> | ||
function yesbye() { | ||
document.getElementById('input').value="yes"; | ||
loadJSON(); | ||
} | ||
|
||
function nobye(){ | ||
document.getElementById('input').value="no"; | ||
loadJSON(); | ||
} | ||
|
||
function button(userinput, buttonContext) { | ||
document.getElementById('input').value=userinput; | ||
watsonContext.product=buttonContext; | ||
loadJSON(); | ||
} | ||
|
||
function openlink(url) { | ||
var win = window.open(url,'_blank'); | ||
win.focus(); | ||
} | ||
|
||
function process(e) { | ||
var code = (e.keyCode ? e.keyCode : e.which); | ||
if (code == 13) { //Enter keycode | ||
loadJSON(); | ||
} | ||
} | ||
|
||
</script> | ||
|
||
<title>Nederlandstalige Chat</title> | ||
</head> | ||
<body onload='loadJSON()' > | ||
<h2>Hallo Nederlandstalige Watson</h2> | ||
<div id="conversation"> | ||
|
||
|
||
</div> | ||
<div> | ||
<input type="hidden" id="conversation_context" /> | ||
</div> | ||
<div> | ||
<input type="text" id="input" onkeypress="process(event, this)"/> | ||
<button class="askbutton" type="button" onclick="loadJSON()">Ask</button> | ||
</div> | ||
<br> | ||
|
||
</body> | ||
<!DOCTYPE html> | ||
<html lang="nl" xmlns="http://www.w3.org/1999/xhtml" class="mcf-noframes chrome chrome54 chrome54_0 chrome54_0_2840 chrome54_0_2840_99 webkit webkit537 webkit537_36" | ||
data-cookiesettings="loaded"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
|
||
<script type = "application/javascript" src="scripts/smalltalk.js"></script> | ||
<script type="text/javascript" src="scripts/jquery.min.js"></script> | ||
|
||
<head> | ||
<title>Nederlandstalige Chat</title> | ||
</head> | ||
<body onload='loadJSON()' > | ||
|
||
<h2>Small-talk minimalistisch</h2> | ||
<div id="conversation"></div> | ||
<div><input type="hidden" id="conversation_context" /></div> | ||
<div> | ||
<input type="text" id="input" onkeypress="process(event, this)"/> | ||
<button class="askbutton" type="button" onclick="loadJSON()">Vraag</button> | ||
</div> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.