Skip to content

Commit

Permalink
Formatting and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitri committed Apr 21, 2017
1 parent e74cf7c commit 3ff5ad5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 14 additions & 3 deletions component/Bubbles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ function Bubbles(container, self, options) {
typeSpeed = options.typeSpeed || 5; // delay per character, to simulate the machine "typing"
widerBy = options.widerBy || 2; // add a little extra width to bubbles to make sure they don't break
sidePadding = options.sidePadding || 6; // padding on both sides of chat bubbles
inputCallbackFn = options.inputCallbackFn || (function(o){ console.log(o); }); // should we display an input field?
inputCallbackFn = options.inputCallbackFn || (function(o){ return false }); // should we display an input field?

var standingAnswer = "ice"; // remember where to restart convo if interrupted



// set up the stage
container.classList.add("bubble-container");
var bubbleWrap = document.createElement("div");
Expand Down Expand Up @@ -44,6 +46,8 @@ function Bubbles(container, self, options) {
}
inputCallbackFn ? this.typeInput(inputCallbackFn) : false;



// init typing bubble
var bubbleTyping = document.createElement("div");
bubbleTyping.className = "bubble-typing imagine";
Expand Down Expand Up @@ -108,6 +112,8 @@ function Bubbles(container, self, options) {
start();
}



// create a bubble
var bubbleQueue = false;
var addBubble = function(say, posted, reply){
Expand All @@ -123,7 +129,10 @@ function Bubbles(container, self, options) {
// answer picker styles
if(reply !== ""){
var bubbleButtons = bubbleContent.querySelectorAll(".bubble-button");
bubbleButtons.forEach(function(el){ el.style.width = el.offsetWidth - sidePadding * 2 + widerBy + "px"; });
bubbleButtons.forEach(function(el){
if(!el.parentNode.parentNode.classList.contains("reply-freeform"))
el.style.width = el.offsetWidth - sidePadding * 2 + widerBy + "px";
});
bubble.addEventListener("click", function(){
bubbleButtons.forEach(function(el){
el.style.width = 0 + "px";
Expand Down Expand Up @@ -166,4 +175,6 @@ function Bubbles(container, self, options) {
}, wait + animationTime * 2);
}

}


} // close function
12 changes: 6 additions & 6 deletions component/start-here/hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,14 @@
<script>
var givemeBubbles = new Bubbles(document.getElementById("chat"), "givemeBubbles", {
inputCallbackFn: function(o){

console.log(o);


// do this if no answer matched
var miss = function(){
givemeBubbles.talk({
"ice": {
"says":
[
"WTF are you talking about?",
"Sorry, I don't get it 😕. Pls repeat? Or you can just click below 👇",
],
"reply" : o.convo[o.standingAnswer].reply
},
Expand All @@ -343,7 +341,6 @@

// do this if answer found
var match = function(key){
console.log(key);
givemeBubbles.talk(convo, key); // restart current convo from point found in the answer
}

Expand All @@ -353,11 +350,14 @@
}

// search function
var found = false;
o.convo[o.standingAnswer].reply.forEach(function(e, i) {
(strip(e.question).includes(strip(o.input)) && o.input.length > 0) ? found = e.answer : found = false;
(strip(e.question).includes(strip(o.input)) && o.input.length > 0) ? found = e.answer : found ? null : found = false;
});
found ? match(found) : miss();



}
});
givemeBubbles.talk(convo);
Expand Down

0 comments on commit 3ff5ad5

Please sign in to comment.