-
Notifications
You must be signed in to change notification settings - Fork 0
/
kLibAll.min.js
1 lines (1 loc) · 5.34 KB
/
kLibAll.min.js
1
var kLib=kLib||{};function KformValueExtension(e){function n(e,n,t){}function t(e,n){return n}e=e||{setter:n,getter:t};this.setter=e.setter||n,this.getter=e.getter||t}!function(i){function a(e,n){e.className=e.className+" "+n}function t(e,o){i.forEach(e,function(e){var n,t;console.log(e),t=o,(n=e).className=n.className.replace(t,"")})}i.addClassById=function(e,n){a(document.getElementById(e),n)},i[a.name]=a,i.validateOnlyThisElementHasClassName=function(e,n){i.removeClassToAllWithClassName(n,n),a(e,n)},i.setElementContentByClassName=function(e,n){document.getElementsByClassName(e)[0].innerHTML=n},i.addClassToAllWithClassName=function(e,n){var t,o,r=document.getElementsByClassName(e);t=r,o=n,i.forEach(t,function(e){a(e,o)})},i.removeClassToAllWithClassName=function(e,n){t(document.getElementsByClassName(e),n)}}(kLib),function(t){var o={mainHostUrl:location.href},r=0;function e(){var e="kCourrier"+ ++r,n=o;return n.id=e,n}t.initCourrier=function(e){if(t.activeCourriers=t.activeCourriers||{},e.id&&t.activeCourriers[e.id])return t.activeCourriers[e.id];var n=new a(e);return t.activeCourriers[e.id]=n};var n=e();t.APIMainCourrier=t.initCourrier(n);var i=e();function a(e){var n=(e=e||t.kCourierOptions).mainHostUrl||mainHostUrl,a=this;function s(e){console.log(e),console.error(e)}a.hostURL=n,a.post=function(o,r,i){return new Promise(function(e,n){n=n||s;try{var t=a.hostURL+o;axios.post(t,r,i).then(e,n)}catch(e){s(e)}})},a.get=function(o){return new Promise(function(e,n){n=n||s;try{var t=a.hostURL+o;axios.get(t).then(e,n)}catch(e){s(e)}})}}t.MainCourrier=t.initCourrier(i)}(kLib),function(o){if(!o)throw"kLib Is IMissing";var a=o.blnkProcedure;function c(e){var t=(e=e||{}).id,n=e.submitBtnId,r=e.courrierTool,u=this;u.submitProcedure=a,u.submitBtn=o.getById(n),u.submitBtn.onclick=u.submitProcedure,u.setSubmitProcedure=function(e){u.submitProcedure=e.bind(u),u.submitBtn.onclick=u.submitProcedure},u.findFormEl=function(e){try{if(t=e||t,!function(){if(t)return 1;throw"mesye.. that form needs an ID"}())return;return document.getElementById(t)}catch(e){return void console.log(e)}},u.ElIsform=function(e){return"form"===e.tagName.toLowerCase()},u.getFormObj=function(e){t=e||t;var n=u.findFormEl(t);if(!u.ElIsform(n))throw"#"+n.id+" this is not a true form";return function(e){for(var n={},t=e.getElementsByTagName("input"),o=e.getElementsByTagName("textarea"),r=e.getElementsByTagName("select"),i=0;i<r.length;i++)if(r[i].name&&""!=r[i].name){var a=r[i];n[a.name]=a.options[a.selectedIndex].value}for(i=0;i<t.length;i++)t[i].name&&""!=t[i].name&&(n[t[i].name]=t[i].value);for(i=0;i<o.length;i++)o[i].name&&""!=o[i].name&&(n[o[i].name]=o[i].value);return n=c.RunExtensionGetters(e,n)}(n)};var i="unknown url";u.sendInfo=function(e,n){e=e||i;var t=u.getFormObj();if(!t)throw"sendInfo-fail:dont know what to send to:"+e;!function(e,n,t){if(!e||e==i)throw"missing url won't send";t=t||function(e){console.log(e)};var o=function(n){return Object.keys(n).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(n[e])}).join("&")}(n);r.post(e,o,{headers:{"Content-Type":"application/x-www-form-urlencoded"}}).then(t).catch(function(e){console.error(e),alert("operation failed")})}(e,t,n)},u.setFormData=function(e,n,t){for(var o=(t=t||u.findFormEl()).getElementsByTagName("input"),r=t.getElementsByTagName("textarea"),i=t.getElementsByTagName("select"),a=0;a<o.length;a++)if(o[a].name&&o[a].name==e)return void(o[a].value=n);for(a=0;a<i.length;a++)if(i[a].name&&i[a].name==e){var s=i[a];s.options[s.selectedIndex].value}for(a=0;a<r.length;a++)r[a].name&&r[a].name==e&&(r[a].value=n);c.RunExtensionSetters(t,e,n)}}o.initForm=function(e){if(o.activeForms=o.activeForms||{},o.activeForms[e.id])return o.activeForms[e.id];var n=new c(e);return o.activeForms[e.id]=n},c.ValueExtesions=[],c.RunExtensionSetters=function(e,n,t){for(var o=0;o<c.ValueExtesions.length;o++)c.ValueExtesions[o].setter(e,n,t)},c.RunExtensionGetters=function(e,n){for(var t=0;t<c.ValueExtesions.length;t++)n=c.ValueExtesions[t].getter(e,n);return n}}(kLib),function(){var e=window||this;e.kLib=e.kLib||{};var t=e.kLib;t.getStringVersion=function(e){var n=document.createElement("span");return n.appendChild(e),n.innerHTML},t.mapTemplate=function(e,n){t.activeControllers=t.activeControllers||{},t.activeControllers[e]||(t.activeControllers[e]={run:window[e],url:n})},t.getController=function(e){return t.activeControllers=t.activeControllers||{},t.activeControllers[e]?t.activeControllers[e]:{run:function(){console.log("not found")},url:""}},t.forEach=function(e,n){for(var t=0;t<e.length;t++){n(e[t])}},t.getById=function(e){return document.getElementById(e)},t.isFunction=function(e){var n=e||!1,t="[object Function]"===toString.call(e||{});return n&&t},t.blnkProcedure=function(){console.log("this is a blank procedure. it should be replaced by an implementation")},e.kLib=t}(),function(t){function o(e){var n=this;function t(e){console.log("this method should be implemented"),e&&(console.log("about to run callback"),e())}n.id=e.id,n.data=[],n.dataHash={},n.render=t,n.fetchProcedure=t,n.onRender=function(e){n.render=e.bind(n),console.log("set on render")},n.onFetch=function(e){n.fetchProcedure=e.bind(n),console.log("set on fetch")},n.fetch=function(){n.fetchProcedure(n.render)}}t.initTemplate=function(e){if(t.activeTemplates=t.activeTemplates||{},t.activeTemplates[e.id])return t.activeTemplates[e.id];var n=new o(e);return t.activeTemplates[e.id]=n}}(kLib);