This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
realvalue.min.js
1 lines (1 loc) · 2.06 KB
/
realvalue.min.js
1
(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{a(window.jQuery)}})(function(b){var a={defs:{}};a.isGet=function(){return arguments.length===0};a.error=function(c){if(c){console.error(c)}return false};a.field=function(d){var c=d.attr("rfield");return c&&a.defs?a.defs[c]:null};a.add=function(d,e){var f=function(g){a.defs[d]=g;if(g.on){var h=b("html");b.each(g.on,function(i,j){h.on(i,"[rfield='"+d+"']",j)})}};if(arguments.length==2){if(a.defs[d]){return this.error("The field definition for the key '"+d+"' already exists.")}else{if(!e||!e.get||!e.set){return this.error("A field definition needs a set and a get function to be ok. ")}}f(e);return true}else{if(arguments.length==1){if(!b.isPlainObject(d)){return this.error("Bad function call.")}var c=false;b.each(d,function(h,g){if(a.defs[h]){c="The field definition key '"+h+"' already exists."}else{if(!g.get||!g.set){c="The field definition with '"+h+"' key , needs a set and a get function to be ok. "}}if(c){return false}f(e)});if(c){return this.console.error(c)}else{return true}}else{return this.error("Bad function call.")}}};b.fn.autoVal=function(h){var d,f=this,g=f.prop("tagName"),e=["TD","TH","SPAN","DIV","A"];if(b.inArray(g,e)>-1){if(h!==d){f[0].innerHTML=h}else{return f[0].innerHTML}}else{var i=b.inArray(g,["INPUT","SELECT"])>-1,c=f.attr("type")=="checkbox";if(c){if(h!==d){return f.prop("checked",Boolean(h))}else{return f.prop("checked")}}else{if(i){if(h!==d){return f.val(h)}else{return f.val()}}}}};b.fn.rval=function(){if(!this.length){return}var d=arguments;justOne=function(){var g=a.field(this),h=g&&g.isGet?g.isGet.apply(this,arguments):a.isGet.apply(this,arguments),f=h?"get":"set";return g&&g[f]?g[f].apply(this,arguments):this.autoVal.apply(this,arguments)};if(this.length===1){return justOne.apply(this,d)}else{if(this.length>1){var c={};if(d.length===1&&b.isPlainObject(d[0])){var e=d[0];this.each(function(g,j){var h=b(j),f=h.attr("name");c[f]=justOne.apply(h,[e[f]])})}else{this.each(function(g,j){var h=b(j),f=h.attr("name");c[f]=justOne.apply(h,d)})}return c}}};return(window.RealValue=a)});