-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vsformbuilder.min.js
26 lines (26 loc) · 12.2 KB
/
vsformbuilder.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(c,e,a){c!=Array.prototype&&c!=Object.prototype&&(c[e]=a.value)};$jscomp.getGlobal=function(c){return"undefined"!=typeof window&&window===c?c:"undefined"!=typeof global&&null!=global?global:c};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(c){return $jscomp.SYMBOL_PREFIX+(c||"")+$jscomp.symbolCounter_++};
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var c=$jscomp.global.Symbol.iterator;c||(c=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[c]&&$jscomp.defineProperty(Array.prototype,c,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(c){var e=0;return $jscomp.iteratorPrototype(function(){return e<c.length?{done:!1,value:c[e++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(c){$jscomp.initSymbolIterator();c={next:c};c[$jscomp.global.Symbol.iterator]=function(){return this};return c};$jscomp.makeIterator=function(c){$jscomp.initSymbolIterator();var e=c[Symbol.iterator];return e?e.call(c):$jscomp.arrayIterator(c)};$jscomp.arrayFromIterator=function(c){for(var e,a=[];!(e=c.next()).done;)a.push(e.value);return a};$jscomp.arrayFromIterable=function(c){return c instanceof Array?c:$jscomp.arrayFromIterator($jscomp.makeIterator(c))};
$jscomp.owns=function(c,e){return Object.prototype.hasOwnProperty.call(c,e)};$jscomp.polyfill=function(c,e,a,b){if(e){a=$jscomp.global;c=c.split(".");for(b=0;b<c.length-1;b++){var d=c[b];d in a||(a[d]={});a=a[d]}c=c[c.length-1];b=a[c];e=e(b);e!=b&&null!=e&&$jscomp.defineProperty(a,c,{configurable:!0,writable:!0,value:e})}};
$jscomp.polyfill("Object.assign",function(c){return c?c:function(c,a){for(var b=1;b<arguments.length;b++){var d=arguments[b];if(d)for(var m in d)$jscomp.owns(d,m)&&(c[m]=d[m])}return c}},"es6-impl","es3");
(function(c){function e(){return function(a){this.options=this.SETTINGS=null;this.GenerateHTML="";this.init(a);return this}}"undefined"===typeof Library&&(c.VSFormBuilder=e());VSFormBuilder.prototype={VERSION:"1.0",DEFAULTS:{field_default_class:!0,parent_wrap_tag:"div",parent_wrap_attributes:{class:"field-container"},wrap_tag:"p",wrap_attributes:{id:"{field_id}_wrap",class:"form-row"},label_position:"before",label_tag:"label",label_attributes:{class:"input-label",for:{id:"{field_id}"}},help_text_tag:"span",
help_text_position:"after",help_text_attributes:{class:"help-text",id:"{field_id}_help_text"}},CURRENT_PARAM:{},fromJson:[],GenerateHTML:"",MainExcludeFields:"",AttributeMap:{},init:function(a){this.SETTINGS=this._merge_array(this.DEFAULTS,a);this.MainExcludeFields=["options","label","help_text","label_position","option_label_position"];this.AttributeMap={form:{map:"global",_attributes:{action:"",method:"get"}},fieldset:{map:"global",exclude:["placeholder"]},global:{exclude:this.MainExcludeFields,
_attributes:{class:"",id:"",name:""},map:""},wrap:{map:"global",_attributes:{id:"{new_id}"}},label:{map:"global"},input:{map:"global",_attributes:{placeholder:"",value:"",type:""}},radio:{exclude:["placeholder","options"],include:["value"],map:"input"},checkbox:{map:"radio"},text:{map:"input"},file:{map:"input"},textarea:{exclude:["placeholder","options","value","type"],_attributes:{rows:10,cols:10},map:"global"},select:{exclude:["value","placeholder","options","type"],map:"global"},option:{exclude:this._merge_array(JSON.parse(JSON.stringify(this.MainExcludeFields)),
["placeholder","type","class","id","label"]),_attributes:{value:""}},search:{map:"input"},email:{map:"input"},url:{map:"input"},tel:{map:"input"},number:{map:"input"},range:{map:"input"},date:{map:"input"},month:{map:"input"},week:{map:"input"},time:{map:"input"},datetime:{map:"input"},"datetime-local":{map:"input"},color:{map:"input"}};return this},get_option:function(a,b){return void 0===this.SETTINGS[a]?b:JSON.parse(JSON.stringify(this.SETTINGS[a]))},add_html:function(a){this.GenerateHTML+=a+"\n\n"},
add:function(a,b){void 0==b&&(b={});this.fromJson.push({type:a,data:b});return this},generate:function(){var a=this.fromJson,b;for(b in a){var d=a[b].type,c={};this.CURRENT_PARAM={};void 0!==a[b].data&&(c=a[b].data);this.CURRENT_PARAM=c;this[d]()}return this.GenerateHTML},AttributeMapping:function(a,b){void 0===b&&(b={exclude:[],include:[],_attributes:[],map:"",class:[]});return void 0!==this.AttributeMap[a]?(a=this.AttributeMap[a],a=this._merge_array(b,a),""==a.map?a:this.AttributeMapping(a.map,
a)):[]},get_field_attributes:function(a,b){a=this.AttributeMapping(a);a._attributes=this._merge_array(a._attributes,b);a.attributes={};b=JSON.parse(JSON.stringify(a._attributes));for(var d in b)-1==jQuery.inArray(d,a.exclude)&&(a.attributes[d]=b[d]);return a},_merge_array:function(a,b){for(var d in b)a[d]?"object"==typeof b[d]?Array.isArray(b[d])?a[d].push.apply(a[d],[].concat($jscomp.arrayFromIterable(b[d]))):a[d]=Object.assign({},a[d],b[d]):a[d]=b[d]:a[d]=b[d];return a},_array_to_html_attribute:function(a){var b=
"",d;for(d in a)if("object"==typeof a[d]){var b=b+(" "+d+'="'),c;for(c in a[d])b+=a[d][c]+" ";b+='"'}else b+=" "+d+'="'+a[d]+'" ';return b},_array_to_string:function(a,b){var d="",c;for(c in a)if("object"==typeof a[c])for(var f in a[c])d+=a[c][f]+b;else d+=a[c]+b;return d},getRandomInt:function(a,b){return Math.floor(Math.random()*(b-a+1)+a)},_get_id:function(a){return(new Date).getTime()+this.getRandomInt(1,1E4)},render_template_tags:function(a,b){for(var d in a)if("object"==typeof a[d])for(var c in a[d])"{field_id}"==
a[d][c]&&(a[d]=a[d][c].replace("{field_id}",b[c]));else a[d]=a[d].replace("{field_id}",b[d]);return a},field_attributes:function(a,b){b=JSON.parse(JSON.stringify(b));b=this.get_field_attributes(a,b);void 0!==b.attributes.id&&""==b.attributes.id&&(b.attributes.id=a+this._get_id(2));this.get_option("field_default_class")&&void 0!==b.class&&(b.class.push("input-"+a),b.class.push(a));if(void 0!==b.attributes.class){a=this._array_to_string(b.attributes.class," ");var d=this._array_to_string(b.class," ");
b.attributes.class=a+d}b.attribute_html=this._array_to_html_attribute(b.attributes);return b},tag:function(a,b,d){return"inline"==a?"<"+b+" "+d+"/>":a?"<"+b+" "+d+">":"</"+b+">"},render_tag:function(a,b,d){a=this.tag(a,b,d);this.add_html(a);return this},field_label:function(a){var b=this.get_option("label_tag");var d=void 0===a._attributes.label_position?this.get_option("label_position"):a._attributes.label_position;var c=this.get_option("label_attributes"),c=this.render_template_tags(c,a.attributes),
c=this._array_to_html_attribute(c);a=this.tag(!0,b,c)+a._attributes.label+this.tag(!1,b);return{position:d,html:a}},field_help_text:function(a){var b=this.get_option("help_text_tag"),d=this.get_option("help_text_position"),c=this.get_option("help_text_attributes"),c=this.render_template_tags(c,a.attributes),c=this._array_to_html_attribute(c);a=this.tag(!0,b,c)+a._attributes.help_text+this.tag(!1,b);return{position:d,html:a}},field_wrap:function(a,b){void 0===b&&(b="wrap");var d=this.get_option(b+
"_attributes"),d=this.render_template_tags(d,a.attributes),d=this._array_to_html_attribute(d);return{tag:this.get_option(b+"_tag"),html:d}},form_start:function(a){void 0===a&&(a=this.CURRENT_PARAM);a=this.field_attributes("form",a);this.render_tag(!0,"form",a.attribute_html);return this},form_end:function(){this.render_tag(!1,"form","")},fieldset_start:function(a){void 0===a&&(a=this.CURRENT_PARAM);a=this.field_attributes("fieldset",a);this.render_tag(!0,"fieldset",a.attribute_html);void 0!==a._attributes.label&&
(this.render_tag(!0,"legend",""),this.add_html(a._attributes.label),this.render_tag(!1,"legend"));return this},fieldset_end:function(){this.render_tag(!1,"fieldset","")},form_field:function(a,b,d){var c,f,e,g,h=JSON.parse(JSON.stringify(d));d=c=f=e=g="";var l=this.field_wrap(h),p=l.html,l=l.tag;if(void 0!==h._attributes.label){var k=this.field_label(h);"before"==k.position&&(g=k.html);"after"==k.position&&(e=k.html)}void 0!==h._attributes.help_text&&(k=this.field_help_text(h),"before"==k.position&&
(f=k.html),"after"==k.position&&(c=k.html));1==a||"inline"==a?(this.add_html(this.tag(!0,l,p)),1==a?(d=g+f+this.tag(!0,b,h.attribute_html),void 0!==h._attributes.value&&(d+=h._attributes.value),d+=this.tag(!1,b,h.attribute_html)+c+e):"inline"==a&&(d=g+f+this.tag(!0,b,h.attribute_html)+c+e),this.add_html(d),this.add_html(this.tag(!1,l))):this.add_html(this.tag(a,l));return this},_option:function(a,b){return"<option "+a+">"+b+"</option>"},_options:function(a,b,d){var c="",f;for(f in a)if("string"==
typeof a[f]){b.value=a[f];d==f?b.selected=!0:delete b.selected;var e=this.field_attributes("option",b);c+=this._option(e.attribute_html,a[f])}else if("object"==typeof a[f])if(void 0!==a[f].group_name){var g=a[f].options;e=' label="'+(void 0!==a[f].group_name?a[f].group_name:"")+'" ';void 0!==a[f].disabled&&a[f].disabled&&(e+=" disabled");c+=this.tag(!0,"optgroup",e)+this._options(g,b,d)+this.tag(!1,"optgroup")}else g="",void 0!==a[f].value&&(g=a[f].value),d==f?a[f].selected=!0:delete a[f].selected,
e=JSON.parse(JSON.stringify(b)),e=this._merge_array(e,a[f]),e.value=f,e=this.field_attributes("option",e),c+=this._option(e.attribute_html,g);return c},check_radio:function(a,b){void 0===b&&(b=this.CURRENT_PARAM);var d=this.field_attributes("wrap",b),c=this.field_wrap(d,"parent_wrap"),d=c.html,c=c.tag,e="",n="";this.render_tag(!0,c,d);void 0!==b.label&&(d=this.field_label(this.field_attributes("label",b)),"before"==d.position?e=d.html:n=d.html);this.add_html(e);d=b.options;delete b.options;b.type=
a;for(var g in d)b.value=g,b.label=d[g],void 0!==b.option_label_position&&(b.label_position=b.option_label_position),e=this.field_attributes(a,b),this.form_field("inline","input",e);this.add_html(n);this.render_tag(!1,c);return this},input_field:function(a,b){void 0===b&&(b=this.CURRENT_PARAM);b.type=a;a=this.field_attributes(a,b);this.form_field("inline","input",a);return this},textarea:function(a){void 0===a&&(a=this.CURRENT_PARAM);a=this.field_attributes("textarea",a);this.form_field(!0,"textarea",
a);return this},text:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("text",a)},password:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("password",a)},search:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("search",a)},email:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("email",a)},url:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("url",a)},tel:function(a){void 0===a&&(a=this.CURRENT_PARAM);
return this.input_field("tel",a)},number:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("number",a)},range:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("range",a)},date:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("date",a)},month:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("month",a)},week:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("week",a)},time:function(a){void 0===
a&&(a=this.CURRENT_PARAM);return this.input_field("time",a)},datetime:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("datetime",a)},datetime_local:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("datetime-local",a)},color:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("color",a)},file:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.input_field("file",a)},radio:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.check_radio("radio",
a)},checkbox:function(a){void 0===a&&(a=this.CURRENT_PARAM);return this.check_radio("checkbox",a)},select:function(a){void 0===a&&(a=this.CURRENT_PARAM);var b=JSON.parse(JSON.stringify(a.options));delete a.options;var c=JSON.parse(JSON.stringify(a)),b=this._options(b,c,void 0!==a.selected?a.selected:"");a.value=b;a=this.field_attributes("select",a);this.form_field(!0,"select",a);return this}}})(window);