Advertisement
Guest User

extension

a guest
Oct 20th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. var scope = this;
  2.  
  3. // Get the URL of the page where we load the iFrame
  4. scope.websiteSourceURL = encodeURIComponent(window.parent.location);
  5.  
  6. // Create an HTML div
  7. var div = document.createElement("div");
  8.  
  9. div.innerHTML = '<iframe id="elementID" src="<BUBBLEAPPURL>' width="225px" height="58px" frameBorder="0" scrolling="no" style="position:fixed;bottom:2%;left:2%;z-index:999999999999999;"></iframe>';
  10.  
  11. scope.document.body.appendChild(div);
  12.  
  13. window.addEventListener('message', (event) => {
  14.  
  15. console.log("artnftmint widget: postMessage called");
  16.  
  17. if (event.origin != '<ORGINURL>') { return; }
  18.  
  19. console.log("artnftmint Widget: postMessage's origin validated, OK.");
  20.  
  21. if (event.data.WorkflowAPICall) {
  22. var workflowCall = JSON.parse(event.data.WorkflowAPICall);
  23.  
  24. let _data71linesBookACall = {
  25. 'email': workflowCall.body.email,
  26. "date": workflowCall.body.date
  27. }
  28.  
  29. fetch('<APIWORKFLOWCALLBACKURL>', {
  30. method: "POST",
  31. body: JSON.stringify(BODYOFCALL),
  32. headers: {"Content-type": "application/json; charset=UTF-8",
  33. "Authorization": workflowCall.token}
  34. })
  35. .then(response => {
  36. if (response.ok) {
  37. response.json().then(function (json) {
  38.  
  39. var iframe = document.getElementById("ELEMENTID");
  40. var iframeWindow = (iframe.contentWindow || iframe.contentDocument);
  41.  
  42. iframeWindow.postMessage(
  43. {"newAppointmentCreated": json.response.appointmentUniqeId }, "https://figmaimportui.bubbleapps.io");
  44.  
  45. console.log("artnftmint Widget: postMessage called on iframeWindow");
  46.  
  47. });
  48.  
  49. }}).catch(error => console.log("artnftmint Error"))}
  50.  
  51. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement