442d2429 by Michael Richards

Build 0.5.0.

1 parent 5b4cdf90
......@@ -2,9 +2,9 @@
"name": "rivets",
"repo": "mikeric/rivets",
"description": "Declarative data binding facility.",
"version": "0.4.9",
"version": "0.5.0",
"keywords": ["data binding", "templating"],
"scripts": ["lib/rivets.js"],
"main": "lib/rivets.js",
"scripts": ["dist/rivets.js"],
"main": "dist/rivets.js",
"license": "MIT"
}
......
// rivets.js
// version: 0.4.9
// version: 0.5.0
// author: Michael Richards
// license: MIT
(function() {
......@@ -17,28 +17,24 @@
}
Rivets.Binding = (function() {
function Binding(el, type, model, keypath, options) {
function Binding(view, el, type, key, keypath, options) {
var identifier, regexp, value, _ref;
this.view = view;
this.el = el;
this.type = type;
this.model = model;
this.key = key;
this.keypath = keypath;
this.options = options != null ? options : {};
this.update = __bind(this.update, this);
this.unbind = __bind(this.unbind, this);
this.bind = __bind(this.bind, this);
this.publish = __bind(this.publish, this);
this.sync = __bind(this.sync, this);
this.set = __bind(this.set, this);
this.formattedValue = __bind(this.formattedValue, this);
if (!(this.binder = Rivets.binders[type])) {
_ref = Rivets.binders;
if (!(this.binder = this.view.binders[type])) {
_ref = this.view.binders;
for (identifier in _ref) {
value = _ref[identifier];
if (identifier !== '*' && identifier.indexOf('*') !== -1) {
......@@ -51,23 +47,25 @@
}
}
}
this.binder || (this.binder = Rivets.binders['*']);
this.binder || (this.binder = this.view.binders['*']);
if (this.binder instanceof Function) {
this.binder = {
routine: this.binder
};
}
this.formatters = this.options.formatters || [];
this.model = this.view.models[this.key];
}
Binding.prototype.formattedValue = function(value) {
var args, formatter, id, _i, _len, _ref, _ref1, _ref2, _ref3;
_ref = this.formatters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
formatter = _ref[_i];
args = formatter.split(/\s+/);
id = args.shift();
formatter = this.model[id] instanceof Function ? this.model[id] : ((_ref1 = this.options) != null ? (_ref2 = _ref1.bindingOptions) != null ? (_ref3 = _ref2.formatters) != null ? _ref3[id] : void 0 : void 0 : void 0) instanceof Function ? this.options.bindingOptions.formatters[id] : Rivets.formatters[id];
formatter = this.model[id] instanceof Function ? this.model[id] : ((_ref1 = this.options) != null ? (_ref2 = _ref1.bindingOptions) != null ? (_ref3 = _ref2.formatters) != null ? _ref3[id] : void 0 : void 0 : void 0) instanceof Function ? this.options.bindingOptions.formatters[id] : this.view.formatters[id];
if ((formatter != null ? formatter.read : void 0) instanceof Function) {
value = formatter.read.apply(formatter, [value].concat(__slice.call(args)));
} else if (formatter instanceof Function) {
......@@ -79,39 +77,42 @@
Binding.prototype.set = function(value) {
var _ref;
value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value);
return (_ref = this.binder.routine) != null ? _ref.call(this, this.el, value) : void 0;
};
Binding.prototype.sync = function() {
return this.set(this.options.bypass ? this.model[this.keypath] : Rivets.config.adapter.read(this.model, this.keypath));
return this.set(this.options.bypass ? this.model[this.keypath] : this.view.config.adapter.read(this.model, this.keypath));
};
Binding.prototype.publish = function() {
var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2;
value = getInputValue(this.el);
_ref = this.formatters.slice(0).reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
formatter = _ref[_i];
args = formatter.split(/\s+/);
id = args.shift();
if ((_ref1 = Rivets.formatters[id]) != null ? _ref1.publish : void 0) {
value = (_ref2 = Rivets.formatters[id]).publish.apply(_ref2, [value].concat(__slice.call(args)));
if ((_ref1 = this.view.formatters[id]) != null ? _ref1.publish : void 0) {
value = (_ref2 = this.view.formatters[id]).publish.apply(_ref2, [value].concat(__slice.call(args)));
}
}
return Rivets.config.adapter.publish(this.model, this.keypath, value);
return this.view.config.adapter.publish(this.model, this.keypath, value);
};
Binding.prototype.bind = function() {
var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results;
if ((_ref = this.binder.bind) != null) {
_ref.call(this, this.el);
}
if (this.options.bypass) {
this.sync();
} else {
Rivets.config.adapter.subscribe(this.model, this.keypath, this.sync);
if (Rivets.config.preloadData) {
this.view.config.adapter.subscribe(this.model, this.keypath, this.sync);
if (this.view.config.preloadData) {
this.sync();
}
}
......@@ -128,7 +129,7 @@
model = this.view.models[dependency.shift()];
keypath = dependency.join('.');
}
_results.push(Rivets.config.adapter.subscribe(model, keypath, this.sync));
_results.push(this.view.config.adapter.subscribe(model, keypath, this.sync));
}
return _results;
}
......@@ -136,11 +137,12 @@
Binding.prototype.unbind = function() {
var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results;
if ((_ref = this.binder.unbind) != null) {
_ref.call(this, this.el);
}
if (!this.options.bypass) {
Rivets.config.adapter.unsubscribe(this.model, this.keypath, this.sync);
this.view.config.adapter.unsubscribe(this.model, this.keypath, this.sync);
}
if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) {
_ref2 = this.options.dependencies;
......@@ -155,45 +157,66 @@
model = this.view.models[dependency.shift()];
keypath = dependency.join('.');
}
_results.push(Rivets.config.adapter.unsubscribe(model, keypath, this.sync));
_results.push(this.view.config.adapter.unsubscribe(model, keypath, this.sync));
}
return _results;
}
};
Binding.prototype.update = function() {
this.unbind();
this.model = this.view.models[this.key];
return this.bind();
};
return Binding;
})();
Rivets.View = (function() {
function View(els, models, options) {
var k, option, v, _base, _i, _len, _ref, _ref1, _ref2, _ref3;
this.els = els;
this.models = models;
this.options = options;
this.options = options != null ? options : {};
this.update = __bind(this.update, this);
this.publish = __bind(this.publish, this);
this.sync = __bind(this.sync, this);
this.unbind = __bind(this.unbind, this);
this.bind = __bind(this.bind, this);
this.select = __bind(this.select, this);
this.build = __bind(this.build, this);
this.bindingRegExp = __bind(this.bindingRegExp, this);
if (!(this.els.jquery || this.els instanceof Array)) {
this.els = [this.els];
}
_ref = ['config', 'binders', 'formatters'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
this[option] = {};
if (this.options[option]) {
_ref1 = this.options[option];
for (k in _ref1) {
v = _ref1[k];
this[option][k] = v;
}
}
_ref2 = Rivets[option];
for (k in _ref2) {
v = _ref2[k];
if ((_ref3 = (_base = this[option])[k]) == null) {
_base[k] = v;
}
}
}
this.build();
}
View.prototype.bindingRegExp = function() {
var prefix;
prefix = Rivets.config.prefix;
prefix = this.config.prefix;
if (prefix) {
return new RegExp("^data-" + prefix + "-");
} else {
......@@ -204,19 +227,21 @@
View.prototype.build = function() {
var bindingRegExp, el, node, parse, skipNodes, _i, _j, _len, _len1, _ref, _ref1,
_this = this;
this.bindings = [];
skipNodes = [];
bindingRegExp = this.bindingRegExp();
parse = function(node) {
var attribute, attributes, binder, binding, context, ctx, dependencies, identifier, keypath, model, n, options, path, pipe, pipes, regexp, splitPath, type, value, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
var attribute, attributes, binder, context, ctx, dependencies, identifier, key, keypath, n, options, path, pipe, pipes, regexp, splitPath, type, value, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
if (__indexOf.call(skipNodes, node) < 0) {
_ref = node.attributes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
attribute = _ref[_i];
if (bindingRegExp.test(attribute.name)) {
type = attribute.name.replace(bindingRegExp, '');
if (!(binder = Rivets.binders[type])) {
_ref1 = Rivets.binders;
if (!(binder = _this.binders[type])) {
_ref1 = _this.binders;
for (identifier in _ref1) {
value = _ref1[identifier];
if (identifier !== '*' && identifier.indexOf('*') !== -1) {
......@@ -227,7 +252,7 @@
}
}
}
binder || (binder = Rivets.binders['*']);
binder || (binder = _this.binders['*']);
if (binder.block) {
_ref2 = node.getElementsByTagName('*');
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
......@@ -243,12 +268,10 @@
attribute = _ref3[_k];
if (bindingRegExp.test(attribute.name)) {
options = {};
if ((_this.options != null) && typeof _this.options === 'object') {
options.bindingOptions = _this.options;
}
type = attribute.name.replace(bindingRegExp, '');
pipes = (function() {
var _l, _len3, _ref4, _results;
_ref4 = attribute.value.split('|');
_results = [];
for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) {
......@@ -259,6 +282,7 @@
})();
context = (function() {
var _l, _len3, _ref4, _results;
_ref4 = pipes.shift().split('<');
_results = [];
for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) {
......@@ -272,19 +296,17 @@
options.formatters = pipes;
options.bypass = path.indexOf(':') !== -1;
if (splitPath[0]) {
model = _this.models[splitPath.shift()];
key = splitPath.shift();
} else {
model = _this.models;
key = null;
splitPath.shift();
}
keypath = splitPath.join('.');
if (model) {
if (_this.models[key] != null) {
if (dependencies = context.shift()) {
options.dependencies = dependencies.split(/\s+/);
}
binding = new Rivets.Binding(node, type, model, keypath, options);
binding.view = _this;
_this.bindings.push(binding);
_this.bindings.push(new Rivets.Binding(_this, node, type, key, keypath, options));
}
}
}
......@@ -309,6 +331,7 @@
View.prototype.select = function(fn) {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -322,6 +345,7 @@
View.prototype.bind = function() {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -333,6 +357,7 @@
View.prototype.unbind = function() {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -344,6 +369,7 @@
View.prototype.sync = function() {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -355,6 +381,7 @@
View.prototype.publish = function() {
var binding, _i, _len, _ref, _results;
_ref = this.select(function(b) {
return b.binder.publishes;
});
......@@ -366,12 +393,40 @@
return _results;
};
View.prototype.update = function(models) {
var binding, key, model, _results;
if (models == null) {
models = {};
}
_results = [];
for (key in models) {
model = models[key];
this.models[key] = model;
_results.push((function() {
var _i, _len, _ref, _results1;
_ref = this.select(function(b) {
return b.key === key;
});
_results1 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results1.push(binding.update());
}
return _results1;
}).call(this));
}
return _results;
};
return View;
})();
bindEvent = function(el, event, handler, context) {
var fn;
fn = function(e) {
return handler.call(context, e);
};
......@@ -409,6 +464,7 @@
getInputValue = function(el) {
var o, _i, _len, _results;
if (window.jQuery != null) {
el = jQuery(el);
switch (el[0].type) {
......@@ -454,6 +510,7 @@
},
routine: function(el, value) {
var _ref;
if (el.type === 'radio') {
return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) === (value != null ? value.toString() : void 0);
} else {
......@@ -471,6 +528,7 @@
},
routine: function(el, value) {
var _ref;
if (el.type === 'radio') {
return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) !== (value != null ? value.toString() : void 0);
} else {
......@@ -497,6 +555,7 @@
},
routine: function(el, value) {
var o, _i, _len, _ref, _ref1, _ref2, _results;
if (window.jQuery != null) {
el = jQuery(el);
if ((value != null ? value.toString() : void 0) !== ((_ref = el.val()) != null ? _ref.toString() : void 0)) {
......@@ -537,10 +596,24 @@
"each-*": {
block: true,
bind: function(el, collection) {
return el.removeAttribute(['data', Rivets.config.prefix, this.type].join('-').replace('--', '-'));
return el.removeAttribute(['data', this.view.config.prefix, this.type].join('-').replace('--', '-'));
},
unbind: function(el, collection) {
var view, _i, _len, _ref, _results;
if (this.iterated != null) {
_ref = this.iterated;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
view = _ref[_i];
_results.push(view.unbind());
}
return _results;
}
},
routine: function(el, collection) {
var data, e, item, itemEl, m, n, previous, view, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _results;
if (this.iterated != null) {
_ref = this.iterated;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -572,7 +645,7 @@
itemEl = el.cloneNode(true);
previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker;
this.marker.parentNode.insertBefore(itemEl, (_ref3 = previous.nextSibling) != null ? _ref3 : null);
view = new Rivets.View(itemEl, data);
view = new Rivets.View(itemEl, data, this.view.options);
view.bind();
_results.push(this.iterated.push(view));
}
......@@ -582,6 +655,7 @@
},
"class-*": function(el, value) {
var elClass;
elClass = " " + el.className + " ";
if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) {
return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim();
......@@ -608,6 +682,7 @@
exports.config = Rivets.config;
exports.configure = function(options) {
var property, value;
if (options == null) {
options = {};
}
......@@ -618,6 +693,7 @@
};
return exports.bind = function(el, models, options) {
var view;
if (models == null) {
models = {};
}
......
// rivets.js
// version: 0.5.0
// author: Michael Richards
// license: MIT
(function(){var t,i,e,n,s,r=function(t,i){return function(){return t.apply(i,arguments)}},h=[].slice,o=[].indexOf||function(t){for(var i=0,e=this.length;e>i;i++)if(i in this&&this[i]===t)return i;return-1};t={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),t.Binding=function(){function t(t,i,e,n,s,h){var o,u,l,a;if(this.view=t,this.el=i,this.type=e,this.key=n,this.keypath=s,this.options=null!=h?h:{},this.update=r(this.update,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.set=r(this.set,this),this.formattedValue=r(this.formattedValue,this),!(this.binder=this.view.binders[e])){a=this.view.binders;for(o in a)l=a[o],"*"!==o&&-1!==o.indexOf("*")&&(u=RegExp("^"+o.replace("*",".+")+"$"),u.test(e)&&(this.binder=l,this.args=RegExp("^"+o.replace("*","(.+)")+"$").exec(e),this.args.shift()))}this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function&&(this.binder={routine:this.binder}),this.formatters=this.options.formatters||[],this.model=this.view.models[this.key]}return t.prototype.formattedValue=function(t){var i,e,n,s,r,o,u,l,a;for(o=this.formatters,s=0,r=o.length;r>s;s++)e=o[s],i=e.split(/\s+/),n=i.shift(),e=this.model[n]instanceof Function?this.model[n]:(null!=(u=this.options)?null!=(l=u.bindingOptions)?null!=(a=l.formatters)?a[n]:void 0:void 0:void 0)instanceof Function?this.options.bindingOptions.formatters[n]:this.view.formatters[n],(null!=e?e.read:void 0)instanceof Function?t=e.read.apply(e,[t].concat(h.call(i))):e instanceof Function&&(t=e.apply(null,[t].concat(h.call(i))));return t},t.prototype.set=function(t){var i;return t=t instanceof Function&&!this.binder["function"]?this.formattedValue(t.call(this.model)):this.formattedValue(t),null!=(i=this.binder.routine)?i.call(this,this.el,t):void 0},t.prototype.sync=function(){return this.set(this.options.bypass?this.model[this.keypath]:this.view.config.adapter.read(this.model,this.keypath))},t.prototype.publish=function(){var t,i,e,s,r,o,u,l,a;for(s=n(this.el),u=this.formatters.slice(0).reverse(),r=0,o=u.length;o>r;r++)i=u[r],t=i.split(/\s+/),e=t.shift(),(null!=(l=this.view.formatters[e])?l.publish:void 0)&&(s=(a=this.view.formatters[e]).publish.apply(a,[s].concat(h.call(t))));return this.view.config.adapter.publish(this.model,this.keypath,s)},t.prototype.bind=function(){var t,i,e,n,s,r,h,o,u;if(null!=(r=this.binder.bind)&&r.call(this,this.el),this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync()),null!=(h=this.options.dependencies)?h.length:void 0){for(o=this.options.dependencies,u=[],n=0,s=o.length;s>n;n++)t=o[n],/^\./.test(t)?(e=this.model,i=t.substr(1)):(t=t.split("."),e=this.view.models[t.shift()],i=t.join(".")),u.push(this.view.config.adapter.subscribe(e,i,this.sync));return u}},t.prototype.unbind=function(){var t,i,e,n,s,r,h,o,u;if(null!=(r=this.binder.unbind)&&r.call(this,this.el),this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),null!=(h=this.options.dependencies)?h.length:void 0){for(o=this.options.dependencies,u=[],n=0,s=o.length;s>n;n++)t=o[n],/^\./.test(t)?(e=this.model,i=t.substr(1)):(t=t.split("."),e=this.view.models[t.shift()],i=t.join(".")),u.push(this.view.config.adapter.unsubscribe(e,i,this.sync));return u}},t.prototype.update=function(){return this.unbind(),this.model=this.view.models[this.key],this.bind()},t}(),t.View=function(){function i(i,e,n){var s,h,o,u,l,a,d,c,f,p;for(this.els=i,this.models=e,this.options=null!=n?n:{},this.update=r(this.update,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.select=r(this.select,this),this.build=r(this.build,this),this.bindingRegExp=r(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),d=["config","binders","formatters"],l=0,a=d.length;a>l;l++){if(h=d[l],this[h]={},this.options[h]){c=this.options[h];for(s in c)o=c[s],this[h][s]=o}f=t[h];for(s in f)o=f[s],null==(p=(u=this[h])[s])&&(u[s]=o)}this.build()}return i.prototype.bindingRegExp=function(){var t;return t=this.config.prefix,t?RegExp("^data-"+t+"-"):/^data-/},i.prototype.build=function(){var i,e,n,s,r,h,u,l,a,d,c,f=this;for(this.bindings=[],r=[],i=this.bindingRegExp(),s=function(e){var n,s,h,u,l,a,d,c,p,b,v,g,y,m,w,x,k,E,j,L,N,Q,R,V,O,B,F,T;if(0>o.call(r,e)){for(O=e.attributes,j=0,Q=O.length;Q>j;j++)if(n=O[j],i.test(n.name)){if(k=n.name.replace(i,""),!(h=f.binders[k])){B=f.binders;for(d in B)E=B[d],"*"!==d&&-1!==d.indexOf("*")&&(w=RegExp("^"+d.replace("*",".+")+"$"),w.test(k)&&(h=E))}if(h||(h=f.binders["*"]),h.block){for(F=e.getElementsByTagName("*"),L=0,R=F.length;R>L;L++)b=F[L],r.push(b);s=[n]}}for(T=s||e.attributes,N=0,V=T.length;V>N;N++)n=T[N],i.test(n.name)&&(v={},k=n.name.replace(i,""),m=function(){var t,i,e,s;for(e=n.value.split("|"),s=[],t=0,i=e.length;i>t;t++)y=e[t],s.push(y.trim());return s}(),u=function(){var t,i,e,n;for(e=m.shift().split("<"),n=[],t=0,i=e.length;i>t;t++)l=e[t],n.push(l.trim());return n}(),g=u.shift(),x=g.split(/\.|:/),v.formatters=m,v.bypass=-1!==g.indexOf(":"),x[0]?c=x.shift():(c=null,x.shift()),p=x.join("."),null!=f.models[c]&&((a=u.shift())&&(v.dependencies=a.split(/\s+/)),f.bindings.push(new t.Binding(f,e,k,c,p,v))));s&&(s=null)}},d=this.els,h=0,l=d.length;l>h;h++)for(e=d[h],s(e),c=e.getElementsByTagName("*"),u=0,a=c.length;a>u;u++)n=c[u],null!=n.attributes&&s(n)},i.prototype.select=function(t){var i,e,n,s,r;for(s=this.bindings,r=[],e=0,n=s.length;n>e;e++)i=s[e],t(i)&&r.push(i);return r},i.prototype.bind=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.bind());return s},i.prototype.unbind=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.unbind());return s},i.prototype.sync=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.sync());return s},i.prototype.publish=function(){var t,i,e,n,s;for(n=this.select(function(t){return t.binder.publishes}),s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.publish());return s},i.prototype.update=function(t){var i,e,n,s;null==t&&(t={}),s=[];for(e in t)n=t[e],this.models[e]=n,s.push(function(){var t,n,s,r;for(s=this.select(function(t){return t.key===e}),r=[],t=0,n=s.length;n>t;t++)i=s[t],r.push(i.update());return r}.call(this));return s},i}(),i=function(t,i,e,n){var s;return s=function(t){return e.call(n,t)},null!=window.jQuery?(t=jQuery(t),null!=t.on?t.on(i,s):t.bind(i,s)):null!=window.addEventListener?t.addEventListener(i,s,!1):(i="on"+i,t.attachEvent(i,s)),s},s=function(t,i,e){return null!=window.jQuery?(t=jQuery(t),null!=t.off?t.off(i,e):t.unbind(i,e)):window.removeEventListener?t.removeEventListener(i,e,!1):(i="on"+i,t.detachEvent(i,e))},n=function(t){var i,e,n,s;if(null!=window.jQuery)switch(t=jQuery(t),t[0].type){case"checkbox":return t.is(":checked");default:return t.val()}else switch(t.type){case"checkbox":return t.checked;case"select-multiple":for(s=[],e=0,n=t.length;n>e;e++)i=t[e],i.selected&&s.push(i.value);return s;default:return t.value}},t.binders={enabled:function(t,i){return t.disabled=!i},disabled:function(t,i){return t.disabled=!!i},checked:{publishes:!0,bind:function(t){return this.currentListener=i(t,"change",this.publish)},unbind:function(t){return s(t,"change",this.currentListener)},routine:function(t,i){var e;return t.checked="radio"===t.type?(null!=(e=t.value)?""+e:void 0)===(null!=i?""+i:void 0):!!i}},unchecked:{publishes:!0,bind:function(t){return this.currentListener=i(t,"change",this.publish)},unbind:function(t){return s(t,"change",this.currentListener)},routine:function(t,i){var e;return t.checked="radio"===t.type?(null!=(e=t.value)?""+e:void 0)!==(null!=i?""+i:void 0):!i}},show:function(t,i){return t.style.display=i?"":"none"},hide:function(t,i){return t.style.display=i?"none":""},html:function(t,i){return t.innerHTML=null!=i?i:""},value:{publishes:!0,bind:function(t){return this.currentListener=i(t,"change",this.publish)},unbind:function(t){return s(t,"change",this.currentListener)},routine:function(t,i){var e,n,s,r,h,u,l;if(null!=window.jQuery){if(t=jQuery(t),(null!=i?""+i:void 0)!==(null!=(r=t.val())?""+r:void 0))return t.val(null!=i?i:"")}else if("select-multiple"===t.type){if(null!=i){for(l=[],n=0,s=t.length;s>n;n++)e=t[n],l.push(e.selected=(h=e.value,o.call(i,h)>=0));return l}}else if((null!=i?""+i:void 0)!==(null!=(u=t.value)?""+u:void 0))return t.value=null!=i?i:""}},text:function(t,i){return null!=t.innerText?t.innerText=null!=i?i:"":t.textContent=null!=i?i:""},"on-*":{"function":!0,routine:function(t,e){return this.currentListener&&s(t,this.args[0],this.currentListener),this.currentListener=i(t,this.args[0],e,this.model)}},"each-*":{block:!0,bind:function(t){return t.removeAttribute(["data",this.view.config.prefix,this.type].join("-").replace("--","-"))},unbind:function(){var t,i,e,n,s;if(null!=this.iterated){for(n=this.iterated,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.unbind());return s}},routine:function(i,e){var n,s,r,h,o,u,l,a,d,c,f,p,b,v,g,y,m,w,x;if(null!=this.iterated)for(g=this.iterated,d=0,p=g.length;p>d;d++)for(a=g[d],a.unbind(),y=a.els,c=0,b=y.length;b>c;c++)s=y[c],s.parentNode.removeChild(s);else this.marker=document.createComment(" rivets: "+this.type+" "),i.parentNode.insertBefore(this.marker,i),i.parentNode.removeChild(i);if(this.iterated=[],e){for(x=[],f=0,v=e.length;v>f;f++){r=e[f],n={},m=this.view.models;for(u in m)o=m[u],n[u]=o;n[this.args[0]]=r,h=i.cloneNode(!0),l=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,this.marker.parentNode.insertBefore(h,null!=(w=l.nextSibling)?w:null),a=new t.View(h,n,this.view.options),a.bind(),x.push(this.iterated.push(a))}return x}}},"class-*":function(t,i){var e;return e=" "+t.className+" ",!i==(-1!==e.indexOf(" "+this.args[0]+" "))?t.className=i?""+t.className+" "+this.args[0]:e.replace(" "+this.args[0]+" "," ").trim():void 0},"*":function(t,i){return i?t.setAttribute(this.type,i):t.removeAttribute(this.type)}},t.config={preloadData:!0},t.formatters={},e=function(i){return i.binders=t.binders,i.formatters=t.formatters,i.config=t.config,i.configure=function(i){var e,n;null==i&&(i={});for(e in i)n=i[e],t.config[e]=n},i.bind=function(i,e,n){var s;return null==e&&(e={}),null==n&&(n={}),s=new t.View(i,e,n),s.bind(),s}},"object"==typeof exports?e(exports):"function"==typeof define&&define.amd?define(["exports"],function(t){return e(this.rivets=t),t}):e(this.rivets={})}).call(this);
\ No newline at end of file
// rivets.js
// version: 0.4.9
// author: Michael Richards
// license: MIT
(function(){var e,t,n,r,i,s=function(e,t){return function(){return e.apply(t,arguments)}},o=[].slice,u=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};e={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),e.Binding=function(){function t(t,n,r,i,o){var u,a,f,l;this.el=t,this.type=n,this.model=r,this.keypath=i,this.options=o!=null?o:{},this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.publish=s(this.publish,this),this.sync=s(this.sync,this),this.set=s(this.set,this),this.formattedValue=s(this.formattedValue,this);if(!(this.binder=e.binders[n])){l=e.binders;for(u in l)f=l[u],u!=="*"&&u.indexOf("*")!==-1&&(a=new RegExp("^"+u.replace("*",".+")+"$"),a.test(n)&&(this.binder=f,this.args=(new RegExp("^"+u.replace("*","(.+)")+"$")).exec(n),this.args.shift()))}this.binder||(this.binder=e.binders["*"]),this.binder instanceof Function&&(this.binder={routine:this.binder}),this.formatters=this.options.formatters||[]}return t.prototype.formattedValue=function(t){var n,r,i,s,u,a,f,l,c;a=this.formatters;for(s=0,u=a.length;s<u;s++)r=a[s],n=r.split(/\s+/),i=n.shift(),r=this.model[i]instanceof Function?this.model[i]:((f=this.options)!=null?(l=f.bindingOptions)!=null?(c=l.formatters)!=null?c[i]:void 0:void 0:void 0)instanceof Function?this.options.bindingOptions.formatters[i]:e.formatters[i],(r!=null?r.read:void 0)instanceof Function?t=r.read.apply(r,[t].concat(o.call(n))):r instanceof Function&&(t=r.apply(null,[t].concat(o.call(n))));return t},t.prototype.set=function(e){var t;return e=e instanceof Function&&!this.binder["function"]?this.formattedValue(e.call(this.model)):this.formattedValue(e),(t=this.binder.routine)!=null?t.call(this,this.el,e):void 0},t.prototype.sync=function(){return this.set(this.options.bypass?this.model[this.keypath]:e.config.adapter.read(this.model,this.keypath))},t.prototype.publish=function(){var t,n,i,s,u,a,f,l,c;s=r(this.el),f=this.formatters.slice(0).reverse();for(u=0,a=f.length;u<a;u++){n=f[u],t=n.split(/\s+/),i=t.shift();if((l=e.formatters[i])!=null?l.publish:void 0)s=(c=e.formatters[i]).publish.apply(c,[s].concat(o.call(t)))}return e.config.adapter.publish(this.model,this.keypath,s)},t.prototype.bind=function(){var t,n,r,i,s,o,u,a,f;(o=this.binder.bind)!=null&&o.call(this,this.el),this.options.bypass?this.sync():(e.config.adapter.subscribe(this.model,this.keypath,this.sync),e.config.preloadData&&this.sync());if((u=this.options.dependencies)!=null?u.length:void 0){a=this.options.dependencies,f=[];for(i=0,s=a.length;i<s;i++)t=a[i],/^\./.test(t)?(r=this.model,n=t.substr(1)):(t=t.split("."),r=this.view.models[t.shift()],n=t.join(".")),f.push(e.config.adapter.subscribe(r,n,this.sync));return f}},t.prototype.unbind=function(){var t,n,r,i,s,o,u,a,f;(o=this.binder.unbind)!=null&&o.call(this,this.el),this.options.bypass||e.config.adapter.unsubscribe(this.model,this.keypath,this.sync);if((u=this.options.dependencies)!=null?u.length:void 0){a=this.options.dependencies,f=[];for(i=0,s=a.length;i<s;i++)t=a[i],/^\./.test(t)?(r=this.model,n=t.substr(1)):(t=t.split("."),r=this.view.models[t.shift()],n=t.join(".")),f.push(e.config.adapter.unsubscribe(r,n,this.sync));return f}},t}(),e.View=function(){function t(e,t,n){this.els=e,this.models=t,this.options=n,this.publish=s(this.publish,this),this.sync=s(this.sync,this),this.unbind=s(this.unbind,this),this.bind=s(this.bind,this),this.select=s(this.select,this),this.build=s(this.build,this),this.bindingRegExp=s(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),this.build()}return t.prototype.bindingRegExp=function(){var t;return t=e.config.prefix,t?new RegExp("^data-"+t+"-"):/^data-/},t.prototype.build=function(){var t,n,r,i,s,o,a,f,l,c,h,p=this;this.bindings=[],s=[],t=this.bindingRegExp(),i=function(n){var r,i,o,a,f,l,c,h,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P;if(u.call(s,n)<0){M=n.attributes;for(N=0,L=M.length;N<L;N++){r=M[N];if(t.test(r.name)){x=r.name.replace(t,"");if(!(o=e.binders[x])){_=e.binders;for(h in _)T=_[h],h!=="*"&&h.indexOf("*")!==-1&&(E=new RegExp("^"+h.replace("*",".+")+"$"),E.test(x)&&(o=T))}o||(o=e.binders["*"]);if(o.block){D=n.getElementsByTagName("*");for(C=0,A=D.length;C<A;C++)m=D[C],s.push(m);i=[r]}}}P=i||n.attributes;for(k=0,O=P.length;k<O;k++){r=P[k];if(t.test(r.name)){g={},p.options!=null&&typeof p.options=="object"&&(g.bindingOptions=p.options),x=r.name.replace(t,""),w=function(){var e,t,n,i;n=r.value.split("|"),i=[];for(e=0,t=n.length;e<t;e++)b=n[e],i.push(b.trim());return i}(),f=function(){var e,t,n,r;n=w.shift().split("<"),r=[];for(e=0,t=n.length;e<t;e++)l=n[e],r.push(l.trim());return r}(),y=f.shift(),S=y.split(/\.|:/),g.formatters=w,g.bypass=y.indexOf(":")!==-1,S[0]?v=p.models[S.shift()]:(v=p.models,S.shift()),d=S.join(".");if(v){if(c=f.shift())g.dependencies=c.split(/\s+/);a=new e.Binding(n,x,v,d,g),a.view=p,p.bindings.push(a)}}}i&&(i=null)}},c=this.els;for(o=0,f=c.length;o<f;o++){n=c[o],i(n),h=n.getElementsByTagName("*");for(a=0,l=h.length;a<l;a++)r=h[a],r.attributes!=null&&i(r)}},t.prototype.select=function(e){var t,n,r,i,s;i=this.bindings,s=[];for(n=0,r=i.length;n<r;n++)t=i[n],e(t)&&s.push(t);return s},t.prototype.bind=function(){var e,t,n,r,i;r=this.bindings,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.bind());return i},t.prototype.unbind=function(){var e,t,n,r,i;r=this.bindings,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.unbind());return i},t.prototype.sync=function(){var e,t,n,r,i;r=this.bindings,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.sync());return i},t.prototype.publish=function(){var e,t,n,r,i;r=this.select(function(e){return e.binder.publishes}),i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.publish());return i},t}(),t=function(e,t,n,r){var i;return i=function(e){return n.call(r,e)},window.jQuery!=null?(e=jQuery(e),e.on!=null?e.on(t,i):e.bind(t,i)):window.addEventListener!=null?e.addEventListener(t,i,!1):(t="on"+t,e.attachEvent(t,i)),i},i=function(e,t,n){return window.jQuery!=null?(e=jQuery(e),e.off!=null?e.off(t,n):e.unbind(t,n)):window.removeEventListener?e.removeEventListener(t,n,!1):(t="on"+t,e.detachEvent(t,n))},r=function(e){var t,n,r,i;if(window.jQuery!=null){e=jQuery(e);switch(e[0].type){case"checkbox":return e.is(":checked");default:return e.val()}}else switch(e.type){case"checkbox":return e.checked;case"select-multiple":i=[];for(n=0,r=e.length;n<r;n++)t=e[n],t.selected&&i.push(t.value);return i;default:return e.value}},e.binders={enabled:function(e,t){return e.disabled=!t},disabled:function(e,t){return e.disabled=!!t},checked:{publishes:!0,bind:function(e){return this.currentListener=t(e,"change",this.publish)},unbind:function(e){return i(e,"change",this.currentListener)},routine:function(e,t){var n;return e.type==="radio"?e.checked=((n=e.value)!=null?n.toString():void 0)===(t!=null?t.toString():void 0):e.checked=!!t}},unchecked:{publishes:!0,bind:function(e){return this.currentListener=t(e,"change",this.publish)},unbind:function(e){return i(e,"change",this.currentListener)},routine:function(e,t){var n;return e.type==="radio"?e.checked=((n=e.value)!=null?n.toString():void 0)!==(t!=null?t.toString():void 0):e.checked=!t}},show:function(e,t){return e.style.display=t?"":"none"},hide:function(e,t){return e.style.display=t?"none":""},html:function(e,t){return e.innerHTML=t!=null?t:""},value:{publishes:!0,bind:function(e){return this.currentListener=t(e,"change",this.publish)},unbind:function(e){return i(e,"change",this.currentListener)},routine:function(e,t){var n,r,i,s,o,a,f;if(window.jQuery!=null){e=jQuery(e);if((t!=null?t.toString():void 0)!==((s=e.val())!=null?s.toString():void 0))return e.val(t!=null?t:"")}else if(e.type==="select-multiple"){if(t!=null){f=[];for(r=0,i=e.length;r<i;r++)n=e[r],f.push(n.selected=(o=n.value,u.call(t,o)>=0));return f}}else if((t!=null?t.toString():void 0)!==((a=e.value)!=null?a.toString():void 0))return e.value=t!=null?t:""}},text:function(e,t){return e.innerText!=null?e.innerText=t!=null?t:"":e.textContent=t!=null?t:""},"on-*":{"function":!0,routine:function(e,n){return this.currentListener&&i(e,this.args[0],this.currentListener),this.currentListener=t(e,this.args[0],n,this.model)}},"each-*":{block:!0,bind:function(t,n){return t.removeAttribute(["data",e.config.prefix,this.type].join("-").replace("--","-"))},routine:function(t,n){var r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E;if(this.iterated!=null){g=this.iterated;for(c=0,d=g.length;c<d;c++){l=g[c],l.unbind(),y=l.els;for(h=0,v=y.length;h<v;h++)i=y[h],i.parentNode.removeChild(i)}}else this.marker=document.createComment(" rivets: "+this.type+" "),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);this.iterated=[];if(n){E=[];for(p=0,m=n.length;p<m;p++){s=n[p],r={},b=this.view.models;for(a in b)u=b[a],r[a]=u;r[this.args[0]]=s,o=t.cloneNode(!0),f=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,this.marker.parentNode.insertBefore(o,(w=f.nextSibling)!=null?w:null),l=new e.View(o,r),l.bind(),E.push(this.iterated.push(l))}return E}}},"class-*":function(e,t){var n;n=" "+e.className+" ";if(!t==(n.indexOf(" "+this.args[0]+" ")!==-1))return e.className=t?""+e.className+" "+this.args[0]:n.replace(" "+this.args[0]+" "," ").trim()},"*":function(e,t){return t?e.setAttribute(this.type,t):e.removeAttribute(this.type)}},e.config={preloadData:!0},e.formatters={},n=function(t){return t.binders=e.binders,t.formatters=e.formatters,t.config=e.config,t.configure=function(t){var n,r;t==null&&(t={});for(n in t)r=t[n],e.config[n]=r},t.bind=function(t,n,r){var i;return n==null&&(n={}),r==null&&(r={}),i=new e.View(t,n,r),i.bind(),i}},typeof exports=="object"?n(exports):typeof define=="function"&&define.amd?define(["exports"],function(e){return n(this.rivets=e),e}):n(this.rivets={})}).call(this);
\ No newline at end of file
{
"name": "rivets",
"description": "Declarative data binding facility.",
"version": "0.4.9",
"version": "0.5.0",
"author": "Michael Richards",
"url": "http://rivetsjs.com",
"main": "./lib/rivets.js",
"main": "./dist/rivets.js",
"licenses": [
{
"type": "MIT",
......
# rivets.js
# version : 0.4.9
# version : 0.5.0
# author : Michael Richards
# license : MIT
......