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

Function bot

scripts/bot.js:3–405  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1'use strict';
2
3function bot() {
4
5 var msgDuration = 500;
6
7 var sel,
8 botName = "",
9 mode = "on",
10 face,
11 body,
12 messages,
13 learninal,
14 learninalSel,
15 pendingDialogue,
16 dialogueStep,
17 visible,
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;
58 botName = _;
59 return robot;
60 };

Callers 12

languages.jsFile · 0.85
grabbag.jsFile · 0.85
paperclip.jsFile · 0.85
paulbot.jsFile · 0.85
debug.jsFile · 0.85
learninal.jsFile · 0.85
shoppingcart.jsFile · 0.85
mouse.jsFile · 0.85
circuit.jsFile · 0.85
tree.jsFile · 0.85
keyboard.jsFile · 0.85
crapplets.jsFile · 0.85

Calls 1

isVisibleFunction · 0.85

Tested by

no test coverage detected