You are here

tawk-to-iframe.html.twig in Tawk.to - Live chat application (Drupal 8) 8.2

Same filename and directory in other branches
  1. 8 templates/tawk-to-iframe.html.twig
{% autoescape false %}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<iframe id="tawkIframe" src="" style="min-height: 400px; width : 100%; border: none">
</iframe>

<script type="text/javascript">
  var currentHost = window.location.protocol + "//" + window.location.host;
  var url = "{{ items.iframeUrl }}&parentDomain=" + currentHost;

  jQuery("#tawkIframe").attr("src", url);

  var iframe = jQuery("#tawk_widget_customization")[0];

  window.addEventListener("message", function (e) {
    if (e.origin === "{{ items.baseUrl }}") {

      if (e.data.action === "setWidget") {
        setWidget(e);
      }

      if (e.data.action === "removeWidget") {
        removeWidget(e);
      }
    }
  });

  function setWidget(e) {
    jQuery.post("{{ path('tawk_to.set_widget') }}", {
      pageId: e.data.pageId,
      widgetId: e.data.widgetId
    }, function (r) {
      if (r.success) {
        e.source.postMessage({action: "setDone"}, "{{ items.baseUrl }}");
      } else {
        e.source.postMessage({action: "setFail"}, "{{ items.baseUrl }}");
      }
    });
  }

  function removeWidget(e) {
    jQuery.post("{{ path('tawk_to.remove_widget') }}", function (r) {
      if (r.success) {
        e.source.postMessage({action: "removeDone"}, "{{ items.baseUrl }}");
      } else {
        e.source.postMessage({action: "removeFail"}, "{{ items.baseUrl }}");
      }
    });
  }
</script>
{% endautoescape %}

File

templates/tawk-to-iframe.html.twig
View source
  1. {% autoescape false %}
  2. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  3. <iframe id="tawkIframe" src="" style="min-height: 400px; width : 100%; border: none">
  4. </iframe>
  5. <script type="text/javascript">
  6. var currentHost = window.location.protocol + "//" + window.location.host;
  7. var url = "{{ items.iframeUrl }}&parentDomain=" + currentHost;
  8. jQuery("#tawkIframe").attr("src", url);
  9. var iframe = jQuery("#tawk_widget_customization")[0];
  10. window.addEventListener("message", function (e) {
  11. if (e.origin === "{{ items.baseUrl }}") {
  12. if (e.data.action === "setWidget") {
  13. setWidget(e);
  14. }
  15. if (e.data.action === "removeWidget") {
  16. removeWidget(e);
  17. }
  18. }
  19. });
  20. function setWidget(e) {
  21. jQuery.post("{{ path('tawk_to.set_widget') }}", {
  22. pageId: e.data.pageId,
  23. widgetId: e.data.widgetId
  24. }, function (r) {
  25. if (r.success) {
  26. e.source.postMessage({action: "setDone"}, "{{ items.baseUrl }}");
  27. } else {
  28. e.source.postMessage({action: "setFail"}, "{{ items.baseUrl }}");
  29. }
  30. });
  31. }
  32. function removeWidget(e) {
  33. jQuery.post("{{ path('tawk_to.remove_widget') }}", function (r) {
  34. if (r.success) {
  35. e.source.postMessage({action: "removeDone"}, "{{ items.baseUrl }}");
  36. } else {
  37. e.source.postMessage({action: "removeFail"}, "{{ items.baseUrl }}");
  38. }
  39. });
  40. }
  41. </script>
  42. {% endautoescape %}