Skip to content

Instantly share code, notes, and snippets.

@Fedenieto90
Created April 3, 2019 13:34
Show Gist options
  • Save Fedenieto90/f1ad24e293361302a09b77c56e6ab435 to your computer and use it in GitHub Desktop.
Save Fedenieto90/f1ad24e293361302a09b77c56e6ab435 to your computer and use it in GitHub Desktop.
import UIKit
class TypeFormHelper: NSObject {
struct Constants {
static let typeFormUrl = "yourTypeformUrl"
static let formSubmissionHandler = "formSubmitted"
static let TypeForm = "TypeForm"
static let html = "html"
}
static func getTypeFormScript(urlString: String, messageHandlerName: String) -> String {
return """
const embedElement = document.querySelector('iframe') // NOTE: `.target-dom-node` is the target DOM element from your website or web app
typeformEmbed.makeWidget(
embedElement,
'\(urlString)', // NOTE: Replace with your typeform URL
{
hideHeaders: true,
hideFooter: true,
opacity: 75,
onSubmit: function () {
window.webkit.messageHandlers.\(messageHandlerName).postMessage("Form Submitted");
}
}
)
"""
}
static func getTypeFormHtml() -> String? {
let htmlFile = Bundle.main.path(forResource: Constants.TypeForm, ofType: Constants.html)
let html = try? String(contentsOfFile: htmlFile!, encoding: String.Encoding.utf8)
return html
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment