DemoJS.js
1 function download(filename, text) { 2 var element = document.createElement('a'); 3 element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); 4 element.setAttribute('download', filename); 5 6 element.style.display = 'none'; 7 document.body.appendChild(element); 8 9 element.click(); 10 11 document.body.removeChild(element); 12 } 13 var enteredCmds=[], 14 aiFunctions={}, 15 userFunctions={}, 16 currentAI="Andy", 17 usersName="User"; 18 userFunctions.say=function(text) { 19 text=emojione.toImage(text.replace(/</g,"<").replace(/>/g,">").replace(/^\s*/g,"").replace(/\s*$/g,"")); 20 $("#output").find("tbody").append("<tr style='min-height:1em'><td style='height:1px'></td><td style='float:right'><p class='userText ui-corner-left ui-corner-top'>"+text+"</p><td/><td style='vertical-align: bottom;'><p class='userName'>"+usersName+"</p></td></tr>"); 21 $("#output").animate({ scrollTop: "+="+$($("#output p")[$("#output p").length-2]).outerHeight()}, 2000); 22 }; 23 aiFunctions.say=function(text) { 24 text=emojione.toImage(text.replace(/</g,"<").replace(/>/g,">").replace(/^\s*/g,"").replace(/\s*$/g,"")); 25 $("#output").find("tbody").append("<tr style='min-height:1em'><td style='vertical-align: bottom;'><p class='aiName'>"+currentAI+"</p></td><td style='float:left'><p class='aiText ui-corner-right ui-corner-top'>"+text+"</p><td/><td style='height:1px'></td></tr>"); 26 $("#output").animate({ scrollTop: "+="+$($("#output p")[$("#output p").length-2]).outerHeight()}, 2000); 27 }; 28 var ais={}; 29 ais[currentAI]=new Ai(currentAI); 30 $(function() { 31 $(":file").css("margin","0px").parent().css("padding","0px").find(":file").addClass("ui-button").before('<div style="position:absolute; margin-bottom:0px; cursor: pointer; margin-top:0.5em" class="">Choose file (No file chosen)</div>').css({opacity:0}).change(function() { 32 $(this).prev().text("Choose file ("+($(this).val().substring($(this).val().lastIndexOf("\\")+1)||"No file chosen")+")"); 33 }); 34 $("#enter").click(function() { 35 if ($("#input").val()!="") { 36 $("#input").val($("#input").val().replace(/"/g,"\\\"").replace(/\\/g,"\\")); 37 $("#output").attr("title",""); 38 userFunctions.say($("#input").val()); 39 aiFunctions.say(ais[currentAI].reactTo($("#input").val())); 40 } 41 $("#input").val(""); 42 }); 43 $("#input").bind("keypress",function(event) { 44 if (event.keyCode==13) $("#enter").click(); 45 }); 46 });