-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakFillFromJSON.min.js
2 lines (2 loc) · 2.94 KB
/
akFillFromJSON.min.js
1
2
/*! akFillFromJSON v1.0.1 2020-01-23 | https://github.com/akwebapps/ak-FillFromJSON | (c) 2020 AK Web Apps | @license Licensed MIT */
!function(a){a.fn.akFillFromJSON=function(t,e){this.each(function(){new a.akFillFromJSON(this,t,e)})},a.akFillFromJSON=function(t,e,i){function s(t,e){var i=(e||"").toString();return t.hasClass("alphaNumify")?i=i.replace(/\s/g,"_").replace(/\W+/g,""):t.hasClass("slugify")?i=i.replace(/\s+/g,"-").replace(/[^\w\-]+/g,"").replace(/\-\-+/g,"-").replace(/^-+/,"").replace(/-+$/,""):t.hasClass("toHTML")?i=i.replace(new RegExp("\n".replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),"<br>"):t.hasClass("toText")&&(i=a("<div>"+fieldValue+"</div>").text()),t.hasClass("toLowerCase")?i=i.toLowerCase():t.hasClass("toUpperCase")?i=i.toUpperCase():t.hasClass("camelCase")?i=i.replace(/-([a-z])/g,function(a){return a[1].toUpperCase()}):t.hasClass("pascalCase")&&(i=i.replace(/(\-|^)([a-z])/gi,function(a,t,e){return e.toUpperCase()})),i}a.each(e,function(e,r){Array.isArray(r)&&r.length&&"object"!=typeof r[0]&&(r=r.join(", ")),"string"==typeof r||"number"==typeof r?(a("."+e+"Val:not(img):not(iframe), [data-param='"+e+"']:not(img):not(iframe)",t).each(function(){var t=a(this),e=s(t,r);t.hasClass("toText")?t.text(e):t.html(e)}),a("img."+e+"Val, img[data-param='"+e+"'], iframe."+e+"Val, iframe[data-param='"+e+"']",t).attr("src",r),a("a."+e+"Val-link, a[data-param='"+e+"']",t).attr("href",r),a("."+e+"Val-class",t).addClass(r),r.toString().indexOf("//")<0&&(a("img."+e+"Val[data-path], iframe."+e+"Val[data-path]",t).each(function(){a(this).attr("src",a(this).attr("data-path")+s(a(this),r))}),a("."+e+"Val-link[data-path]",t).each(function(){a(this).attr("href",a(this).attr("data-path")+s(a(this),r))})),a("a."+e+"Val-email",t).attr("href","mailto:"+r),a("a."+e+"Val-social[data-base]",t).each(function(){var t=a(this).attr("data-base"),e=s(a(this),r);a(this).attr("href",t+("/"!=t.slice(-1)&&"/"!=e.substr(0,1)?"/":"")+e)}),a("a."+e+"Val-tel",t).attr("href","tel:"+r).text(r),a.isNumeric(r)?a("."+e+"Val-width",t).css("width",r+"%").removeClass("d-none"):a("."+e+"Val-width",t).addClass("d-none"),a("."+e+"Val-inpV",t).attr("value",r),a("."+e+"Val-inpN",t).attr("name",r).addClass(r),a("."+e+"Val-attr",t).attr("data-"+e,r)):"object"==typeof r&&Array.isArray(r)&&r.length&&"object"==typeof r[0]&&a("."+e+"Div",t).length&&a("."+e+"-item",t).length&&a("."+e+"Div",t).each(function(){var t=a("."+e+"-holder",this).length?a("."+e+"-holder",this):a(this),i=a(a("."+e+"-item",this).first().outerHTML()),s=a(this).attr("data-assign")||"";a("."+e+"-item",this).remove(),a(r).each(function(a,e){i.akFillFromJSON(e),s&&i.attr("data-id",e[s]),t.append(i.outerHTML())})}),""!=r?i?(a(".not-"+e+"Div",t).hide(),a("."+e+"Div",t).show()):(a(".not-"+e+"Div",t).addClass("d-none hidden"),a("."+e+"Div",t).removeClass("d-none hidden")):i?(a(".not-"+e+"Div",t).show(),a("."+e+"Div",t).hide()):(a(".not-"+e+"Div",t).removeClass("d-none hidden"),a("."+e+"Div",t).addClass("d-none hidden"))})}}(jQuery);