-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proof of concept for remote inclusion
remote.html goes into other website that you want to pull Formulize content into
- Loading branch information
1 parent
6c3bcfa
commit 9112108
Showing
5 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Formulize remote include test</title> | ||
<script id='formulize.remote.js' src='https://julian.formulize.net/remote.js'></script> | ||
</head> | ||
|
||
<body> | ||
|
||
<div id='formulize'></div> | ||
|
||
<script> | ||
window.onload = function() { | ||
formulize_remoteRenderScreen(2, 'formulize'); | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Formulize remote include javascript library | ||
* Copyright the Formulize Project 2023 | ||
*/ | ||
|
||
var formulize = {url:''}; | ||
formulize.url = document.getElementById('formulize.remote.js').getAttribute('src').replace('/remote.js', ''); | ||
if (formulize.url == '') { | ||
console.log('Formulize Remote Error: could not determine url for your Formulize instance. Check that the <script> tag that includes the remote.js file has the id "formulize.remote.js".'); | ||
} | ||
|
||
if(typeof window.jQuery == 'undefined') { | ||
var dochead = document.getElementsByTagName('head')[0]; | ||
const formulize_jQueryScript = document.createElement('script'); | ||
formulize_jQueryScript.src = 'https://code.jquery.com/jquery-1.12.4.js'; | ||
formulize_jQueryScript.crossorigin = 'anonymous'; | ||
dochead.appendChild(formulize_jQueryScript); | ||
const formulize_jQueryUIScript = document.createElement('script'); | ||
formulize_jQueryUIScript.src = 'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js'; | ||
formulize_jQueryUIScript.crossorigin = 'anonymous'; | ||
dochead.appendChild(formulize_jQueryUIScript); | ||
/*const formulize_styles = document.createElement('style'); | ||
var css = '@font-face { font-family: "formulize-icons"; src: url("'+formulize.url+'/modules/formulize/templates/css/formulize-icons/formulize-icons.eot"); src: url("'+formulize.url+'/modules/formulize/templates/css/formulize-icons/formulize-icons.eot?#iefix") format("embedded-opentype"), url("'+formulize.url+'/modules/formulize/templates/css/formulize-icons/formulize-icons.woff") format("woff"), url("'+formulize.url+'/modules/formulize/templates/css/formulize-icons/formulize-icons.ttf") format("truetype"), url("'+formulize.url+'/modules/formulize/templates/css/formulize-icons/formulize-icons.svg#formulize-icons") format("svg"); font-weight: normal; font-style: normal; }'; | ||
formulize_styles.appendChild(document.createTextNode(css)); | ||
dochead.appendChild(formulize_styles);*/ | ||
const formulize_moduleCSS = document.createElement('link'); | ||
formulize_moduleCSS.rel = 'stylesheet'; | ||
formulize_moduleCSS.href = formulize.url+'/modules/formulize/templates/css/formulize.css'; | ||
formulize_moduleCSS.type = 'text/css'; | ||
dochead.appendChild(formulize_moduleCSS); | ||
const formulize_themeCSS = document.createElement('link'); | ||
formulize_themeCSS.rel = 'stylesheet'; | ||
formulize_themeCSS.href = formulize.url+'/themes/Anari/css/style.css'; | ||
formulize_themeCSS.type = 'text/css'; | ||
dochead.appendChild(formulize_themeCSS); | ||
|
||
} | ||
|
||
var lastLoadedScreenId = 0; | ||
var lastUsedDomTarget = ''; | ||
function formulize_remoteRenderScreen(screen_id, dom_id, formData='') { | ||
lastLoadedScreenId = parseInt(screen_id); | ||
lastUsedDomTarget = dom_id; | ||
jQuery.ajax({ | ||
type: "POST", | ||
data: formData, | ||
url: formulize.url+'/modules/formulize/index.php?sid='+screen_id, | ||
headers: { 'formulize-remote-include': 1 }, | ||
success: function(html) { | ||
jQuery('#'+dom_id).empty(); | ||
jQuery('#'+dom_id).append(html).ready(function() { | ||
jQuery('body').show(200, function() { | ||
jQuery('.formulizeThemeForm').each(function() { | ||
jQuery(this).show(); | ||
}); | ||
jQuery(window).keydown(function(event){ | ||
if(event.keyCode == 13) { | ||
event.preventDefault(); | ||
formulize_remoteSubmitList(); | ||
} | ||
return true; | ||
}); | ||
var formulize_pageShown = new CustomEvent('formulize_pageShown'); | ||
window.dispatchEvent(formulize_pageShown); | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function formulize_remoteSubmitList() { | ||
formulize_remoteRenderScreen(lastLoadedScreenId, lastUsedDomTarget, jQuery('#controls').serialize()); | ||
} | ||
|
||
function formulize_remoteSubmitForm() { | ||
formulize_remoteRenderScreen(lastLoadedScreenId, lastUsedDomTarget, jQuery('#formulize_mainform').serialize()); | ||
} |