-
-
Save victorb/1e14233c2ea6f8fcfe55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="form_here"></div> | |
<script id="jsbin-javascript"> | |
console.clear(); | |
function makeCreateFormCall(fields, callback, api_key) { | |
function reqListener () { | |
var response = JSON.parse(this.responseText); | |
var form_link = response.links.form_render.get; | |
callback(form_link, response); | |
} | |
var oReq = new XMLHttpRequest(); | |
oReq.onload = reqListener; | |
oReq.open("POST", "https://api.typeform.io/v0.1/forms", true); | |
oReq.setRequestHeader("X-API-TOKEN", api_key); | |
var form = { | |
title: "Created from Typeform library", | |
fields: fields | |
}; | |
oReq.send(JSON.stringify(form)); | |
} | |
function createIframe(link, element) { | |
ifrm = document.createElement("IFRAME"); | |
ifrm.setAttribute("src", link); | |
ifrm.style.width = 640+"px"; | |
ifrm.style.height = 480+"px"; | |
element.appendChild(ifrm); | |
} | |
var Typeform = function(api_key) { | |
if(api_key === undefined) { | |
throw new Error("You need to provide a API-key as the first argument"); | |
} | |
this.api_key = api_key; | |
}; | |
Typeform.prototype = { | |
createForm: function(selector, fields) { | |
var element = document. querySelector (selector); | |
makeCreateFormCall(fields, function(link) { | |
createIframe(link, element); | |
}, this.api_key); | |
} | |
}; | |
var typeform_instance = new Typeform('8a280cd49ae26a7dd78caa4c13e6460d'); | |
typeform_instance.createForm('#form_here', [ | |
{ | |
type: "yes_no", | |
question: "Hello there" | |
} | |
]); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">console.clear(); | |
function makeCreateFormCall(fields, callback, api_key) { | |
function reqListener () { | |
var response = JSON.parse(this.responseText); | |
var form_link = response.links.form_render.get; | |
callback(form_link, response); | |
} | |
var oReq = new XMLHttpRequest(); | |
oReq.onload = reqListener; | |
oReq.open("POST", "https://api.typeform.io/v0.1/forms", true); | |
oReq.setRequestHeader("X-API-TOKEN", api_key); | |
var form = { | |
title: "Created from Typeform library", | |
fields: fields | |
}; | |
oReq.send(JSON.stringify(form)); | |
} | |
function createIframe(link, element) { | |
ifrm = document.createElement("IFRAME"); | |
ifrm.setAttribute("src", link); | |
ifrm.style.width = 640+"px"; | |
ifrm.style.height = 480+"px"; | |
element.appendChild(ifrm); | |
} | |
var Typeform = function(api_key) { | |
if(api_key === undefined) { | |
throw new Error("You need to provide a API-key as the first argument"); | |
} | |
this.api_key = api_key; | |
}; | |
Typeform.prototype = { | |
createForm: function(selector, fields) { | |
var element = document. querySelector (selector); | |
makeCreateFormCall(fields, function(link) { | |
createIframe(link, element); | |
}, this.api_key); | |
} | |
}; | |
var typeform_instance = new Typeform('8a280cd49ae26a7dd78caa4c13e6460d'); | |
typeform_instance.createForm('#form_here', [ | |
{ | |
type: "yes_no", | |
question: "Hello there" | |
} | |
]);</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear(); | |
function makeCreateFormCall(fields, callback, api_key) { | |
function reqListener () { | |
var response = JSON.parse(this.responseText); | |
var form_link = response.links.form_render.get; | |
callback(form_link, response); | |
} | |
var oReq = new XMLHttpRequest(); | |
oReq.onload = reqListener; | |
oReq.open("POST", "https://api.typeform.io/v0.1/forms", true); | |
oReq.setRequestHeader("X-API-TOKEN", api_key); | |
var form = { | |
title: "Created from Typeform library", | |
fields: fields | |
}; | |
oReq.send(JSON.stringify(form)); | |
} | |
function createIframe(link, element) { | |
ifrm = document.createElement("IFRAME"); | |
ifrm.setAttribute("src", link); | |
ifrm.style.width = 640+"px"; | |
ifrm.style.height = 480+"px"; | |
element.appendChild(ifrm); | |
} | |
var Typeform = function(api_key) { | |
if(api_key === undefined) { | |
throw new Error("You need to provide a API-key as the first argument"); | |
} | |
this.api_key = api_key; | |
}; | |
Typeform.prototype = { | |
createForm: function(selector, fields) { | |
var element = document. querySelector (selector); | |
makeCreateFormCall(fields, function(link) { | |
createIframe(link, element); | |
}, this.api_key); | |
} | |
}; | |
var typeform_instance = new Typeform('8a280cd49ae26a7dd78caa4c13e6460d'); | |
typeform_instance.createForm('#form_here', [ | |
{ | |
type: "yes_no", | |
question: "Hello there" | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment