Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

minified v0.5.0 for release

  • Loading branch information...
commit fce1b94d6a9882307229f6b487950a9b61139602 1 parent 12a3f77
@derickbailey authored
Showing with 26 additions and 3 deletions.
  1. +1 −2  backbone.modelbinding.js
  2. +25 −1 backbone.modelbinding.min.js
View
3  backbone.modelbinding.js
@@ -5,11 +5,10 @@
//
// Documentation and Full Licence Availabe at:
// http://github.com/derickbailey/backbone.modelbinding
-
+//
// ----------------------------
// Backbone.ModelBinding
// ----------------------------
-
;(function(root){
var modelbinding = (function(Backbone, _, $) {
View
26 backbone.modelbinding.min.js
@@ -1 +1,25 @@
-(function(a){var b=(function(k,l,h){var e={version:"0.4.3",bind:function(m,n){m.modelBinder=new d(m,n);m.modelBinder.bind()},unbind:function(m){if(m.modelBinder){m.modelBinder.unbind()}}};var d=function(m,n){this.config=new e.Configuration(n);this.modelBindings=[];this.elementBindings=[];this.bind=function(){var o=e.Conventions;for(var p in o){if(o.hasOwnProperty(p)){var s=o[p];var r=s.handler;var q=s.selector;r.bind.call(this,q,m,m.model,this.config)}}};this.unbind=function(){l.each(this.elementBindings,function(o){o.element.unbind(o.eventName,o.callback)});l.each(this.modelBindings,function(o){o.model.unbind(o.eventName,o.callback)})};this.registerModelBinding=function(p,q,r){var o="change:"+q;p.bind(o,r);this.modelBindings.push({model:p,eventName:o,callback:r})};this.registerDataBinding=function(p,o,q){p.bind(o,q);this.modelBindings.push({model:p,eventName:o,callback:q})};this.registerElementBinding=function(o,p){o.bind("change",p);this.elementBindings.push({element:o,eventName:"change",callback:p})}};e.Configuration=function(n){this.bindingAttrConfig={};l.extend(this.bindingAttrConfig,e.Configuration.bindindAttrConfig,n);if(this.bindingAttrConfig.all){var m=this.bindingAttrConfig.all;delete this.bindingAttrConfig.all;for(var o in this.bindingAttrConfig){if(this.bindingAttrConfig.hasOwnProperty(o)){this.bindingAttrConfig[o]=m}}}this.getBindingAttr=function(p){return this.bindingAttrConfig[p]};this.getBindingValue=function(q,r){var p=this.getBindingAttr(r);return q.attr(p)}};e.Configuration.bindindAttrConfig={text:"id",textarea:"id",password:"id",radio:"name",checkbox:"id",select:"id",number:"id",range:"id",tel:"id",search:"id",url:"id",email:"id"};e.Configuration.store=function(){e.Configuration.originalConfig=l.clone(e.Configuration.bindindAttrConfig)};e.Configuration.restore=function(){e.Configuration.bindindAttrConfig=e.Configuration.originalConfig};e.Configuration.configureBindingAttributes=function(m){if(m.all){this.configureAllBindingAttributes(m.all);delete m.all}l.extend(e.Configuration.bindindAttrConfig,m)};e.Configuration.configureAllBindingAttributes=function(n){var m=e.Configuration.bindindAttrConfig;m.text=n;m.textarea=n;m.password=n;m.radio=n;m.checkbox=n;m.select=n;m.number=n;m.range=n;m.tel=n;m.search=n;m.url=n;m.email=n};var c=(function(o){var n={};var m=function(p){var q=p[0].tagName.toLowerCase();if(q=="input"){q=p.attr("type");if(q==undefined||q==""){q="text"}}return q};n.bind=function(p,r,t,s){var q=this;r.$(p).each(function(A){var x=r.$(this);var B=m(x);var z=s.getBindingValue(x,B);var C=function(D,E){x.val(E)};var v=function(F,E){var D={};D[F]=E;t.set(D)};var y=function(D){v(z,r.$(D.target).val())};q.registerModelBinding(t,z,C);q.registerElementBinding(x,y);var u=t.get(z);if(typeof u!=="undefined"&&u!==null){x.val(u)}else{var w=x.val();if(w){v(z,w)}}})};return n})(k);var j=(function(n){var m={};m.bind=function(o,q,s,r){var p=this;q.$(o).each(function(y){var v=q.$(this);var x=r.getBindingValue(v,"select");var z=function(C,D){v.val(D)};var u=function(C,F,E){var D={};D[C]=F;D[C+"_text"]=E;s.set(D)};var w=function(C){var F=q.$(C.target);var D=F.val();var E=F.find(":selected").text();u(x,D,E)};p.registerModelBinding(s,x,z);p.registerElementBinding(v,w);var t=s.get(x);if(typeof t!=="undefined"&&t!==null){v.val(t)}if(v.val()!=t){var A=v.val();var B=v.find(":selected").text();u(x,A,B)}})};return m})(k);var i=(function(n){var m={};m.bind=function(o,r,t,s){var q=this;var p=[];r.$(o).each(function(z){var x=r.$(this);var w=s.getBindingValue(x,"radio");if(!p[w]){p[w]=true;var A=s.getBindingAttr("radio");var B=function(F,H){var G="input[type=radio]["+A+"='"+w+"'][value='"+H+"']";r.$(G).attr("checked","checked")};q.registerModelBinding(t,w,B);var v=function(F,H){var G={};G[F]=H;t.set(G)};var y=function(G){var F=r.$(G.currentTarget);if(F.is(":checked")){v(w,F.val())}};var E="input[type=radio]["+A+"='"+w+"']";r.$(E).each(function(){var F=h(this);q.registerElementBinding(F,y)});var u=t.get(w);if(typeof u!=="undefined"&&u!==null){var D="input[type=radio]["+A+"='"+w+"'][value='"+u+"']";r.$(D).attr("checked","checked")}else{var D="input[type=radio]["+A+"='"+w+"']:checked";var C=r.$(D).val();v(w,C)}}})};return m})(k);var f=(function(n){var m={};m.bind=function(o,q,s,r){var p=this;q.$(o).each(function(z){var w=q.$(this);var A=r.getBindingAttr("checkbox");var y=r.getBindingValue(w,"checkbox");var B=function(D,E){if(E){w.attr("checked","checked")}else{w.removeAttr("checked")}};var v=function(F,E){var D={};D[F]=E;s.set(D)};var x=function(E){var F=q.$(E.target);var D=F.is(":checked")?true:false;v(y,D)};p.registerModelBinding(s,y,B);p.registerElementBinding(w,x);var u=s.attributes.hasOwnProperty(y);if(u){var t=s.get(y);if(typeof t!=="undefined"&&t!==null&&t!=false){w.attr("checked","checked")}else{w.removeAttr("checked")}}else{var C=w.is(":checked")?true:false;v(y,C)}})};return m})(k);var g=(function(t,o,s){var n={"default":""};e.Configuration.dataBindSubst=function(u){this.storeDataBindSubstConfig();o.extend(n,u)};e.Configuration.storeDataBindSubstConfig=function(){e.Configuration._dataBindSubstConfig=o.clone(n)};e.Configuration.restoreDataBindSubstConfig=function(){if(e.Configuration._dataBindSubstConfig){n=e.Configuration._dataBindSubstConfig;delete e.Configuration._dataBindSubstConfig}};e.Configuration.getDataBindSubst=function(u,w){var v=w;if(w===undefined){if(n.hasOwnProperty(u)){v=n[u]}else{v=n["default"]}}return v};var r=function(v,u,x){var w=x;x=e.Configuration.getDataBindSubst(u,x);switch(u){case"html":v.html(x);break;case"text":v.text(x);break;case"enabled":v.attr("disabled",!x);break;case"displayed":v[x?"show":"hide"]();break;case"hidden":v[x?"hide":"show"]();break;default:v.attr(u,x)}};var q=function(w){var x=[];var v=e.Conventions.databind.selector.replace(/^(.*\[)([^\]]*)(].*)/g,"$2");var u=w.attr(v).split(";");o.each(u,function(y){var z=s.trim(y).split(" ");if(z.length==1){z.unshift("text")}x.push({elementAttr:z[0],modelAttr:z[1]})});return x};var p=function(x,y){var w={};var u=y.modelAttr;var v=u.indexOf("event:");if(v==0){w.name=u.substr(6);w.callback=function(z){r(x,y.elementAttr,z)}}else{w.name="change:"+u;w.callback=function(z,A){r(x,y.elementAttr,A)}}return w};var m={};m.bind=function(u,w,y,x){var v=this;w.$(u).each(function(A){var B=w.$(this);var z=q(B);o.each(z,function(D){var C=p(B,D);v.registerDataBinding(y,C.name,C.callback);r(B,D.elementAttr,y.get(D.modelAttr))})})};return m})(k,l,h);e.Conventions={text:{selector:"input:text",handler:c},textarea:{selector:"textarea",handler:c},password:{selector:"input:password",handler:c},radio:{selector:"input:radio",handler:i},checkbox:{selector:"input:checkbox",handler:f},select:{selector:"select",handler:j},databind:{selector:"*[data-bind]",handler:g},number:{selector:"input[type=number]",handler:c},range:{selector:"input[type=range]",handler:c},tel:{selector:"input[type=tel]",handler:c},search:{selector:"input[type=search]",handler:c},url:{selector:"input[type=url]",handler:c},email:{selector:"input[type=email]",handler:c}};return e});if(typeof define==="function"&&define.amd){define(["backbone","underscore","jquery"],function(e,c,d){return b(e,c,d)})}else{a.Backbone=Backbone||{};a.Backbone.ModelBinding=b(Backbone,_,jQuery)}})(this);
+// Backbone.ModelBinding v0.5.0
+//
+// Copyright (C)2011 Derick Bailey, Muted Solutions, LLC
+// Distributed Under MIT Liscene
+//
+// Documentation and Full Licence Availabe at:
+// http://github.com/derickbailey/backbone.modelbinding
+//
+// ----------------------------
+// Backbone.ModelBinding
+// ----------------------------
+(function(m){var p=function(j,l,r){var c={version:"0.5.0",bind:function(a,b){a.modelBinder=new m(a,b);a.modelBinder.bind()},unbind:function(a){a.modelBinder&&a.modelBinder.unbind()}},m=function(a,b){this.config=new c.Configuration(b);this.modelBindings=[];this.elementBindings=[];this.bind=function(){var q=c.Conventions,b;for(b in q)if(q.hasOwnProperty(b)){var f=q[b];f.handler.bind.call(this,f.selector,a,a.model,this.config)}};this.unbind=function(){l.each(this.elementBindings,function(b){b.element.unbind(b.eventName,
+b.callback)});l.each(this.modelBindings,function(b){b.model.unbind(b.eventName,b.callback)})};this.registerModelBinding=function(b,a,c){a="change:"+a;b.bind(a,c);this.modelBindings.push({model:b,eventName:a,callback:c})};this.registerDataBinding=function(b,a,c){b.bind(a,c);this.modelBindings.push({model:b,eventName:a,callback:c})};this.registerElementBinding=function(b,a){b.bind("change",a);this.elementBindings.push({element:b,eventName:"change",callback:a})}};c.Configuration=function(a){this.bindingAttrConfig=
+{};l.extend(this.bindingAttrConfig,c.Configuration.bindindAttrConfig,a);if(this.bindingAttrConfig.all){a=this.bindingAttrConfig.all;delete this.bindingAttrConfig.all;for(var b in this.bindingAttrConfig)this.bindingAttrConfig.hasOwnProperty(b)&&(this.bindingAttrConfig[b]=a)}this.getBindingAttr=function(b){return this.bindingAttrConfig[b]};this.getBindingValue=function(b,a){var c=this.getBindingAttr(a);return b.attr(c)}};c.Configuration.bindindAttrConfig={text:"id",textarea:"id",password:"id",radio:"name",
+checkbox:"id",select:"id",number:"id",range:"id",tel:"id",search:"id",url:"id",email:"id"};c.Configuration.store=function(){c.Configuration.originalConfig=l.clone(c.Configuration.bindindAttrConfig)};c.Configuration.restore=function(){c.Configuration.bindindAttrConfig=c.Configuration.originalConfig};c.Configuration.configureBindingAttributes=function(a){a.all&&(this.configureAllBindingAttributes(a.all),delete a.all);l.extend(c.Configuration.bindindAttrConfig,a)};c.Configuration.configureAllBindingAttributes=
+function(a){var b=c.Configuration.bindindAttrConfig;b.text=a;b.textarea=a;b.password=a;b.radio=a;b.checkbox=a;b.select=a;b.number=a;b.range=a;b.tel=a;b.search=a;b.url=a;b.email=a};var k=function(){var a={},b=function(b){var a=b[0].tagName.toLowerCase();if("input"==a&&(a=b.attr("type"),void 0==a||""==a))a="text";return a};a.bind=function(a,c,f,n){var g=this;c.$(a).each(function(){var a=c.$(this),d=b(a),e=n.getBindingValue(a,d),o=function(a,b){var d={};d[a]=b;f.set(d)};g.registerModelBinding(f,e,function(b,
+d){a.val(d)});g.registerElementBinding(a,function(b){o(e,c.$(b.target).val())});d=f.get(e);"undefined"!==typeof d&&null!==d?a.val(d):(d=a.val())&&o(e,d)})};return a}(j),p=function(){return{bind:function(a,b,c,i){var f=this;b.$(a).each(function(){var a=b.$(this),g=i.getBindingValue(a,"select"),h=function(a,b,d){var e={};e[a]=b;e[a+"_text"]=d;c.set(e)};f.registerModelBinding(c,g,function(b,d){a.val(d)});f.registerElementBinding(a,function(a){var d=b.$(a.target),a=d.val(),d=d.find(":selected").text();
+h(g,a,d)});var d=c.get(g);"undefined"!==typeof d&&null!==d&&a.val(d);if(a.val()!=d){var d=a.val(),e=a.find(":selected").text();h(g,d,e)}})}}}(j),s=function(){return{bind:function(a,b,c,i){var f=this,n=[];b.$(a).each(function(){var a=b.$(this),h=i.getBindingValue(a,"radio");if(!n[h]){n[h]=!0;var d=i.getBindingAttr("radio");f.registerModelBinding(c,h,function(a,c){b.$("input[type=radio]["+d+"='"+h+"'][value='"+c+"']").attr("checked","checked")});var e=function(a,b){var d={};d[a]=b;c.set(d)},o=function(a){a=
+b.$(a.currentTarget);a.is(":checked")&&e(h,a.val())};b.$("input[type=radio]["+d+"='"+h+"']").each(function(){var a=r(this);f.registerElementBinding(a,o)});a=c.get(h);"undefined"!==typeof a&&null!==a?b.$("input[type=radio]["+d+"='"+h+"'][value='"+a+"']").attr("checked","checked"):(a=b.$("input[type=radio]["+d+"='"+h+"']:checked").val(),e(h,a))}})}}}(j),t=function(){return{bind:function(a,b,c,i){var f=this;b.$(a).each(function(){var a=b.$(this);i.getBindingAttr("checkbox");var g=i.getBindingValue(a,
+"checkbox"),h=function(a,b){var d={};d[a]=b;c.set(d)};f.registerModelBinding(c,g,function(b,d){d?a.attr("checked","checked"):a.removeAttr("checked")});f.registerElementBinding(a,function(a){a=b.$(a.target).is(":checked")?!0:!1;h(g,a)});if(c.attributes.hasOwnProperty(g)){var d=c.get(g);"undefined"!==typeof d&&null!==d&&!1!=d?a.attr("checked","checked"):a.removeAttr("checked")}else d=a.is(":checked")?!0:!1,h(g,d)})}}}(j),j=function(a,b,j){var i={"default":""};c.Configuration.dataBindSubst=function(a){this.storeDataBindSubstConfig();
+b.extend(i,a)};c.Configuration.storeDataBindSubstConfig=function(){c.Configuration._dataBindSubstConfig=b.clone(i)};c.Configuration.restoreDataBindSubstConfig=function(){c.Configuration._dataBindSubstConfig&&(i=c.Configuration._dataBindSubstConfig,delete c.Configuration._dataBindSubstConfig)};c.Configuration.getDataBindSubst=function(a,b){var c=b;void 0===b&&(c=i.hasOwnProperty(a)?i[a]:i["default"]);return c};var f=function(a,b,e){e=c.Configuration.getDataBindSubst(b,e);switch(b){case "html":a.html(e);
+break;case "text":a.text(e);break;case "enabled":a.attr("disabled",!e);break;case "displayed":a[e?"show":"hide"]();break;case "hidden":a[e?"hide":"show"]();break;default:a.attr(b,e)}},k=function(a){var d=[],e=c.Conventions.databind.selector.replace(/^(.*\[)([^\]]*)(].*)/g,"$2"),a=a.attr(e).split(";");b.each(a,function(a){a=j.trim(a).split(" ");1==a.length&&a.unshift("text");d.push({elementAttr:a[0],modelAttr:a[1]})});return d},g=function(a,b){var c={},g=b.modelAttr;0==g.indexOf("event:")?(c.name=
+g.substr(6),c.callback=function(c){f(a,b.elementAttr,c)}):(c.name="change:"+g,c.callback=function(c,e){f(a,b.elementAttr,e)});return c};return{bind:function(a,c,e){var i=this;c.$(a).each(function(){var a=c.$(this),h=k(a);b.each(h,function(b){var c=g(a,b);i.registerDataBinding(e,c.name,c.callback);f(a,b.elementAttr,e.get(b.modelAttr))})})}}}(j,l,r);c.Conventions={text:{selector:"input:text",handler:k},textarea:{selector:"textarea",handler:k},password:{selector:"input:password",handler:k},radio:{selector:"input:radio",
+handler:s},checkbox:{selector:"input:checkbox",handler:t},select:{selector:"select",handler:p},databind:{selector:"*[data-bind]",handler:j},number:{selector:"input[type=number]",handler:k},range:{selector:"input[type=range]",handler:k},tel:{selector:"input[type=tel]",handler:k},search:{selector:"input[type=search]",handler:k},url:{selector:"input[type=url]",handler:k},email:{selector:"input[type=email]",handler:k}};return c};"function"===typeof define&&define.amd?define(["backbone","underscore","jquery"],
+function(j,l,m){return p(j,l,m)}):(m.Backbone=Backbone||{},m.Backbone.ModelBinding=p(Backbone,_,jQuery))})(this);
Please sign in to comment.
Something went wrong with that request. Please try again.