Skip to content
Snippets Groups Projects
Unverified Commit b1e941c4 authored by Tom Robinson's avatar Tom Robinson
Browse files

Remove embed script

parent 8d4d9aab
No related merge requests found
(function() {
var scriptUrl;
try {
throw new Error();
} catch (e) {
scriptUrl = e.stack.match(
/https?:\/\/[\w_-]+(\.[\w_-]+)*(\:\d+)?\/[^:\s]+\.js/
)[0];
}
var scripts = document.getElementsByTagName("script");
var script;
for (var i = scripts.length - 1; i >= 0; i--) {
if (scripts[i].src === scriptUrl) {
script = scripts[i];
break;
}
}
var iframeAttrsMap = {
width: "800",
height: "600",
frameborder: "0",
allowtransparency: "allowtransparency"
};
var hashParamsMap = {};
if (script) {
for (var name in script.dataset) {
if (name in iframeAttrsMap) {
iframeAttrsMap[name] = script.dataset[name];
} else {
hashParamsMap[name] = script.dataset[name];
}
}
}
var hashParamsStr = Object.keys(hashParamsMap)
.map(function(name) {
return name + "=" + hashParamsMap[name];
})
.join("&");
iframeAttrsMap["src"] = scriptUrl.replace(/\.js$/, "") + (hashParamsStr ? "#" + hashParamsStr : "");
iframeAttrsMap["onload"] = "iFrameResize({}, this)";
var iframeAttrs = Object.keys(iframeAttrsMap)
.map(function(name) {
return name + "=" + JSON.stringify(iframeAttrsMap[name]);
})
.join(" ");
if (!window.iFrameResize) {
document.write(
'<script src="node_modules/iframe-resizer/js/iframeResizer.js" charset="utf-8"></script>'
);
}
console.log("iframeAttrs", iframeAttrs)
document.write('<iframe ' + iframeAttrs + '></iframe>');
})();
......@@ -32,21 +32,14 @@
(def ^:private public (partial entrypoint "public" :embeddable))
(def ^:private embed (partial entrypoint "embed" :embeddable))
(defn- embed-script []
(-> (load-file "frontend_client/embed_script.js")
resp/response
(resp/content-type "application/javascript; charset=utf-8")))
(defroutes ^:private public-routes
(GET ["/question/:uuid.csv" :uuid u/uuid-regex] [uuid] (resp/redirect (format "/api/public/card/%s/query/csv" uuid)))
(GET ["/question/:uuid.json" :uuid u/uuid-regex] [uuid] (resp/redirect (format "/api/public/card/%s/query/json" uuid)))
(GET "/:type/:uuid.js" [] (embed-script))
(GET "*" [] public))
(defroutes ^:private embed-routes
(GET "/question/:token.csv" [token] (resp/redirect (format "/api/embed/card/%s/query/csv" token)))
(GET "/question/:token.json" [token] (resp/redirect (format "/api/embed/card/%s/query/json" token)))
(GET "/:type/:uuid.js" [] (embed-script))
(GET "*" [] embed))
;; Redirect naughty users who try to visit a page other than setup if setup is not yet complete
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment