Browse files

Moving actual source files into src directory, adding grunt. For now,…

… it's only to provide a minified version of the js. bug 11:resolved
  • Loading branch information...
1 parent 104da34 commit 85d3ba51cf6c325c2401c14960a7cc1dae905c87 @viveleroi committed Feb 12, 2014
View
1 .gitignore
@@ -1,3 +1,4 @@
+node_modules
.DS_Store
*.tmproj
nbproject
View
29 Gruntfile.js
@@ -0,0 +1,29 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ uglify: {
+ options: {
+ banner: '/*! <%= pkg.name %> */\n'
+ },
+ dist: {
+ files: {
+ 'src/js/jquery.formbuilder.min.js': ['src/js/*.js']
+ }
+ }
+ },
+ jshint: {
+ all: ['Gruntfile.js','src/js/*.js']
+ }
+ });
+
+ // grunt.loadNpmTasks('grunt-contrib-cssmin');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+
+ // Default task(s).
+ grunt.registerTask('default', ['uglify']);
+ // @todo jshint temp disabled. I'd really like to rewrite this
+
+};
View
18 package.json
@@ -0,0 +1,18 @@
+{
+ "name": "jQuery.formbuilder",
+ "version": "0.5.0",
+ "devDependencies": {
+ "grunt": "~0.4.2",
+ "grunt-contrib-jshint": "~0.8.0",
+ "grunt-contrib-uglify": "~0.2.2"
+ },
+ "main": "Gruntfile.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git@github.com:botskonet/jquery.formbuilder.git"
+ },
+ "author": "viveleroi"
+}
View
0 Formbuilder/Formbuilder.php → src/Formbuilder/Formbuilder.php
File renamed without changes.
View
0 Formbuilder/Formbuilder_pdo.php → src/Formbuilder/Formbuilder_pdo.php
File renamed without changes.
View
0 Formbuilder/sql/mysql.sql → src/Formbuilder/sql/mysql.sql
File renamed without changes.
View
0 css/jquery.formbuilder.css → src/css/jquery.formbuilder.css
File renamed without changes.
View
0 example-html.php → src/example-html.php
File renamed without changes.
View
0 example-json.php → src/example-json.php
File renamed without changes.
View
0 example-save.php → src/example-save.php
File renamed without changes.
View
0 example-submit.php → src/example-submit.php
File renamed without changes.
View
0 fake-form-db-vals.php → src/fake-form-db-vals.php
File renamed without changes.
View
0 index.html → src/index.html
File renamed without changes.
View
0 js/jquery.formbuilder.js → src/js/jquery.formbuilder.js
File renamed without changes.
View
2 src/js/jquery.formbuilder.min.js
@@ -0,0 +1,2 @@
+/*! jQuery.formbuilder */
+!function(a){a.fn.formbuilder=function(b){var c={save_url:!1,load_url:!1,control_box_target:!1,serialize_prefix:"frmb",css_ol_sortable_class:"ol_opt_sortable",messages:{save:"Save",add_new_field:"Add New Field...",text:"Text Field",title:"Title",paragraph:"Paragraph",checkboxes:"Checkboxes",radio:"Radio",select:"Select List",text_field:"Text Field",label:"Label",paragraph_field:"Paragraph Field",select_options:"Select Options",add:"Add",checkbox_group:"Checkbox Group",remove_message:"Are you sure you want to remove this element?",remove:"Remove",radio_group:"Radio Group",selections_message:"Allow Multiple Selections",hide:"Hide",required:"Required",show:"Show"},loaded:function(){},saving:function(){},saved:function(){}},d=a.extend(c,b),e="frmb-"+a("ul[id^=frmb-]").length++;return this.each(function(){var b,c,f=a(this).append('<ul id="'+e+'" class="frmb"></ul>').find("ul").sortable(),g="",h="",j=1;if(f.addClass(e),d.load_url)a.getJSON(d.load_url,function(a){c=a.form_id,l(a.form_structure),d.loaded(a);k(d.control_box_target)});else{k(d.control_box_target)}var k=function(b){var c="",g="",h="",i=e+"-control-box",k=e+"-save-button";c+='<option value="0" disabled selected>'+d.messages.add_new_field+"</option>",c+='<option value="input_text">'+d.messages.text+"</option>",c+='<option value="textarea">'+d.messages.paragraph+"</option>",c+='<option value="checkbox">'+d.messages.checkboxes+"</option>",c+='<option value="radio">'+d.messages.radio+"</option>",c+='<option value="select">'+d.messages.select+"</option>",g='<select id="'+i+'" class="frmb-control form-control">'+c+"</select>",h='<button type="submit" id="'+k+'" class="frmb-submit btn btn-primary">'+d.messages.save+"</button>",b?a(b).append(g):a(f).before(g),a(f).after(h),a("#"+k).click(function(){return d.saving.call(this),w.call(this),!1}),a("#"+i).change(function(){return m(a(this).val()),a(this).val(0).blur(),a("html, body").animate({scrollTop:a("#frm-"+(j-1)+"-item").offset().top},500),!1})},l=function(b){var c="",d=!1;a(b).each(function(){"checkbox"===this.cssClass?(d=[this.title],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):"radio"===this.cssClass?(d=[this.title],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):"select"===this.cssClass?(d=[this.title,this.multiple],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):c=[this.values],m(this.cssClass,c,d,this.required)})},m=function(a,b,c,d){switch(g="",h=a,"undefined"==typeof b&&(b=""),a){case"input_text":n(b,d);break;case"textarea":o(b,d);break;case"checkbox":p(b,c,d);break;case"radio":r(b,c,d);break;case"select":t(b,c,d)}},n=function(a,c){g+="<label>"+d.messages.label+"</label>",g+='<input class="fld-title form-control" id="title-'+j+'" type="text" value="'+a+'" />',b="",v(d.messages.text,g,c,b)},o=function(a,c){g+="<label>"+d.messages.label+"</label>",g+='<input type="text" class="form-control" value="'+a+'" />',b="",v(d.messages.paragraph_field,g,c,b)},p=function(c,e,f){var h="";if("object"==typeof e&&(h=e[0]),g+='<div class="chk_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" name="title" class="form-control" value="'+h+'" /></div>',g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=q(c[i]);else g+=q("");g+='<li class="add-area"><a href="#" class="add add_ck">'+d.messages.add+"</a></li>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.checkbox_group,g,f,b),a("."+d.css_ol_sortable_class).sortable()},q=function(a){var b=!1,c="";return"object"==typeof a&&(c=a[0],b="false"===a[1]||"undefined"===a[1]?!1:!0),g="<li>",g+="<div>",g+='<input type="checkbox"'+(b?' checked="checked"':"")+" />",g+='<input type="text" class="form-control" value="'+c+'" />',g+='<a href="#" class="remove" title="'+d.messages.remove_message+'">'+d.messages.remove+"</a>",g+="</div></li>"},r=function(c,e,f){var h="";if("object"==typeof e&&(h=e[0]),g+='<div class="rd_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" class="form-control" name="title" value="'+h+'" /></div>',g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=s(c[i],"frm-"+j+"-fld");else g+=s("","frm-"+j+"-fld");g+='<div class="add-area"><a href="#" class="add add_rd">'+d.messages.add+"</a></div>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.radio_group,g,f,b),a("."+d.css_ol_sortable_class).sortable()},s=function(a,b){var c=!1,e="";return"object"==typeof a&&(e=a[0],c="false"===a[1]||"undefined"===a[1]?!1:!0),g="<li>",g+="<div>",g+='<input type="radio"'+(c?' checked="checked"':"")+' name="radio_'+b+'" />',g+='<input type="text" class="form-control" value="'+e+'" />',g+='<a href="#" class="remove" title="'+d.messages.remove_message+'">'+d.messages.remove+"</a>",g+="</div></li>"},t=function(c,e,f){var h=!1,j="";if("object"==typeof e&&(j=e[0],h="true"===e[1]||"checked"===e[1]?!0:!1),g+='<div class="opt_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" class="form-control" name="title" value="'+j+'" /></div>',g+="",g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<input type="checkbox" name="multiple"'+(h?'checked="checked"':"")+">",g+='<label class="auto">'+d.messages.selections_message+"</label>",g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=u(c[i],h);else g+=u("",h);g+='<div class="add-area"><a href="#" class="add add_opt">'+d.messages.add+"</a></div>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.select,g,f,b),a("."+d.css_ol_sortable_class).sortable()},u=function(a,b){return b?q(a):s(a)},v=function(b,c,e){e&&(e="true"===e?!0:!1);var i="";i+='<li id="frm-'+j+'-item" class="'+h+'">',i+='<div class="legend">',i+='<a id="frm-'+j+'" class="toggle-form" href="#">'+d.messages.hide+"</a> ",i+='<a id="del_'+j+'" class="del-button delete-confirm" href="#" title="'+d.messages.remove_message+'"><span>'+d.messages.remove+"</span></a>",i+='<strong id="txt-title-'+j+'">'+b+"</strong></div>",i+='<div id="frm-'+j+'-fld" class="frm-holder">',i+='<div class="frm-elements">',i+='<div class="frm-fld"><label for="required-'+j+'">'+d.messages.required+"</label>",i+='<input class="required" type="checkbox" value="1" name="required-'+j+'" id="required-'+j+'"'+(e?' checked="checked"':"")+" /></div>",i+=g,i+="</div>",i+="</div>",i+="</li>",a(f).append(i),a("#frm-"+j+"-item").hide(),a("#frm-"+j+"-item").animate({opacity:"show",height:"show"},"slow"),j++};f.on("click",".remove",function(b){return b.preventDefault(),a(this).parents("li:eq(0)").animate({opacity:"hide",height:"hide",marginBottom:"0px"},"fast",function(){a(this).remove()}),!1}),f.on("click",".toggle-form",function(b){b.preventDefault();var c=a(this).parents("li:eq(0)").find(".frm-holder");return c.is(":visible")?(a(this).removeClass("open").addClass("closed").html(d.messages.show),c.animate({opacity:"hide",height:"hide"},"slow")):(a(this).removeClass("closed").addClass("open").html(d.messages.hide),c.animate({opacity:"show",height:"show"},"slow")),!1}),f.on("click",".delete-confirm",function(b){return b.preventDefault(),confirm(a(this).attr("title"))&&a(this).parents("li:eq(0)").animate({opacity:"hide",height:"hide",marginBottom:"0px"},"slow",function(){a(this).remove()}),!1}),f.on("click",".add_ck",function(b){return b.preventDefault(),a(this).parent().before(q()),!1}),f.on("click",".add_opt",function(b){return b.preventDefault(),a(this).parent().before(u("",!1)),!1}),f.on("click",".add_rd",function(b){return b.preventDefault(),a(this).parent().before(s(!1,a(this).parents(".frm-holder").attr("id"))),!1});var w=function(){var b=this;d.save_url&&a.ajax({type:"POST",url:d.save_url,data:a(f).serializeFormList({prepend:d.serialize_prefix})+"&form_id="+c,success:function(){d.saved.call(b)}})}})}}(jQuery),function(a){a.fn.serializeFormList=function(b){var c={prepend:"ul",is_child:!1,attributes:["class"]},d=a.extend(c,b);d.is_child||(d.prepend="&"+d.prepend);var e="";return this.each(function(){var b=0,c=1;a(this).children().each(function(){for(att=0;att<d.attributes.length;att++){var f="class"===d.attributes[att]?"cssClass":d.attributes[att];if(e+=d.prepend+"["+b+"]["+f+"]="+encodeURIComponent(a(this).attr(d.attributes[att])),"class"===d.attributes[att])switch(e+=d.prepend+"["+b+"][required]="+encodeURIComponent(a("#"+a(this).attr("id")+" input.required").is(":checked")),a(this).attr(d.attributes[att])){case"input_text":e+=d.prepend+"["+b+"][values]="+encodeURIComponent(a("#"+a(this).attr("id")+" input[type=text]").val());break;case"textarea":e+=d.prepend+"["+b+"][values]="+encodeURIComponent(a("#"+a(this).attr("id")+" input[type=text]").val());break;case"checkbox":c=1,a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++});break;case"radio":c=1,a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++});break;case"select":c=1,e+=d.prepend+"["+b+"][multiple]="+a("#"+a(this).attr("id")+" input[name=multiple]").is(":checked"),a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++})}}b++})}),e}}(jQuery),!function(a){a.fn.formbuilder=function(b){var c={save_url:!1,load_url:!1,control_box_target:!1,serialize_prefix:"frmb",css_ol_sortable_class:"ol_opt_sortable",messages:{save:"Save",add_new_field:"Add New Field...",text:"Text Field",title:"Title",paragraph:"Paragraph",checkboxes:"Checkboxes",radio:"Radio",select:"Select List",text_field:"Text Field",label:"Label",paragraph_field:"Paragraph Field",select_options:"Select Options",add:"Add",checkbox_group:"Checkbox Group",remove_message:"Are you sure you want to remove this element?",remove:"Remove",radio_group:"Radio Group",selections_message:"Allow Multiple Selections",hide:"Hide",required:"Required",show:"Show"},loaded:function(){},saving:function(){},saved:function(){}},d=a.extend(c,b),e="frmb-"+a("ul[id^=frmb-]").length++;return this.each(function(){var b,c,f=a(this).append('<ul id="'+e+'" class="frmb"></ul>').find("ul").sortable(),g="",h="",j=1;f.addClass(e),d.load_url?a.getJSON(d.load_url,function(a){c=a.form_id,l(a.form_structure),d.loaded(a),k(d.control_box_target)}):k(d.control_box_target);var k=function(b){var c="",g="",h="",i=e+"-control-box",k=e+"-save-button";c+='<option value="0" disabled selected>'+d.messages.add_new_field+"</option>",c+='<option value="input_text">'+d.messages.text+"</option>",c+='<option value="textarea">'+d.messages.paragraph+"</option>",c+='<option value="checkbox">'+d.messages.checkboxes+"</option>",c+='<option value="radio">'+d.messages.radio+"</option>",c+='<option value="select">'+d.messages.select+"</option>",g='<select id="'+i+'" class="frmb-control form-control">'+c+"</select>",h='<button type="submit" id="'+k+'" class="frmb-submit btn btn-primary">'+d.messages.save+"</button>",b?a(b).append(g):a(f).before(g),a(f).after(h),a("#"+k).click(function(){return d.saving.call(this),w.call(this),!1}),a("#"+i).change(function(){return m(a(this).val()),a(this).val(0).blur(),a("html, body").animate({scrollTop:a("#frm-"+(j-1)+"-item").offset().top},500),!1})},l=function(b){var c="",d=!1;a(b).each(function(){"checkbox"===this.cssClass?(d=[this.title],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):"radio"===this.cssClass?(d=[this.title],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):"select"===this.cssClass?(d=[this.title,this.multiple],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):c=[this.values],m(this.cssClass,c,d,this.required)})},m=function(a,b,c,d){switch(g="",h=a,"undefined"==typeof b&&(b=""),a){case"input_text":n(b,d);break;case"textarea":o(b,d);break;case"checkbox":p(b,c,d);break;case"radio":r(b,c,d);break;case"select":t(b,c,d)}},n=function(a,c){g+="<label>"+d.messages.label+"</label>",g+='<input class="fld-title form-control" id="title-'+j+'" type="text" value="'+a+'" />',b="",v(d.messages.text,g,c,b)},o=function(a,c){g+="<label>"+d.messages.label+"</label>",g+='<input type="text" class="form-control" value="'+a+'" />',b="",v(d.messages.paragraph_field,g,c,b)},p=function(c,e,f){var h="";if("object"==typeof e&&(h=e[0]),g+='<div class="chk_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" name="title" class="form-control" value="'+h+'" /></div>',g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=q(c[i]);else g+=q("");g+='<li class="add-area"><a href="#" class="add add_ck">'+d.messages.add+"</a></li>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.checkbox_group,g,f,b),a("."+d.css_ol_sortable_class).sortable()},q=function(a){var b=!1,c="";return"object"==typeof a&&(c=a[0],b="false"===a[1]||"undefined"===a[1]?!1:!0),g="<li>",g+="<div>",g+='<input type="checkbox"'+(b?' checked="checked"':"")+" />",g+='<input type="text" class="form-control" value="'+c+'" />',g+='<a href="#" class="remove" title="'+d.messages.remove_message+'">'+d.messages.remove+"</a>",g+="</div></li>"},r=function(c,e,f){var h="";if("object"==typeof e&&(h=e[0]),g+='<div class="rd_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" class="form-control" name="title" value="'+h+'" /></div>',g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=s(c[i],"frm-"+j+"-fld");else g+=s("","frm-"+j+"-fld");g+='<div class="add-area"><a href="#" class="add add_rd">'+d.messages.add+"</a></div>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.radio_group,g,f,b),a("."+d.css_ol_sortable_class).sortable()},s=function(a,b){var c=!1,e="";return"object"==typeof a&&(e=a[0],c="false"===a[1]||"undefined"===a[1]?!1:!0),g="<li>",g+="<div>",g+='<input type="radio"'+(c?' checked="checked"':"")+' name="radio_'+b+'" />',g+='<input type="text" class="form-control" value="'+e+'" />',g+='<a href="#" class="remove" title="'+d.messages.remove_message+'">'+d.messages.remove+"</a>",g+="</div></li>"},t=function(c,e,f){var h=!1,j="";if("object"==typeof e&&(j=e[0],h="true"===e[1]||"checked"===e[1]?!0:!1),g+='<div class="opt_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" class="form-control" name="title" value="'+j+'" /></div>',g+="",g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<input type="checkbox" name="multiple"'+(h?'checked="checked"':"")+">",g+='<label class="auto">'+d.messages.selections_message+"</label>",g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=u(c[i],h);else g+=u("",h);g+='<div class="add-area"><a href="#" class="add add_opt">'+d.messages.add+"</a></div>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.select,g,f,b),a("."+d.css_ol_sortable_class).sortable()},u=function(a,b){return b?q(a):s(a)},v=function(b,c,e){e&&(e="true"===e?!0:!1);var i="";i+='<li id="frm-'+j+'-item" class="'+h+'">',i+='<div class="legend">',i+='<a id="frm-'+j+'" class="toggle-form" href="#">'+d.messages.hide+"</a> ",i+='<a id="del_'+j+'" class="del-button delete-confirm" href="#" title="'+d.messages.remove_message+'"><span>'+d.messages.remove+"</span></a>",i+='<strong id="txt-title-'+j+'">'+b+"</strong></div>",i+='<div id="frm-'+j+'-fld" class="frm-holder">',i+='<div class="frm-elements">',i+='<div class="frm-fld"><label for="required-'+j+'">'+d.messages.required+"</label>",i+='<input class="required" type="checkbox" value="1" name="required-'+j+'" id="required-'+j+'"'+(e?' checked="checked"':"")+" /></div>",i+=g,i+="</div>",i+="</div>",i+="</li>",a(f).append(i),a("#frm-"+j+"-item").hide(),a("#frm-"+j+"-item").animate({opacity:"show",height:"show"},"slow"),j++};f.on("click",".remove",function(b){return b.preventDefault(),a(this).parents("li:eq(0)").animate({opacity:"hide",height:"hide",marginBottom:"0px"},"fast",function(){a(this).remove()}),!1}),f.on("click",".toggle-form",function(b){b.preventDefault();var c=a(this).parents("li:eq(0)").find(".frm-holder");return c.is(":visible")?(a(this).removeClass("open").addClass("closed").html(d.messages.show),c.animate({opacity:"hide",height:"hide"},"slow")):(a(this).removeClass("closed").addClass("open").html(d.messages.hide),c.animate({opacity:"show",height:"show"},"slow")),!1}),f.on("click",".delete-confirm",function(b){return b.preventDefault(),confirm(a(this).attr("title"))&&a(this).parents("li:eq(0)").animate({opacity:"hide",height:"hide",marginBottom:"0px"},"slow",function(){a(this).remove()}),!1}),f.on("click",".add_ck",function(b){return b.preventDefault(),a(this).parent().before(q()),!1}),f.on("click",".add_opt",function(b){return b.preventDefault(),a(this).parent().before(u("",!1)),!1}),f.on("click",".add_rd",function(b){return b.preventDefault(),a(this).parent().before(s(!1,a(this).parents(".frm-holder").attr("id"))),!1});var w=function(){var b=this;d.save_url&&a.ajax({type:"POST",url:d.save_url,data:a(f).serializeFormList({prepend:d.serialize_prefix})+"&form_id="+c,success:function(){d.saved.call(b)}})}})}}(jQuery),function(a){a.fn.serializeFormList=function(b){var c={prepend:"ul",is_child:!1,attributes:["class"]},d=a.extend(c,b);d.is_child||(d.prepend="&"+d.prepend);var e="";return this.each(function(){var b=0,c=1;a(this).children().each(function(){for(att=0;att<d.attributes.length;att++){var f="class"===d.attributes[att]?"cssClass":d.attributes[att];if(e+=d.prepend+"["+b+"]["+f+"]="+encodeURIComponent(a(this).attr(d.attributes[att])),"class"===d.attributes[att])switch(e+=d.prepend+"["+b+"][required]="+encodeURIComponent(a("#"+a(this).attr("id")+" input.required").is(":checked")),a(this).attr(d.attributes[att])){case"input_text":e+=d.prepend+"["+b+"][values]="+encodeURIComponent(a("#"+a(this).attr("id")+" input[type=text]").val());break;case"textarea":e+=d.prepend+"["+b+"][values]="+encodeURIComponent(a("#"+a(this).attr("id")+" input[type=text]").val());break;case"checkbox":c=1,a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++});break;case"radio":c=1,a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++});break;case"select":c=1,e+=d.prepend+"["+b+"][multiple]="+a("#"+a(this).attr("id")+" input[name=multiple]").is(":checked"),a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++})}}b++})}),e}}(jQuery),!function(a){a.fn.formbuilder=function(b){var c={save_url:!1,load_url:!1,control_box_target:!1,serialize_prefix:"frmb",css_ol_sortable_class:"ol_opt_sortable",messages:{save:"Save",add_new_field:"Add New Field...",text:"Text Field",title:"Title",paragraph:"Paragraph",checkboxes:"Checkboxes",radio:"Radio",select:"Select List",text_field:"Text Field",label:"Label",paragraph_field:"Paragraph Field",select_options:"Select Options",add:"Add",checkbox_group:"Checkbox Group",remove_message:"Are you sure you want to remove this element?",remove:"Remove",radio_group:"Radio Group",selections_message:"Allow Multiple Selections",hide:"Hide",required:"Required",show:"Show"},loaded:function(){},saving:function(){},saved:function(){}},d=a.extend(c,b),e="frmb-"+a("ul[id^=frmb-]").length++;return this.each(function(){var b,c,f=a(this).append('<ul id="'+e+'" class="frmb"></ul>').find("ul").sortable(),g="",h="",j=1;f.addClass(e),d.load_url?a.getJSON(d.load_url,function(a){c=a.form_id,l(a.form_structure),d.loaded(a),k(d.control_box_target)}):k(d.control_box_target);var k=function(b){var c="",g="",h="",i=e+"-control-box",k=e+"-save-button";c+='<option value="0" disabled selected>'+d.messages.add_new_field+"</option>",c+='<option value="input_text">'+d.messages.text+"</option>",c+='<option value="textarea">'+d.messages.paragraph+"</option>",c+='<option value="checkbox">'+d.messages.checkboxes+"</option>",c+='<option value="radio">'+d.messages.radio+"</option>",c+='<option value="select">'+d.messages.select+"</option>",g='<select id="'+i+'" class="frmb-control form-control">'+c+"</select>",h='<button type="submit" id="'+k+'" class="frmb-submit btn btn-primary">'+d.messages.save+"</button>",b?a(b).append(g):a(f).before(g),a(f).after(h),a("#"+k).click(function(){return d.saving.call(this),w.call(this),!1}),a("#"+i).change(function(){return m(a(this).val()),a(this).val(0).blur(),a("html, body").animate({scrollTop:a("#frm-"+(j-1)+"-item").offset().top},500),!1})},l=function(b){var c="",d=!1;a(b).each(function(){"checkbox"===this.cssClass?(d=[this.title],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):"radio"===this.cssClass?(d=[this.title],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):"select"===this.cssClass?(d=[this.title,this.multiple],c=[],a.each(this.values,function(){c.push([this.value,this.baseline])})):c=[this.values],m(this.cssClass,c,d,this.required)})},m=function(a,b,c,d){switch(g="",h=a,"undefined"==typeof b&&(b=""),a){case"input_text":n(b,d);break;case"textarea":o(b,d);break;case"checkbox":p(b,c,d);break;case"radio":r(b,c,d);break;case"select":t(b,c,d)}},n=function(a,c){g+="<label>"+d.messages.label+"</label>",g+='<input class="fld-title form-control" id="title-'+j+'" type="text" value="'+a+'" />',b="",v(d.messages.text,g,c,b)},o=function(a,c){g+="<label>"+d.messages.label+"</label>",g+='<input type="text" class="form-control" value="'+a+'" />',b="",v(d.messages.paragraph_field,g,c,b)},p=function(c,e,f){var h="";if("object"==typeof e&&(h=e[0]),g+='<div class="chk_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" name="title" class="form-control" value="'+h+'" /></div>',g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=q(c[i]);else g+=q("");g+='<li class="add-area"><a href="#" class="add add_ck">'+d.messages.add+"</a></li>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.checkbox_group,g,f,b),a("."+d.css_ol_sortable_class).sortable()},q=function(a){var b=!1,c="";return"object"==typeof a&&(c=a[0],b="false"===a[1]||"undefined"===a[1]?!1:!0),g="<li>",g+="<div>",g+='<input type="checkbox"'+(b?' checked="checked"':"")+" />",g+='<input type="text" class="form-control" value="'+c+'" />',g+='<a href="#" class="remove" title="'+d.messages.remove_message+'">'+d.messages.remove+"</a>",g+="</div></li>"},r=function(c,e,f){var h="";if("object"==typeof e&&(h=e[0]),g+='<div class="rd_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" class="form-control" name="title" value="'+h+'" /></div>',g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=s(c[i],"frm-"+j+"-fld");else g+=s("","frm-"+j+"-fld");g+='<div class="add-area"><a href="#" class="add add_rd">'+d.messages.add+"</a></div>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.radio_group,g,f,b),a("."+d.css_ol_sortable_class).sortable()},s=function(a,b){var c=!1,e="";return"object"==typeof a&&(e=a[0],c="false"===a[1]||"undefined"===a[1]?!1:!0),g="<li>",g+="<div>",g+='<input type="radio"'+(c?' checked="checked"':"")+' name="radio_'+b+'" />',g+='<input type="text" class="form-control" value="'+e+'" />',g+='<a href="#" class="remove" title="'+d.messages.remove_message+'">'+d.messages.remove+"</a>",g+="</div></li>"},t=function(c,e,f){var h=!1,j="";if("object"==typeof e&&(j=e[0],h="true"===e[1]||"checked"===e[1]?!0:!1),g+='<div class="opt_group">',g+='<div class="frm-fld"><label>'+d.messages.title+"</label>",g+='<input type="text" class="form-control" name="title" value="'+j+'" /></div>',g+="",g+='<div class="false-label">'+d.messages.select_options+"</div>",g+='<div class="fields">',g+='<input type="checkbox" name="multiple"'+(h?'checked="checked"':"")+">",g+='<label class="auto">'+d.messages.selections_message+"</label>",g+='<div><ol class="'+d.css_ol_sortable_class+'">',"object"==typeof c)for(i=0;i<c.length;i++)g+=u(c[i],h);else g+=u("",h);g+='<div class="add-area"><a href="#" class="add add_opt">'+d.messages.add+"</a></div>",g+="</ol></div>",g+="</div>",g+="</div>",b="",v(d.messages.select,g,f,b),a("."+d.css_ol_sortable_class).sortable()},u=function(a,b){return b?q(a):s(a)},v=function(b,c,e){e&&(e="true"===e?!0:!1);var i="";i+='<li id="frm-'+j+'-item" class="'+h+'">',i+='<div class="legend">',i+='<a id="frm-'+j+'" class="toggle-form" href="#">'+d.messages.hide+"</a> ",i+='<a id="del_'+j+'" class="del-button delete-confirm" href="#" title="'+d.messages.remove_message+'"><span>'+d.messages.remove+"</span></a>",i+='<strong id="txt-title-'+j+'">'+b+"</strong></div>",i+='<div id="frm-'+j+'-fld" class="frm-holder">',i+='<div class="frm-elements">',i+='<div class="frm-fld"><label for="required-'+j+'">'+d.messages.required+"</label>",i+='<input class="required" type="checkbox" value="1" name="required-'+j+'" id="required-'+j+'"'+(e?' checked="checked"':"")+" /></div>",i+=g,i+="</div>",i+="</div>",i+="</li>",a(f).append(i),a("#frm-"+j+"-item").hide(),a("#frm-"+j+"-item").animate({opacity:"show",height:"show"},"slow"),j++};f.on("click",".remove",function(b){return b.preventDefault(),a(this).parents("li:eq(0)").animate({opacity:"hide",height:"hide",marginBottom:"0px"},"fast",function(){a(this).remove()}),!1}),f.on("click",".toggle-form",function(b){b.preventDefault();var c=a(this).parents("li:eq(0)").find(".frm-holder");return c.is(":visible")?(a(this).removeClass("open").addClass("closed").html(d.messages.show),c.animate({opacity:"hide",height:"hide"},"slow")):(a(this).removeClass("closed").addClass("open").html(d.messages.hide),c.animate({opacity:"show",height:"show"},"slow")),!1}),f.on("click",".delete-confirm",function(b){return b.preventDefault(),confirm(a(this).attr("title"))&&a(this).parents("li:eq(0)").animate({opacity:"hide",height:"hide",marginBottom:"0px"},"slow",function(){a(this).remove()}),!1}),f.on("click",".add_ck",function(b){return b.preventDefault(),a(this).parent().before(q()),!1}),f.on("click",".add_opt",function(b){return b.preventDefault(),a(this).parent().before(u("",!1)),!1}),f.on("click",".add_rd",function(b){return b.preventDefault(),a(this).parent().before(s(!1,a(this).parents(".frm-holder").attr("id"))),!1});var w=function(){var b=this;d.save_url&&a.ajax({type:"POST",url:d.save_url,data:a(f).serializeFormList({prepend:d.serialize_prefix})+"&form_id="+c,success:function(){d.saved.call(b)}})}})}}(jQuery),function(a){a.fn.serializeFormList=function(b){var c={prepend:"ul",is_child:!1,attributes:["class"]},d=a.extend(c,b);d.is_child||(d.prepend="&"+d.prepend);var e="";return this.each(function(){var b=0,c=1;a(this).children().each(function(){for(att=0;att<d.attributes.length;att++){var f="class"===d.attributes[att]?"cssClass":d.attributes[att];if(e+=d.prepend+"["+b+"]["+f+"]="+encodeURIComponent(a(this).attr(d.attributes[att])),"class"===d.attributes[att])switch(e+=d.prepend+"["+b+"][required]="+encodeURIComponent(a("#"+a(this).attr("id")+" input.required").is(":checked")),a(this).attr(d.attributes[att])){case"input_text":e+=d.prepend+"["+b+"][values]="+encodeURIComponent(a("#"+a(this).attr("id")+" input[type=text]").val());break;case"textarea":e+=d.prepend+"["+b+"][values]="+encodeURIComponent(a("#"+a(this).attr("id")+" input[type=text]").val());break;case"checkbox":c=1,a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++});break;case"radio":c=1,a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++});break;case"select":c=1,e+=d.prepend+"["+b+"][multiple]="+a("#"+a(this).attr("id")+" input[name=multiple]").is(":checked"),a("#"+a(this).attr("id")+" input[type=text]").each(function(){"title"===a(this).attr("name")?e+=d.prepend+"["+b+"][title]="+encodeURIComponent(a(this).val()):(e+=d.prepend+"["+b+"][values]["+c+"][value]="+encodeURIComponent(a(this).val()),e+=d.prepend+"["+b+"][values]["+c+"][baseline]="+a(this).prev().is(":checked")),c++})}}b++})}),e}}(jQuery);

0 comments on commit 85d3ba5

Please sign in to comment.