123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- var builder;
-
- function openlink(menuitem){
- var menu = { name: menuitem };
- $.ajax({
- type: "PUT",
- url: window.name,
- contentType: "application/json",
- data: JSON.stringify(menu),
- success: function (data) {
-
- }
- });
- }
- //https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
- function validURL(str) {
- var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
- '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
- '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
- '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
- return !!pattern.test(str);
- }
- function convertLinks(){
- $("#form a").each(function() {
- if(!validURL($(this).attr('href'))){
- $(this).attr('href', "javascript:openlink('" + $(this).attr('href') + "');")
- }
- })
-
- }
- $(document).ready(function(){
-
-
- var formElement = document.getElementById('form');
- var subJSON = document.getElementById('submission');
- var onForm = function(form) {
- subJSON.appendChild(document.createTextNode(JSON.stringify(form.submission, null, 4)));
- convertLinks();
-
- form.on('change', function() {
- subJSON.innerHTML = '';
- subJSON.appendChild(document.createTextNode(JSON.stringify(form.submission, null, 4)));
- });
- };
-
- $.ajax({
- type: "GET",
- url: (window.location.href + "/json").replace(/([^:]\/)\/+/g, "$1"),
- dataType: "json",
- success: function(json) {
- var builder = new Formio.FormBuilder(document.getElementById("builder"), json);
- Formio.createForm(formElement, builder.instance.form).then(onForm);
-
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
- });
|