tawk-to-iframe.html.twig in Tawk.to - Live chat application (Drupal 8) 8.2
{% 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
- {% 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 %}