|
1 | | -'use strict'; |
| 1 | +function injectJotForm() { |
| 2 | + var ifr = document.getElementById("JotFormIFrame"); |
| 3 | + if (window.location.href && window.location.href.indexOf("?") > -1) { |
| 4 | + var get = window.location.href.substr(window.location.href.indexOf("?") + 1); |
| 5 | + if (ifr && get.length > 0) { |
| 6 | + var src = ifr.src; |
| 7 | + src = src.indexOf("?") > -1 ? src + "&" + get : src + "?" + get; |
| 8 | + ifr.src = src; |
| 9 | + } |
| 10 | + } |
| 11 | + window.handleIFrameMessage = function (e) { |
| 12 | + var args = e.data.split(":"); |
| 13 | + |
| 14 | + iframe = document.getElementById("JotFormIFrame"); |
| 15 | + |
| 16 | + if (!iframe) return; |
| 17 | + switch (args[0]) { |
| 18 | + case "scrollIntoView": |
| 19 | + iframe.scrollIntoView(); |
| 20 | + break; |
| 21 | + case "setHeight": |
| 22 | + iframe.style.height = args[1] + "px"; |
| 23 | + break; |
| 24 | + case "collapseErrorPage": |
| 25 | + if (iframe.clientHeight > window.innerHeight) { |
| 26 | + iframe.style.height = window.innerHeight + "px"; |
| 27 | + } |
| 28 | + break; |
| 29 | + case "reloadPage": |
| 30 | + window.location.reload(); |
| 31 | + break; |
| 32 | + } |
| 33 | + var isJotForm = (e.origin.indexOf("jotform") > -1) ? true : false; |
| 34 | + if (isJotForm && "contentWindow" in iframe && "postMessage" in iframe.contentWindow) { |
| 35 | + var urls = {"docurl": encodeURIComponent(document.URL), "referrer": encodeURIComponent(document.referrer)}; |
| 36 | + iframe.contentWindow.postMessage(JSON.stringify({"type": "urls", "value": urls}), "*"); |
| 37 | + } |
| 38 | + }; |
| 39 | + if (window.addEventListener) { |
| 40 | + window.addEventListener("message", handleIFrameMessage, false); |
| 41 | + } else if (window.attachEvent) { |
| 42 | + window.attachEvent("onmessage", handleIFrameMessage); |
| 43 | + } |
| 44 | +} |
| 45 | + |
2 | 46 |
|
3 | 47 | (function (angular) { |
4 | 48 | angular.module('jotFormPluginWidget', ['ui.bootstrap']) |
|
22 | 66 | var dummyData = {url: "https://form.jotform.me/60070086181448"}; |
23 | 67 | WidgetHome.data.content.url = dummyData.url; |
24 | 68 | } |
| 69 | + injectJotForm(); |
25 | 70 | }; |
26 | 71 | WidgetHome.error = function (err) { |
27 | 72 | if (err && err.code !== STATUS_CODE.NOT_FOUND) { |
|
0 commit comments