MCPcopy Create free account
hub / github.com/BloombergGraphics/whatiscode / robot

Function robot

scripts/bot.js:20–54  ·  view source on GitHub ↗
(selection)

Source from the content-addressed store, hash-verified

18 attachment;
19
20 function robot(selection) {
21
22 sel = selection;
23 sel.classed("bot", true);
24 if(botName) sel.attr("id", botName);
25 face = sel.append("div").classed("face", true);
26 body = sel.append("div").classed("body", true);
27 messages = body.append("div").classed("messages", true);
28 dialogueStep = messages.append("div.step");
29 learninalSel = body.append("div").classed("learninal", true);
30
31 learninal = new Sandbox.View({
32 el: learninalSel[0],
33 model: new Sandbox.Model(),
34 placeholder: "Write code, hit 'Enter'"
35 });
36
37 // Listen to dispatcher
38 learninal.model.dispatcher.on("evaluate", function(item) {
39
40 var msg = dialogueStep.append("div").classed("message", true).classed("eval", true).classed(item._class, true);
41 var input = msg.append("pre").append("code").classed("javascript", true).classed("input", true).html(learninal.toEscaped(item.command));
42 var output = msg.append("pre").append("code").classed("javascript", true).classed("output", true).html(learninal.toEscaped(item.result));
43 body.node().scrollTop = body.node().scrollHeight;
44
45 hljs.highlightBlock(input.node());
46 hljs.highlightBlock(output.node());
47
48 msg.transition().duration(msgDuration)
49 .attrTween('evalExpand', function(){ return function(t){ msg.style("transform", "scaleY(" + (.001 + t) + ")") } });
50 })
51
52 return robot;
53
54 }
55
56 robot.botName = function(_) {
57 if (!arguments.length) return botName;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected