extend.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <head>
  3. <title>ChatUI</title>
  4. <meta charset="utf-8">
  5. <link rel="stylesheet" href="../build/chatUI.css">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8. html, body{
  9. margin:0;
  10. padding:0;
  11. border:0;
  12. }
  13. #chatbot{
  14. width:100%;
  15. height: 100vh;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="chatbot">
  21. </div>
  22. <script src="https://d3js.org/d3.v4.min.js"></script>
  23. <script src="../build/index-d3.min.js"></script>
  24. <script type="text/javascript">
  25. var chat = chatUI(d3.select('#chatbot'));
  26. //New bubble type
  27. chat.types.image = function(bubble, options, callback){
  28. bubble.append('div')
  29. .attr('class', 'cb-waiting')
  30. .html('<div class="circle"></div><div class="circle"></div><div class="circle"></div>');
  31. var image = new Image();
  32. image.src = options.value;
  33. image.addEventListener('load', function(){
  34. bubble.select(".cb-waiting").remove();
  35. options.value = '<img src="' + options.value + '" />';
  36. //This is a helper function for simply adding a paragrah with text/html
  37. chat.appendText(bubble, options, callback);
  38. }, false);
  39. };
  40. chat.addBubble({ type: 'text', value: 'Let me show you my Logo...', class: 'bot', delay: 1000 }, function () {
  41. chat.addBubble({ type: 'image', value: 'https://github.com/svift-org/ChatUI/blob/master/README/ChatUI-Logo.png?raw=true', class: 'bot', delay: 1000 });
  42. });
  43. </script>
  44. </body>
  45. </html>