d29df654 by Michael Richards

Build 0.6.0.

1 parent b878ba4d
{
"name": "rivets",
"repo": "mikeric/rivets",
"description": "Declarative data binding facility.",
"version": "0.5.13",
"description": "Declarative data binding + templating solution.",
"version": "0.6.0",
"keywords": ["data binding", "templating"],
"scripts": ["dist/rivets.js"],
"main": "dist/rivets.js",
......
// Rivets.js
// version: 0.5.13
// version: 0.6.0
// author: Michael Richards
// license: MIT
(function() {
var Rivets, jQuery,
var KeypathObserver, Rivets,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Rivets = {};
jQuery = window.jQuery || window.Zepto;
if (!String.prototype.trim) {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
}
Rivets.Binding = (function() {
function Binding(view, el, type, key, keypath, options) {
var identifier, regexp, value, _ref;
this.view = view;
this.el = el;
this.type = type;
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.eventHandler = __bind(this.eventHandler, this);
this.formattedValue = __bind(this.formattedValue, this);
if (!(this.binder = this.view.binders[type])) {
_ref = this.view.binders;
for (identifier in _ref) {
value = _ref[identifier];
if (identifier !== '*' && identifier.indexOf('*') !== -1) {
regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$");
if (regexp.test(type)) {
this.binder = value;
this.args = new RegExp("^" + (identifier.replace('*', '(.+)')) + "$").exec(type);
this.args.shift();
}
}
}
}
this.binder || (this.binder = this.view.binders['*']);
if (this.binder instanceof Function) {
this.binder = {
routine: this.binder
};
Rivets = {
binders: {},
components: {},
formatters: {},
adapters: {},
config: {
prefix: 'rv',
templateDelimiters: ['{', '}'],
rootInterface: '.',
preloadData: true,
handler: function(context, ev, binding) {
return this.call(context, ev, binding.view.models);
}
this.formatters = this.options.formatters || [];
this.model = this.key ? this.view.models[this.key] : this.view.models;
}
};
Binding.prototype.formattedValue = function(value) {
var args, formatter, id, _i, _len, _ref;
_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] : 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) {
value = formatter.apply(null, [value].concat(__slice.call(args)));
}
}
return value;
};
Binding.prototype.eventHandler = function(fn) {
var binding, handler;
handler = (binding = this).view.config.handler;
return function(ev) {
return handler.call(fn, this, ev, binding);
};
};
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] : this.view.config.adapter.read(this.model, this.keypath));
};
Binding.prototype.publish = function() {
var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2;
value = Rivets.Util.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 = this.view.formatters[id]) != null ? _ref1.publish : void 0) {
value = (_ref2 = this.view.formatters[id]).publish.apply(_ref2, [value].concat(__slice.call(args)));
}
}
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 {
this.view.config.adapter.subscribe(this.model, this.keypath, this.sync);
if (this.view.config.preloadData) {
this.sync();
}
}
if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) {
_ref2 = this.options.dependencies;
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
dependency = _ref2[_i];
if (/^\./.test(dependency)) {
model = this.model;
keypath = dependency.substr(1);
} else {
dependency = dependency.split('.');
model = this.view.models[dependency.shift()];
keypath = dependency.join('.');
}
_results.push(this.view.config.adapter.subscribe(model, keypath, this.sync));
}
return _results;
}
};
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) {
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;
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
dependency = _ref2[_i];
if (/^\./.test(dependency)) {
model = this.model;
keypath = dependency.substr(1);
} else {
dependency = dependency.split('.');
model = this.view.models[dependency.shift()];
keypath = dependency.join('.');
}
_results.push(this.view.config.adapter.unsubscribe(model, keypath, this.sync));
}
return _results;
}
};
Binding.prototype.update = function(models) {
var _ref;
if (models == null) {
models = {};
}
if (this.key) {
if (models[this.key]) {
if (!this.options.bypass) {
this.view.config.adapter.unsubscribe(this.model, this.keypath, this.sync);
}
this.model = models[this.key];
if (this.options.bypass) {
this.sync();
} else {
this.view.config.adapter.subscribe(this.model, this.keypath, this.sync);
if (this.view.config.preloadData) {
this.sync();
}
}
Rivets.Util = {
bindEvent: function(el, event, handler) {
if (window.jQuery != null) {
el = jQuery(el);
if (el.on != null) {
return el.on(event, handler);
} else {
return el.bind(event, handler);
}
} else if (window.addEventListener != null) {
return el.addEventListener(event, handler, false);
} else {
this.sync();
event = 'on' + event;
return el.attachEvent(event, handler);
}
return (_ref = this.binder.update) != null ? _ref.call(this, models) : void 0;
};
return Binding;
})();
Rivets.ComponentBinding = (function(_super) {
__extends(ComponentBinding, _super);
function ComponentBinding(view, el, type) {
var attribute, _i, _len, _ref, _ref1;
this.view = view;
this.el = el;
this.type = type;
this.unbind = __bind(this.unbind, this);
this.bind = __bind(this.bind, this);
this.update = __bind(this.update, this);
this.locals = __bind(this.locals, this);
this.component = Rivets.components[this.type];
this.attributes = {};
this.inflections = {};
_ref = this.el.attributes || [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
attribute = _ref[_i];
if (_ref1 = attribute.name, __indexOf.call(this.component.attributes, _ref1) >= 0) {
this.attributes[attribute.name] = attribute.value;
},
unbindEvent: function(el, event, handler) {
if (window.jQuery != null) {
el = jQuery(el);
if (el.off != null) {
return el.off(event, handler);
} else {
this.inflections[attribute.name] = attribute.value;
}
}
}
ComponentBinding.prototype.sync = function() {};
ComponentBinding.prototype.locals = function(models) {
var inverse, key, model, path, result, _i, _len, _ref, _ref1;
if (models == null) {
models = this.view.models;
}
result = {};
_ref = this.inflections;
for (key in _ref) {
inverse = _ref[key];
_ref1 = inverse.split('.');
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
path = _ref1[_i];
result[key] = (result[key] || models)[path];
return el.unbind(event, handler);
}
} else if (window.removeEventListener != null) {
return el.removeEventListener(event, handler, false);
} else {
event = 'on' + event;
return el.detachEvent(event, handler);
}
for (key in models) {
model = models[key];
if (result[key] == null) {
result[key] = model;
},
getInputValue: function(el) {
var o, _i, _len, _results;
if (window.jQuery != null) {
el = jQuery(el);
switch (el[0].type) {
case 'checkbox':
return el.is(':checked');
default:
return el.val();
}
}
return result;
};
ComponentBinding.prototype.update = function(models) {
var _ref;
return (_ref = this.componentView) != null ? _ref.update(this.locals(models)) : void 0;
};
ComponentBinding.prototype.bind = function() {
var el, _ref;
if (this.componentView != null) {
return (_ref = this.componentView) != null ? _ref.bind() : void 0;
} else {
el = this.component.build.call(this.attributes);
(this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind();
return this.el.parentNode.replaceChild(el, this.el);
}
};
ComponentBinding.prototype.unbind = function() {
var _ref;
return (_ref = this.componentView) != null ? _ref.unbind() : void 0;
};
return ComponentBinding;
})(Rivets.Binding);
Rivets.TextBinding = (function(_super) {
__extends(TextBinding, _super);
function TextBinding(view, el, type, key, keypath, options) {
this.view = view;
this.el = el;
this.type = type;
this.key = key;
this.keypath = keypath;
this.options = options != null ? options : {};
this.sync = __bind(this.sync, this);
this.formatters = this.options.formatters || [];
this.model = this.key ? this.view.models[this.key] : this.view.models;
}
TextBinding.prototype.binder = {
routine: function(node, value) {
return node.data = value != null ? value : '';
}
};
TextBinding.prototype.sync = function() {
return TextBinding.__super__.sync.apply(this, arguments);
};
return TextBinding;
})(Rivets.Binding);
switch (el.type) {
case 'checkbox':
return el.checked;
case 'select-multiple':
_results = [];
for (_i = 0, _len = el.length; _i < _len; _i++) {
o = el[_i];
if (o.selected) {
_results.push(o.value);
}
}
return _results;
break;
default:
return el.value;
}
}
}
};
Rivets.View = (function() {
function View(els, models, options) {
......@@ -321,10 +103,10 @@
this.build = __bind(this.build, this);
this.componentRegExp = __bind(this.componentRegExp, this);
this.bindingRegExp = __bind(this.bindingRegExp, this);
if (typeof this.els.length === 'undefined') {
if (!(this.els.jquery || this.els instanceof Array)) {
this.els = [this.els];
}
_ref = ['config', 'binders', 'formatters'];
_ref = ['config', 'binders', 'formatters', 'adapters'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
this[option] = {};
......@@ -347,18 +129,11 @@
}
View.prototype.bindingRegExp = function() {
var prefix;
prefix = this.config.prefix;
if (prefix) {
return new RegExp("^data-" + prefix + "-");
} else {
return /^data-/;
}
return new RegExp("^" + this.config.prefix + "-");
};
View.prototype.componentRegExp = function() {
var _ref, _ref1;
return new RegExp("^" + ((_ref = (_ref1 = this.config.prefix) != null ? _ref1.toUpperCase() : void 0) != null ? _ref : 'RV') + "-");
return new RegExp("^" + (this.config.prefix.toUpperCase()) + "-");
};
View.prototype.build = function() {
......@@ -369,7 +144,7 @@
bindingRegExp = this.bindingRegExp();
componentRegExp = this.componentRegExp();
buildBinding = function(binding, node, type, declaration) {
var context, ctx, dependencies, key, keypath, options, path, pipe, pipes, splitPath;
var context, ctx, dependencies, keypath, options, pipe, pipes;
options = {};
pipes = (function() {
var _i, _len, _ref, _results;
......@@ -391,21 +166,12 @@
}
return _results;
})();
path = context.shift();
splitPath = path.split(/\.|:/);
keypath = context.shift();
options.formatters = pipes;
options.bypass = path.indexOf(':') !== -1;
if (splitPath[0]) {
key = splitPath.shift();
} else {
key = null;
splitPath.shift();
}
keypath = splitPath.join('.');
if (dependencies = context.shift()) {
options.dependencies = dependencies.split(/\s+/);
}
return _this.bindings.push(new Rivets[binding](_this, node, type, key, keypath, options));
return _this.bindings.push(new Rivets[binding](_this, node, type, keypath, options));
};
parse = function(node) {
var attribute, attributes, binder, childNode, delimiters, identifier, n, parser, regexp, restTokens, startToken, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _results;
......@@ -522,52 +288,374 @@
binding = _ref[_i];
_results.push(binding.unbind());
}
return _results;
return _results;
};
View.prototype.sync = function() {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.sync());
}
return _results;
};
View.prototype.publish = function() {
var binding, _i, _len, _ref, _results;
_ref = this.select(function(b) {
return b.binder.publishes;
});
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.publish());
}
return _results;
};
View.prototype.update = function(models) {
var binding, key, model, _i, _len, _ref, _results;
if (models == null) {
models = {};
}
for (key in models) {
model = models[key];
this.models[key] = model;
}
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.update(models));
}
return _results;
};
return View;
})();
Rivets.Binding = (function() {
function Binding(view, el, type, keypath, options) {
this.view = view;
this.el = el;
this.type = type;
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.eventHandler = __bind(this.eventHandler, this);
this.formattedValue = __bind(this.formattedValue, this);
this.setObserver = __bind(this.setObserver, this);
this.setBinder = __bind(this.setBinder, this);
this.formatters = this.options.formatters || [];
this.dependencies = [];
this.setBinder();
this.setObserver();
}
Binding.prototype.setBinder = function() {
var identifier, regexp, value, _ref;
if (!(this.binder = this.view.binders[this.type])) {
_ref = this.view.binders;
for (identifier in _ref) {
value = _ref[identifier];
if (identifier !== '*' && identifier.indexOf('*') !== -1) {
regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$");
if (regexp.test(this.type)) {
this.binder = value;
this.args = new RegExp("^" + (identifier.replace('*', '(.+)')) + "$").exec(this.type);
this.args.shift();
}
}
}
}
this.binder || (this.binder = this.view.binders['*']);
if (this.binder instanceof Function) {
return this.binder = {
routine: this.binder
};
}
};
Binding.prototype.setObserver = function() {
var _this = this;
this.observer = new KeypathObserver(this.view, this.view.models, this.keypath, function(obs) {
if (_this.key) {
_this.unbind(true);
}
_this.model = obs.target;
if (_this.key) {
_this.bind(true);
}
return _this.sync();
});
this.key = this.observer.key;
return this.model = this.observer.target;
};
Binding.prototype.formattedValue = function(value) {
var args, formatter, id, _i, _len, _ref;
_ref = this.formatters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
formatter = _ref[_i];
args = formatter.split(/\s+/);
id = args.shift();
formatter = 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) {
value = formatter.apply(null, [value].concat(__slice.call(args)));
}
}
return value;
};
Binding.prototype.eventHandler = function(fn) {
var binding, handler;
handler = (binding = this).view.config.handler;
return function(ev) {
return handler.call(fn, this, ev, binding);
};
};
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.key ? this.view.adapters[this.key["interface"]].read(this.model, this.key.path) : this.model);
};
Binding.prototype.publish = function() {
var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2;
value = Rivets.Util.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 = this.view.formatters[id]) != null ? _ref1.publish : void 0) {
value = (_ref2 = this.view.formatters[id]).publish.apply(_ref2, [value].concat(__slice.call(args)));
}
}
return this.view.adapters[this.key["interface"]].publish(this.model, this.key.path, value);
};
Binding.prototype.bind = function(silent) {
var dependency, key, observer, _i, _len, _ref, _ref1, _ref2, _results,
_this = this;
if (silent == null) {
silent = false;
}
if (!silent) {
if ((_ref = this.binder.bind) != null) {
_ref.call(this, this.el);
}
}
if (this.key) {
this.view.adapters[this.key["interface"]].subscribe(this.model, this.key.path, this.sync);
}
if (!silent ? this.view.config.preloadData : void 0) {
this.sync();
}
if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) {
_ref2 = this.options.dependencies;
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
dependency = _ref2[_i];
observer = new KeypathObserver(this.view, this.model, dependency, function(obs, prev) {
var key;
key = obs.key;
_this.view.adapters[key["interface"]].unsubscribe(prev, key.path, _this.sync);
_this.view.adapters[key["interface"]].subscribe(obs.target, key.path, _this.sync);
return _this.sync();
});
key = observer.key;
this.view.adapters[key["interface"]].subscribe(observer.target, key.path, this.sync);
_results.push(this.dependencies.push(observer));
}
return _results;
}
};
Binding.prototype.unbind = function(silent) {
var key, obs, _i, _len, _ref, _ref1;
if (silent == null) {
silent = false;
}
if (!silent) {
if ((_ref = this.binder.unbind) != null) {
_ref.call(this, this.el);
}
}
if (this.key) {
this.view.adapters[this.key["interface"]].unsubscribe(this.model, this.key.path, this.sync);
}
if (this.dependencies.length) {
_ref1 = this.dependencies;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
obs = _ref1[_i];
key = obs.key;
this.view.adapters[key["interface"]].unsubscribe(obs.target, key.path, this.sync);
}
return this.dependencies = [];
}
};
Binding.prototype.update = function(models) {
var _ref;
if (models == null) {
models = {};
}
return (_ref = this.binder.update) != null ? _ref.call(this, models) : void 0;
};
return Binding;
})();
Rivets.ComponentBinding = (function(_super) {
__extends(ComponentBinding, _super);
function ComponentBinding(view, el, type) {
var attribute, _i, _len, _ref, _ref1;
this.view = view;
this.el = el;
this.type = type;
this.unbind = __bind(this.unbind, this);
this.bind = __bind(this.bind, this);
this.update = __bind(this.update, this);
this.locals = __bind(this.locals, this);
this.component = Rivets.components[this.type];
this.attributes = {};
this.inflections = {};
_ref = this.el.attributes || [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
attribute = _ref[_i];
if (_ref1 = attribute.name, __indexOf.call(this.component.attributes, _ref1) >= 0) {
this.attributes[attribute.name] = attribute.value;
} else {
this.inflections[attribute.name] = attribute.value;
}
}
}
ComponentBinding.prototype.sync = function() {};
ComponentBinding.prototype.locals = function(models) {
var inverse, key, model, path, result, _i, _len, _ref, _ref1;
if (models == null) {
models = this.view.models;
}
result = {};
_ref = this.inflections;
for (key in _ref) {
inverse = _ref[key];
_ref1 = inverse.split('.');
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
path = _ref1[_i];
result[key] = (result[key] || models)[path];
}
}
for (key in models) {
model = models[key];
if (result[key] == null) {
result[key] = model;
}
}
return result;
};
ComponentBinding.prototype.update = function(models) {
var _ref;
return (_ref = this.componentView) != null ? _ref.update(this.locals(models)) : void 0;
};
ComponentBinding.prototype.bind = function() {
var el, _ref;
if (this.componentView != null) {
return (_ref = this.componentView) != null ? _ref.bind() : void 0;
} else {
el = this.component.build.call(this.attributes);
(this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind();
return this.el.parentNode.replaceChild(el, this.el);
}
};
View.prototype.sync = function() {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.sync());
}
return _results;
ComponentBinding.prototype.unbind = function() {
var _ref;
return (_ref = this.componentView) != null ? _ref.unbind() : void 0;
};
View.prototype.publish = function() {
var binding, _i, _len, _ref, _results;
_ref = this.select(function(b) {
return b.binder.publishes;
});
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.publish());
return ComponentBinding;
})(Rivets.Binding);
Rivets.TextBinding = (function(_super) {
__extends(TextBinding, _super);
function TextBinding(view, el, type, keypath, options) {
this.view = view;
this.el = el;
this.type = type;
this.keypath = keypath;
this.options = options != null ? options : {};
this.sync = __bind(this.sync, this);
this.formatters = this.options.formatters || [];
this.dependencies = [];
this.setObserver();
}
TextBinding.prototype.binder = {
routine: function(node, value) {
return node.data = value != null ? value : '';
}
return _results;
};
View.prototype.update = function(models) {
var binding, key, model, _i, _len, _ref, _results;
if (models == null) {
models = {};
}
for (key in models) {
model = models[key];
this.models[key] = model;
}
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.update(models));
TextBinding.prototype.sync = function() {
return TextBinding.__super__.sync.apply(this, arguments);
};
return TextBinding;
})(Rivets.Binding);
Rivets.KeypathParser = (function() {
function KeypathParser() {}
KeypathParser.parse = function(keypath, interfaces, root) {
var char, current, index, tokens;
tokens = [];
current = {
"interface": root,
path: ''
};
for (index in keypath) {
char = keypath[index];
if (__indexOf.call(interfaces, char) >= 0) {
tokens.push(current);
current = {
"interface": char,
path: ''
};
} else {
current.path += char;
}
}
return _results;
tokens.push(current);
return tokens;
};
return View;
return KeypathParser;
})();
......@@ -630,357 +718,488 @@
})();
Rivets.Util = {
bindEvent: function(el, event, handler) {
if (window.jQuery != null) {
el = jQuery(el);
if (el.on != null) {
return el.on(event, handler);
} else {
return el.bind(event, handler);
KeypathObserver = (function() {
function KeypathObserver(view, model, keypath, callback) {
this.view = view;
this.model = model;
this.keypath = keypath;
this.callback = callback;
this.realize = __bind(this.realize, this);
this.update = __bind(this.update, this);
this.parse = __bind(this.parse, this);
this.parse();
this.objectPath = [];
this.target = this.realize();
}
KeypathObserver.prototype.parse = function() {
var interfaces, k, path, root, v, _ref;
interfaces = (function() {
var _ref, _results;
_ref = this.view.adapters;
_results = [];
for (k in _ref) {
v = _ref[k];
_results.push(k);
}
} else if (window.addEventListener != null) {
return el.addEventListener(event, handler, false);
return _results;
}).call(this);
if (_ref = this.keypath[0], __indexOf.call(interfaces, _ref) >= 0) {
root = this.keypath[0];
path = this.keypath.substr(1);
} else {
event = 'on' + event;
return el.attachEvent(event, handler);
root = this.view.config.rootInterface;
path = this.keypath;
}
},
unbindEvent: function(el, event, handler) {
if (window.jQuery != null) {
el = jQuery(el);
if (el.off != null) {
return el.off(event, handler);
this.tokens = Rivets.KeypathParser.parse(path, interfaces, root);
return this.key = this.tokens.pop();
};
KeypathObserver.prototype.update = function() {
var next, prev;
if ((next = this.realize()) !== this.target) {
prev = this.target;
this.target = next;
return this.callback(this, prev);
}
};
KeypathObserver.prototype.realize = function() {
var current, index, prev, token, _i, _len, _ref;
current = this.model;
_ref = this.tokens;
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
token = _ref[index];
if (this.objectPath[index] != null) {
if (current !== (prev = this.objectPath[index])) {
this.view.adapters[token["interface"]].unsubscribe(prev, token.path, this.update);
this.view.adapters[token["interface"]].subscribe(current, token.path, this.update);
this.objectPath[index] = current;
}
} else {
return el.unbind(event, handler);
this.view.adapters[token["interface"]].subscribe(current, token.path, this.update);
this.objectPath[index] = current;
}
} else if (window.removeEventListener != null) {
return el.removeEventListener(event, handler, false);
current = this.view.adapters[token["interface"]].read(current, token.path);
}
return current;
};
return KeypathObserver;
})();
Rivets.binders.enabled = function(el, value) {
return el.disabled = !value;
};
Rivets.binders.disabled = function(el, value) {
return el.disabled = !!value;
};
Rivets.binders.checked = {
publishes: true,
bind: function(el) {
return Rivets.Util.bindEvent(el, 'change', this.publish);
},
unbind: function(el) {
return Rivets.Util.unbindEvent(el, 'change', this.publish);
},
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 {
event = 'on' + event;
return el.detachEvent(event, handler);
return el.checked = !!value;
}
}
};
Rivets.binders.unchecked = {
publishes: true,
bind: function(el) {
return Rivets.Util.bindEvent(el, 'change', this.publish);
},
getInputValue: function(el) {
var o, _i, _len, _results;
unbind: function(el) {
return Rivets.Util.unbindEvent(el, 'change', this.publish);
},
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 {
return el.checked = !value;
}
}
};
Rivets.binders.show = function(el, value) {
return el.style.display = value ? '' : 'none';
};
Rivets.binders.hide = function(el, value) {
return el.style.display = value ? 'none' : '';
};
Rivets.binders.html = function(el, value) {
return el.innerHTML = value != null ? value : '';
};
Rivets.binders.value = {
publishes: true,
bind: function(el) {
return Rivets.Util.bindEvent(el, 'change', this.publish);
},
unbind: function(el) {
return Rivets.Util.unbindEvent(el, 'change', this.publish);
},
routine: function(el, value) {
var o, _i, _len, _ref, _ref1, _ref2, _results;
if (window.jQuery != null) {
el = jQuery(el);
switch (el[0].type) {
case 'checkbox':
return el.is(':checked');
default:
return el.val();
if ((value != null ? value.toString() : void 0) !== ((_ref = el.val()) != null ? _ref.toString() : void 0)) {
return el.val(value != null ? value : '');
}
} else {
switch (el.type) {
case 'checkbox':
return el.checked;
case 'select-multiple':
if (el.type === 'select-multiple') {
if (value != null) {
_results = [];
for (_i = 0, _len = el.length; _i < _len; _i++) {
o = el[_i];
if (o.selected) {
_results.push(o.value);
}
_results.push(o.selected = (_ref1 = o.value, __indexOf.call(value, _ref1) >= 0));
}
return _results;
break;
default:
return el.value;
}
} else if ((value != null ? value.toString() : void 0) !== ((_ref2 = el.value) != null ? _ref2.toString() : void 0)) {
return el.value = value != null ? value : '';
}
}
}
};
Rivets.binders = {
enabled: function(el, value) {
return el.disabled = !value;
},
disabled: function(el, value) {
return el.disabled = !!value;
},
checked: {
publishes: true,
bind: function(el) {
return Rivets.Util.bindEvent(el, 'change', this.publish);
},
unbind: function(el) {
return Rivets.Util.unbindEvent(el, 'change', this.publish);
},
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 {
return el.checked = !!value;
}
Rivets.binders.text = function(el, value) {
if (el.innerText != null) {
return el.innerText = value != null ? value : '';
} else {
return el.textContent = value != null ? value : '';
}
};
Rivets.binders["if"] = {
block: true,
bind: function(el) {
var attr, declaration;
if (this.marker == null) {
attr = [this.view.config.prefix, this.type].join('-').replace('--', '-');
declaration = el.getAttribute(attr);
this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " ");
el.removeAttribute(attr);
el.parentNode.insertBefore(this.marker, el);
return el.parentNode.removeChild(el);
}
},
unchecked: {
publishes: true,
bind: function(el) {
return Rivets.Util.bindEvent(el, 'change', this.publish);
},
unbind: function(el) {
return Rivets.Util.unbindEvent(el, 'change', this.publish);
},
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);
unbind: function() {
var _ref;
return (_ref = this.nested) != null ? _ref.unbind() : void 0;
},
routine: function(el, value) {
var key, model, models, options, _ref;
if (!!value === (this.nested == null)) {
if (value) {
models = {};
_ref = this.view.models;
for (key in _ref) {
model = _ref[key];
models[key] = model;
}
options = {
binders: this.view.options.binders,
formatters: this.view.options.formatters,
adapters: this.view.options.adapters,
config: this.view.options.config
};
(this.nested = new Rivets.View(el, models, options)).bind();
return this.marker.parentNode.insertBefore(el, this.marker.nextSibling);
} else {
return el.checked = !value;
el.parentNode.removeChild(el);
this.nested.unbind();
return delete this.nested;
}
}
},
show: function(el, value) {
return el.style.display = value ? '' : 'none';
update: function(models) {
var _ref;
return (_ref = this.nested) != null ? _ref.update(models) : void 0;
}
};
Rivets.binders.unless = {
block: true,
bind: function(el) {
return Rivets.binders["if"].bind.call(this, el);
},
hide: function(el, value) {
return el.style.display = value ? 'none' : '';
unbind: function() {
return Rivets.binders["if"].unbind.call(this);
},
html: function(el, value) {
return el.innerHTML = value != null ? value : '';
routine: function(el, value) {
return Rivets.binders["if"].routine.call(this, el, !value);
},
value: {
publishes: true,
bind: function(el) {
return Rivets.Util.bindEvent(el, 'change', this.publish);
},
unbind: function(el) {
return Rivets.Util.unbindEvent(el, 'change', this.publish);
},
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)) {
return el.val(value != null ? value : '');
}
} else {
if (el.type === 'select-multiple') {
if (value != null) {
_results = [];
for (_i = 0, _len = el.length; _i < _len; _i++) {
o = el[_i];
_results.push(o.selected = (_ref1 = o.value, __indexOf.call(value, _ref1) >= 0));
}
return _results;
}
} else if ((value != null ? value.toString() : void 0) !== ((_ref2 = el.value) != null ? _ref2.toString() : void 0)) {
return el.value = value != null ? value : '';
}
}
update: function(models) {
return Rivets.binders["if"].update.call(this, models);
}
};
Rivets.binders['on-*'] = {
"function": true,
unbind: function(el) {
if (this.handler) {
return Rivets.Util.unbindEvent(el, this.args[0], this.handler);
}
},
text: function(el, value) {
if (el.innerText != null) {
return el.innerText = value != null ? value : '';
} else {
return el.textContent = value != null ? value : '';
routine: function(el, value) {
if (this.handler) {
Rivets.Util.unbindEvent(el, this.args[0], this.handler);
}
},
"if": {
block: true,
bind: function(el) {
var attr, declaration;
if (this.marker == null) {
attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-');
declaration = el.getAttribute(attr);
this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " ");
el.removeAttribute(attr);
el.parentNode.insertBefore(this.marker, el);
return el.parentNode.removeChild(el);
}
},
unbind: function() {
var _ref;
return (_ref = this.nested) != null ? _ref.unbind() : void 0;
},
routine: function(el, value) {
var key, model, models, options, _ref;
if (!!value === (this.nested == null)) {
if (value) {
models = {};
_ref = this.view.models;
for (key in _ref) {
model = _ref[key];
models[key] = model;
}
options = {
binders: this.view.options.binders,
formatters: this.view.options.formatters,
config: this.view.options.config
};
(this.nested = new Rivets.View(el, models, options)).bind();
return this.marker.parentNode.insertBefore(el, this.marker.nextSibling);
} else {
el.parentNode.removeChild(el);
this.nested.unbind();
return delete this.nested;
}
}
},
update: function(models) {
var _ref;
return (_ref = this.nested) != null ? _ref.update(models) : void 0;
return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value));
}
};
Rivets.binders['each-*'] = {
block: true,
bind: function(el) {
var attr;
if (this.marker == null) {
attr = [this.view.config.prefix, this.type].join('-').replace('--', '-');
this.marker = document.createComment(" rivets: " + this.type + " ");
this.iterated = [];
el.removeAttribute(attr);
el.parentNode.insertBefore(this.marker, el);
return el.parentNode.removeChild(el);
}
},
unless: {
block: true,
bind: function(el) {
return Rivets.binders["if"].bind.call(this, el);
},
unbind: function() {
return Rivets.binders["if"].unbind.call(this);
},
routine: function(el, value) {
return Rivets.binders["if"].routine.call(this, el, !value);
},
update: function(models) {
return Rivets.binders["if"].update.call(this, models);
unbind: function(el) {
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;
}
},
"on-*": {
"function": true,
unbind: function(el) {
if (this.handler) {
return Rivets.Util.unbindEvent(el, this.args[0], this.handler);
}
},
routine: function(el, value) {
if (this.handler) {
Rivets.Util.unbindEvent(el, this.args[0], this.handler);
routine: function(el, collection) {
var binding, data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _results;
modelName = this.args[0];
collection = collection || [];
if (this.iterated.length > collection.length) {
_ref = Array(this.iterated.length - collection.length);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
view = this.iterated.pop();
view.unbind();
this.marker.parentNode.removeChild(view.els[0]);
}
return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value));
}
},
"each-*": {
block: true,
bind: function(el) {
var attr;
if (this.marker == null) {
attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-');
this.marker = document.createComment(" rivets: " + this.type + " ");
this.iterated = [];
el.removeAttribute(attr);
el.parentNode.insertBefore(this.marker, el);
return el.parentNode.removeChild(el);
}
},
unbind: function(el) {
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());
for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) {
model = collection[index];
data = {};
data[modelName] = model;
if (this.iterated[index] == null) {
_ref1 = this.view.models;
for (key in _ref1) {
model = _ref1[key];
if (data[key] == null) {
data[key] = model;
}
}
return _results;
}
},
routine: function(el, collection) {
var data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results;
modelName = this.args[0];
collection = collection || [];
if (this.iterated.length > collection.length) {
_ref = Array(this.iterated.length - collection.length);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
view = this.iterated.pop();
view.unbind();
this.marker.parentNode.removeChild(view.els[0]);
previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker;
options = {
binders: this.view.options.binders,
formatters: this.view.options.formatters,
adapters: this.view.options.adapters,
config: {}
};
_ref2 = this.view.options.config;
for (k in _ref2) {
v = _ref2[k];
options.config[k] = v;
}
options.config.preloadData = true;
template = el.cloneNode(true);
view = new Rivets.View(template, data, options);
view.bind();
this.iterated.push(view);
this.marker.parentNode.insertBefore(template, previous.nextSibling);
} else if (this.iterated[index].models[modelName] !== model) {
this.iterated[index].update(data);
}
}
if (el.nodeName === 'OPTION') {
_ref3 = this.view.bindings;
_results = [];
for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) {
model = collection[index];
data = {};
data[modelName] = model;
if (this.iterated[index] == null) {
_ref1 = this.view.models;
for (key in _ref1) {
model = _ref1[key];
if (data[key] == null) {
data[key] = model;
}
}
previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker;
options = {
binders: this.view.options.binders,
formatters: this.view.options.formatters,
config: {}
};
_ref2 = this.view.options.config;
for (k in _ref2) {
v = _ref2[k];
options.config[k] = v;
}
options.config.preloadData = true;
template = el.cloneNode(true);
view = new Rivets.View(template, data, options);
view.bind();
this.iterated.push(view);
_results.push(this.marker.parentNode.insertBefore(template, previous.nextSibling));
} else if (this.iterated[index].models[modelName] !== model) {
_results.push(this.iterated[index].update(data));
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
binding = _ref3[_k];
if (binding.el === this.marker.parentNode && binding.type === 'value') {
_results.push(binding.sync());
} else {
_results.push(void 0);
}
}
return _results;
},
update: function(models) {
var data, key, model, view, _i, _len, _ref, _results;
data = {};
for (key in models) {
model = models[key];
if (key !== this.args[0]) {
data[key] = model;
}
}
_ref = this.iterated;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
view = _ref[_i];
_results.push(view.update(data));
}
return _results;
}
},
"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();
update: function(models) {
var data, key, model, view, _i, _len, _ref, _results;
data = {};
for (key in models) {
model = models[key];
if (key !== this.args[0]) {
data[key] = model;
}
}
},
"*": function(el, value) {
if (value) {
return el.setAttribute(this.type, value);
} else {
return el.removeAttribute(this.type);
_ref = this.iterated;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
view = _ref[_i];
_results.push(view.update(data));
}
return _results;
}
};
Rivets.components = {};
Rivets.binders['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();
}
};
Rivets.config = {
preloadData: true,
handler: function(context, ev, binding) {
return this.call(context, ev, binding.view.models);
Rivets.binders['*'] = function(el, value) {
if (value) {
return el.setAttribute(this.type, value);
} else {
return el.removeAttribute(this.type);
}
};
Rivets.formatters = {};
Rivets.adapters['.'] = {
id: '_rv',
counter: 0,
weakmap: {},
weakReference: function(obj) {
var id;
if (obj[this.id] == null) {
id = this.counter++;
this.weakmap[id] = {
callbacks: {}
};
Object.defineProperty(obj, this.id, {
value: id
});
}
return this.weakmap[obj[this.id]];
},
stubFunction: function(obj, fn) {
var map, original, weakmap;
original = obj[fn];
map = this.weakReference(obj);
weakmap = this.weakmap;
return obj[fn] = function() {
var callback, k, r, response, _i, _len, _ref, _ref1, _ref2, _ref3;
response = original.apply(obj, arguments);
_ref = map.pointers;
for (r in _ref) {
k = _ref[r];
_ref3 = (_ref1 = (_ref2 = weakmap[r]) != null ? _ref2.callbacks[k] : void 0) != null ? _ref1 : [];
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
callback = _ref3[_i];
callback();
}
}
return response;
};
},
observeMutations: function(obj, ref, keypath) {
var fn, functions, map, _base, _i, _len;
if (Array.isArray(obj)) {
map = this.weakReference(obj);
if (map.pointers == null) {
map.pointers = {};
functions = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice'];
for (_i = 0, _len = functions.length; _i < _len; _i++) {
fn = functions[_i];
this.stubFunction(obj, fn);
}
}
if ((_base = map.pointers)[ref] == null) {
_base[ref] = [];
}
if (__indexOf.call(map.pointers[ref], keypath) < 0) {
return map.pointers[ref].push(keypath);
}
}
},
unobserveMutations: function(obj, ref, keypath) {
var keypaths, _ref;
if (Array.isArray(obj && (obj[this.id] != null))) {
if (keypaths = (_ref = this.weakReference(obj).pointers) != null ? _ref[ref] : void 0) {
return keypaths.splice(keypaths.indexOf(keypath), 1);
}
}
},
subscribe: function(obj, keypath, callback) {
var callbacks, value,
_this = this;
callbacks = this.weakReference(obj).callbacks;
if (callbacks[keypath] == null) {
callbacks[keypath] = [];
value = obj[keypath];
Object.defineProperty(obj, keypath, {
get: function() {
return value;
},
set: function(newValue) {
var _i, _len, _ref;
if (newValue !== value) {
value = newValue;
_ref = callbacks[keypath];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
callback = _ref[_i];
callback();
}
return _this.observeMutations(newValue, obj[_this.id], keypath);
}
}
});
}
if (__indexOf.call(callbacks[keypath], callback) < 0) {
callbacks[keypath].push(callback);
}
return this.observeMutations(obj[keypath], obj[this.id], keypath);
},
unsubscribe: function(obj, keypath, callback) {
var callbacks;
callbacks = this.weakmap[obj[this.id]].callbacks[keypath];
callbacks.splice(callbacks.indexOf(callback), 1);
return this.unobserveMutations(obj[keypath], obj[this.id], keypath);
},
read: function(obj, keypath) {
return obj[keypath];
},
publish: function(obj, keypath, value) {
return obj[keypath] = value;
}
};
Rivets.factory = function(exports) {
exports._ = Rivets;
exports.binders = Rivets.binders;
exports.components = Rivets.components;
exports.formatters = Rivets.formatters;
exports.adapters = Rivets.adapters;
exports.config = Rivets.config;
exports.configure = function(options) {
var property, value;
......
// Rivets.js
// version: 0.5.13
// version: 0.6.0
// author: Michael Richards
// license: MIT
!function(){var a,b,c=function(a,b){return function(){return a.apply(b,arguments)}},d=[].slice,e={}.hasOwnProperty,f=function(a,b){function c(){this.constructor=a}for(var d in b)e.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},g=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};a={},b=window.jQuery||window.Zepto,String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),a.Binding=function(){function b(a,b,d,e,f,g){var h,i,j,k;if(this.view=a,this.el=b,this.type=d,this.key=e,this.keypath=f,this.options=null!=g?g:{},this.update=c(this.update,this),this.unbind=c(this.unbind,this),this.bind=c(this.bind,this),this.publish=c(this.publish,this),this.sync=c(this.sync,this),this.set=c(this.set,this),this.eventHandler=c(this.eventHandler,this),this.formattedValue=c(this.formattedValue,this),!(this.binder=this.view.binders[d])){k=this.view.binders;for(h in k)j=k[h],"*"!==h&&-1!==h.indexOf("*")&&(i=new RegExp("^"+h.replace("*",".+")+"$"),i.test(d)&&(this.binder=j,this.args=new RegExp("^"+h.replace("*","(.+)")+"$").exec(d),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.key?this.view.models[this.key]:this.view.models}return b.prototype.formattedValue=function(a){var b,c,e,f,g,h;for(h=this.formatters,f=0,g=h.length;g>f;f++)c=h[f],b=c.split(/\s+/),e=b.shift(),c=this.model[e]instanceof Function?this.model[e]:this.view.formatters[e],(null!=c?c.read:void 0)instanceof Function?a=c.read.apply(c,[a].concat(d.call(b))):c instanceof Function&&(a=c.apply(null,[a].concat(d.call(b))));return a},b.prototype.eventHandler=function(a){var b,c;return c=(b=this).view.config.handler,function(d){return c.call(a,this,d,b)}},b.prototype.set=function(a){var b;return a=a instanceof Function&&!this.binder["function"]?this.formattedValue(a.call(this.model)):this.formattedValue(a),null!=(b=this.binder.routine)?b.call(this,this.el,a):void 0},b.prototype.sync=function(){return this.set(this.options.bypass?this.model[this.keypath]:this.view.config.adapter.read(this.model,this.keypath))},b.prototype.publish=function(){var b,c,e,f,g,h,i,j,k;for(f=a.Util.getInputValue(this.el),i=this.formatters.slice(0).reverse(),g=0,h=i.length;h>g;g++)c=i[g],b=c.split(/\s+/),e=b.shift(),(null!=(j=this.view.formatters[e])?j.publish:void 0)&&(f=(k=this.view.formatters[e]).publish.apply(k,[f].concat(d.call(b))));return this.view.config.adapter.publish(this.model,this.keypath,f)},b.prototype.bind=function(){var a,b,c,d,e,f,g,h,i;if(null!=(f=this.binder.bind)&&f.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!=(g=this.options.dependencies)?g.length:void 0){for(h=this.options.dependencies,i=[],d=0,e=h.length;e>d;d++)a=h[d],/^\./.test(a)?(c=this.model,b=a.substr(1)):(a=a.split("."),c=this.view.models[a.shift()],b=a.join(".")),i.push(this.view.config.adapter.subscribe(c,b,this.sync));return i}},b.prototype.unbind=function(){var a,b,c,d,e,f,g,h,i;if(null!=(f=this.binder.unbind)&&f.call(this,this.el),this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),null!=(g=this.options.dependencies)?g.length:void 0){for(h=this.options.dependencies,i=[],d=0,e=h.length;e>d;d++)a=h[d],/^\./.test(a)?(c=this.model,b=a.substr(1)):(a=a.split("."),c=this.view.models[a.shift()],b=a.join(".")),i.push(this.view.config.adapter.unsubscribe(c,b,this.sync));return i}},b.prototype.update=function(a){var b;return null==a&&(a={}),this.key?a[this.key]&&(this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),this.model=a[this.key],this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync())):this.sync(),null!=(b=this.binder.update)?b.call(this,a):void 0},b}(),a.ComponentBinding=function(b){function d(b,d,e){var f,h,i,j,k;for(this.view=b,this.el=d,this.type=e,this.unbind=c(this.unbind,this),this.bind=c(this.bind,this),this.update=c(this.update,this),this.locals=c(this.locals,this),this.component=a.components[this.type],this.attributes={},this.inflections={},j=this.el.attributes||[],h=0,i=j.length;i>h;h++)f=j[h],k=f.name,g.call(this.component.attributes,k)>=0?this.attributes[f.name]=f.value:this.inflections[f.name]=f.value}return f(d,b),d.prototype.sync=function(){},d.prototype.locals=function(a){var b,c,d,e,f,g,h,i,j;null==a&&(a=this.view.models),f={},i=this.inflections;for(c in i)for(b=i[c],j=b.split("."),g=0,h=j.length;h>g;g++)e=j[g],f[c]=(f[c]||a)[e];for(c in a)d=a[c],null==f[c]&&(f[c]=d);return f},d.prototype.update=function(a){var b;return null!=(b=this.componentView)?b.update(this.locals(a)):void 0},d.prototype.bind=function(){var b,c;return null!=this.componentView?null!=(c=this.componentView)?c.bind():void 0:(b=this.component.build.call(this.attributes),(this.componentView=new a.View(b,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(b,this.el))},d.prototype.unbind=function(){var a;return null!=(a=this.componentView)?a.unbind():void 0},d}(a.Binding),a.TextBinding=function(a){function b(a,b,d,e,f,g){this.view=a,this.el=b,this.type=d,this.key=e,this.keypath=f,this.options=null!=g?g:{},this.sync=c(this.sync,this),this.formatters=this.options.formatters||[],this.model=this.key?this.view.models[this.key]:this.view.models}return f(b,a),b.prototype.binder={routine:function(a,b){return a.data=null!=b?b:""}},b.prototype.sync=function(){return b.__super__.sync.apply(this,arguments)},b}(a.Binding),a.View=function(){function b(b,d,e){var f,g,h,i,j,k,l,m,n;for(this.els=b,this.models=d,this.options=null!=e?e:{},this.update=c(this.update,this),this.publish=c(this.publish,this),this.sync=c(this.sync,this),this.unbind=c(this.unbind,this),this.bind=c(this.bind,this),this.select=c(this.select,this),this.build=c(this.build,this),this.componentRegExp=c(this.componentRegExp,this),this.bindingRegExp=c(this.bindingRegExp,this),"undefined"==typeof this.els.length&&(this.els=[this.els]),l=["config","binders","formatters"],j=0,k=l.length;k>j;j++){if(g=l[j],this[g]={},this.options[g]){m=this.options[g];for(f in m)h=m[f],this[g][f]=h}n=a[g];for(f in n)h=n[f],null==(i=this[g])[f]&&(i[f]=h)}this.build()}return b.prototype.bindingRegExp=function(){var a;return a=this.config.prefix,a?new RegExp("^data-"+a+"-"):/^data-/},b.prototype.componentRegExp=function(){var a,b;return new RegExp("^"+(null!=(a=null!=(b=this.config.prefix)?b.toUpperCase():void 0)?a:"RV")+"-")},b.prototype.build=function(){var b,c,e,f,h,i,j,k,l,m=this;for(this.bindings=[],i=[],b=this.bindingRegExp(),e=this.componentRegExp(),c=function(b,c,d,e){var f,g,h,i,j,k,l,n,o,p;return k={},o=function(){var a,b,c,d;for(c=e.split("|"),d=[],a=0,b=c.length;b>a;a++)n=c[a],d.push(n.trim());return d}(),f=function(){var a,b,c,d;for(c=o.shift().split("<"),d=[],a=0,b=c.length;b>a;a++)g=c[a],d.push(g.trim());return d}(),l=f.shift(),p=l.split(/\.|:/),k.formatters=o,k.bypass=-1!==l.indexOf(":"),p[0]?i=p.shift():(i=null,p.shift()),j=p.join("."),(h=f.shift())&&(k.dependencies=h.split(/\s+/)),m.bindings.push(new a[b](m,c,d,i,j,k))},h=function(f){var j,k,l,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;if(g.call(i,f)<0){if(f.nodeType===Node.TEXT_NODE){if(r=a.TextTemplateParser,(o=m.config.templateDelimiters)&&(x=r.parse(f.data,o)).length&&(1!==x.length||x[0].type!==r.types.text))for(u=x[0],t=2<=x.length?d.call(x,1):[],f.data=u.value,0===u.type?f.data=u.value:c("TextBinding",f,null,u.value),A=0,E=t.length;E>A;A++)w=t[A],v=document.createTextNode(w.value),f.parentNode.appendChild(v),1===w.type&&c("TextBinding",v,null,w.value)}else if(e.test(f.tagName))y=f.tagName.replace(e,"").toLowerCase(),m.bindings.push(new a.ComponentBinding(m,f,y));else if(null!=f.attributes){for(K=f.attributes,B=0,F=K.length;F>B;B++)if(j=K[B],b.test(j.name)){if(y=j.name.replace(b,""),!(l=m.binders[y])){L=m.binders;for(p in L)z=L[p],"*"!==p&&-1!==p.indexOf("*")&&(s=new RegExp("^"+p.replace("*",".+")+"$"),s.test(y)&&(l=z))}if(l||(l=m.binders["*"]),l.block){for(M=f.childNodes,C=0,G=M.length;G>C;C++)q=M[C],i.push(q);k=[j]}}for(N=k||f.attributes,D=0,H=N.length;H>D;D++)j=N[D],b.test(j.name)&&(y=j.name.replace(b,""),c("Binding",f,y,j.value))}for(O=f.childNodes,P=[],J=0,I=O.length;I>J;J++)n=O[J],P.push(h(n));return P}},l=this.els,j=0,k=l.length;k>j;j++)f=l[j],h(f)},b.prototype.select=function(a){var b,c,d,e,f;for(e=this.bindings,f=[],c=0,d=e.length;d>c;c++)b=e[c],a(b)&&f.push(b);return f},b.prototype.bind=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.bind());return e},b.prototype.unbind=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.unbind());return e},b.prototype.sync=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.sync());return e},b.prototype.publish=function(){var a,b,c,d,e;for(d=this.select(function(a){return a.binder.publishes}),e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.publish());return e},b.prototype.update=function(a){var b,c,d,e,f,g,h;null==a&&(a={});for(c in a)d=a[c],this.models[c]=d;for(g=this.bindings,h=[],e=0,f=g.length;f>e;e++)b=g[e],h.push(b.update(a));return h},b}(),a.TextTemplateParser=function(){function a(){}return a.types={text:0,binding:1},a.parse=function(a,b){var c,d,e,f,g,h,i;for(h=[],f=a.length,c=0,d=0;f>d;){if(c=a.indexOf(b[0],d),0>c){h.push({type:this.types.text,value:a.slice(d)});break}if(c>0&&c>d&&h.push({type:this.types.text,value:a.slice(d,c)}),d=c+2,c=a.indexOf(b[1],d),0>c){g=a.slice(d-2),e=h[h.length-1],(null!=e?e.type:void 0)===this.types.text?e.value+=g:h.push({type:this.types.text,value:g});break}i=a.slice(d,c).trim(),h.push({type:this.types.binding,value:i}),d=c+2}return h},a}(),a.Util={bindEvent:function(a,c,d){return null!=window.jQuery?(a=b(a),null!=a.on?a.on(c,d):a.bind(c,d)):null!=window.addEventListener?a.addEventListener(c,d,!1):(c="on"+c,a.attachEvent(c,d))},unbindEvent:function(a,c,d){return null!=window.jQuery?(a=b(a),null!=a.off?a.off(c,d):a.unbind(c,d)):null!=window.removeEventListener?a.removeEventListener(c,d,!1):(c="on"+c,a.detachEvent(c,d))},getInputValue:function(a){var c,d,e,f;if(null!=window.jQuery)switch(a=b(a),a[0].type){case"checkbox":return a.is(":checked");default:return a.val()}else switch(a.type){case"checkbox":return a.checked;case"select-multiple":for(f=[],d=0,e=a.length;e>d;d++)c=a[d],c.selected&&f.push(c.value);return f;default:return a.value}}},a.binders={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:{publishes:!0,bind:function(b){return a.Util.bindEvent(b,"change",this.publish)},unbind:function(b){return a.Util.unbindEvent(b,"change",this.publish)},routine:function(a,b){var c;return a.checked="radio"===a.type?(null!=(c=a.value)?c.toString():void 0)===(null!=b?b.toString():void 0):!!b}},unchecked:{publishes:!0,bind:function(b){return a.Util.bindEvent(b,"change",this.publish)},unbind:function(b){return a.Util.unbindEvent(b,"change",this.publish)},routine:function(a,b){var c;return a.checked="radio"===a.type?(null!=(c=a.value)?c.toString():void 0)!==(null!=b?b.toString():void 0):!b}},show:function(a,b){return a.style.display=b?"":"none"},hide:function(a,b){return a.style.display=b?"none":""},html:function(a,b){return a.innerHTML=null!=b?b:""},value:{publishes:!0,bind:function(b){return a.Util.bindEvent(b,"change",this.publish)},unbind:function(b){return a.Util.unbindEvent(b,"change",this.publish)},routine:function(a,c){var d,e,f,h,i,j,k;if(null!=window.jQuery){if(a=b(a),(null!=c?c.toString():void 0)!==(null!=(h=a.val())?h.toString():void 0))return a.val(null!=c?c:"")}else if("select-multiple"===a.type){if(null!=c){for(k=[],e=0,f=a.length;f>e;e++)d=a[e],k.push(d.selected=(i=d.value,g.call(c,i)>=0));return k}}else if((null!=c?c.toString():void 0)!==(null!=(j=a.value)?j.toString():void 0))return a.value=null!=c?c:""}},text:function(a,b){return null!=a.innerText?a.innerText=null!=b?b:"":a.textContent=null!=b?b:""},"if":{block:!0,bind:function(a){var b,c;return null==this.marker?(b=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),c=a.getAttribute(b),this.marker=document.createComment(" rivets: "+this.type+" "+c+" "),a.removeAttribute(b),a.parentNode.insertBefore(this.marker,a),a.parentNode.removeChild(a)):void 0},unbind:function(){var a;return null!=(a=this.nested)?a.unbind():void 0},routine:function(b,c){var d,e,f,g,h;if(!!c==(null==this.nested)){if(c){f={},h=this.view.models;for(d in h)e=h[d],f[d]=e;return g={binders:this.view.options.binders,formatters:this.view.options.formatters,config:this.view.options.config},(this.nested=new a.View(b,f,g)).bind(),this.marker.parentNode.insertBefore(b,this.marker.nextSibling)}return b.parentNode.removeChild(b),this.nested.unbind(),delete this.nested}},update:function(a){var b;return null!=(b=this.nested)?b.update(a):void 0}},unless:{block:!0,bind:function(b){return a.binders["if"].bind.call(this,b)},unbind:function(){return a.binders["if"].unbind.call(this)},routine:function(b,c){return a.binders["if"].routine.call(this,b,!c)},update:function(b){return a.binders["if"].update.call(this,b)}},"on-*":{"function":!0,unbind:function(b){return this.handler?a.Util.unbindEvent(b,this.args[0],this.handler):void 0},routine:function(b,c){return this.handler&&a.Util.unbindEvent(b,this.args[0],this.handler),a.Util.bindEvent(b,this.args[0],this.handler=this.eventHandler(c))}},"each-*":{block:!0,bind:function(a){var b;return null==this.marker?(b=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],a.removeAttribute(b),a.parentNode.insertBefore(this.marker,a),a.parentNode.removeChild(a)):void 0},unbind:function(){var a,b,c,d,e;if(null!=this.iterated){for(d=this.iterated,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.unbind());return e}},routine:function(b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w;if(j=this.args[0],c=c||[],this.iterated.length>c.length)for(t=Array(this.iterated.length-c.length),p=0,r=t.length;r>p;p++)e=t[p],o=this.iterated.pop(),o.unbind(),this.marker.parentNode.removeChild(o.els[0]);for(w=[],f=q=0,s=c.length;s>q;f=++q)if(i=c[f],d={},d[j]=i,null==this.iterated[f]){u=this.view.models;for(h in u)i=u[h],null==d[h]&&(d[h]=i);l=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,k={binders:this.view.options.binders,formatters:this.view.options.formatters,config:{}},v=this.view.options.config;for(g in v)n=v[g],k.config[g]=n;k.config.preloadData=!0,m=b.cloneNode(!0),o=new a.View(m,d,k),o.bind(),this.iterated.push(o),w.push(this.marker.parentNode.insertBefore(m,l.nextSibling))}else this.iterated[f].models[j]!==i?w.push(this.iterated[f].update(d)):w.push(void 0);return w},update:function(a){var b,c,d,e,f,g,h,i;b={};for(c in a)d=a[c],c!==this.args[0]&&(b[c]=d);for(h=this.iterated,i=[],f=0,g=h.length;g>f;f++)e=h[f],i.push(e.update(b));return i}},"class-*":function(a,b){var c;return c=" "+a.className+" ",!b==(-1!==c.indexOf(" "+this.args[0]+" "))?a.className=b?""+a.className+" "+this.args[0]:c.replace(" "+this.args[0]+" "," ").trim():void 0},"*":function(a,b){return b?a.setAttribute(this.type,b):a.removeAttribute(this.type)}},a.components={},a.config={preloadData:!0,handler:function(a,b,c){return this.call(a,b,c.view.models)}},a.formatters={},a.factory=function(b){return b._=a,b.binders=a.binders,b.components=a.components,b.formatters=a.formatters,b.config=a.config,b.configure=function(b){var c,d;null==b&&(b={});for(c in b)d=b[c],a.config[c]=d},b.bind=function(b,c,d){var e;return null==c&&(c={}),null==d&&(d={}),e=new a.View(b,c,d),e.bind(),e}},"object"==typeof exports?a.factory(exports):"function"==typeof define&&define.amd?define(["exports"],function(b){return a.factory(this.rivets=b),b}):a.factory(this.rivets={})}.call(this);
\ No newline at end of file
(function(){var a,b,c=function(a,b){return function(){return a.apply(b,arguments)}},d=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},e=[].slice,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};b={binders:{},components:{},formatters:{},adapters:{},config:{prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,handler:function(a,b,c){return this.call(a,b,c.view.models)}}},b.Util={bindEvent:function(a,b,c){return null!=window.jQuery?(a=jQuery(a),null!=a.on?a.on(b,c):a.bind(b,c)):null!=window.addEventListener?a.addEventListener(b,c,!1):(b="on"+b,a.attachEvent(b,c))},unbindEvent:function(a,b,c){return null!=window.jQuery?(a=jQuery(a),null!=a.off?a.off(b,c):a.unbind(b,c)):null!=window.removeEventListener?a.removeEventListener(b,c,!1):(b="on"+b,a.detachEvent(b,c))},getInputValue:function(a){var b,c,d,e;if(null!=window.jQuery)switch(a=jQuery(a),a[0].type){case"checkbox":return a.is(":checked");default:return a.val()}else switch(a.type){case"checkbox":return a.checked;case"select-multiple":for(e=[],c=0,d=a.length;d>c;c++)b=a[c],b.selected&&e.push(b.value);return e;default:return a.value}}},b.View=function(){function a(a,d,e){var f,g,h,i,j,k,l,m,n;for(this.els=a,this.models=d,this.options=null!=e?e:{},this.update=c(this.update,this),this.publish=c(this.publish,this),this.sync=c(this.sync,this),this.unbind=c(this.unbind,this),this.bind=c(this.bind,this),this.select=c(this.select,this),this.build=c(this.build,this),this.componentRegExp=c(this.componentRegExp,this),this.bindingRegExp=c(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),l=["config","binders","formatters","adapters"],j=0,k=l.length;k>j;j++){if(g=l[j],this[g]={},this.options[g]){m=this.options[g];for(f in m)h=m[f],this[g][f]=h}n=b[g];for(f in n)h=n[f],null==(i=this[g])[f]&&(i[f]=h)}this.build()}return a.prototype.bindingRegExp=function(){return new RegExp("^"+this.config.prefix+"-")},a.prototype.componentRegExp=function(){return new RegExp("^"+this.config.prefix.toUpperCase()+"-")},a.prototype.build=function(){var a,c,f,g,h,i,j,k,l,m=this;for(this.bindings=[],i=[],a=this.bindingRegExp(),f=this.componentRegExp(),c=function(a,c,d,e){var f,g,h,i,j,k,l;return j={},l=function(){var a,b,c,d;for(c=e.split("|"),d=[],a=0,b=c.length;b>a;a++)k=c[a],d.push(k.trim());return d}(),f=function(){var a,b,c,d;for(c=l.shift().split("<"),d=[],a=0,b=c.length;b>a;a++)g=c[a],d.push(g.trim());return d}(),i=f.shift(),j.formatters=l,(h=f.shift())&&(j.dependencies=h.split(/\s+/)),m.bindings.push(new b[a](m,c,d,i,j))},h=function(g){var j,k,l,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;if(d.call(i,g)<0){if(g.nodeType===Node.TEXT_NODE){if(r=b.TextTemplateParser,(o=m.config.templateDelimiters)&&(x=r.parse(g.data,o)).length&&(1!==x.length||x[0].type!==r.types.text))for(u=x[0],t=2<=x.length?e.call(x,1):[],g.data=u.value,0===u.type?g.data=u.value:c("TextBinding",g,null,u.value),A=0,E=t.length;E>A;A++)w=t[A],v=document.createTextNode(w.value),g.parentNode.appendChild(v),1===w.type&&c("TextBinding",v,null,w.value)}else if(f.test(g.tagName))y=g.tagName.replace(f,"").toLowerCase(),m.bindings.push(new b.ComponentBinding(m,g,y));else if(null!=g.attributes){for(K=g.attributes,B=0,F=K.length;F>B;B++)if(j=K[B],a.test(j.name)){if(y=j.name.replace(a,""),!(l=m.binders[y])){L=m.binders;for(p in L)z=L[p],"*"!==p&&-1!==p.indexOf("*")&&(s=new RegExp("^"+p.replace("*",".+")+"$"),s.test(y)&&(l=z))}if(l||(l=m.binders["*"]),l.block){for(M=g.childNodes,C=0,G=M.length;G>C;C++)q=M[C],i.push(q);k=[j]}}for(N=k||g.attributes,D=0,H=N.length;H>D;D++)j=N[D],a.test(j.name)&&(y=j.name.replace(a,""),c("Binding",g,y,j.value))}for(O=g.childNodes,P=[],J=0,I=O.length;I>J;J++)n=O[J],P.push(h(n));return P}},l=this.els,j=0,k=l.length;k>j;j++)g=l[j],h(g)},a.prototype.select=function(a){var b,c,d,e,f;for(e=this.bindings,f=[],c=0,d=e.length;d>c;c++)b=e[c],a(b)&&f.push(b);return f},a.prototype.bind=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.bind());return e},a.prototype.unbind=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.unbind());return e},a.prototype.sync=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.sync());return e},a.prototype.publish=function(){var a,b,c,d,e;for(d=this.select(function(a){return a.binder.publishes}),e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.publish());return e},a.prototype.update=function(a){var b,c,d,e,f,g,h;null==a&&(a={});for(c in a)d=a[c],this.models[c]=d;for(g=this.bindings,h=[],e=0,f=g.length;f>e;e++)b=g[e],h.push(b.update(a));return h},a}(),b.Binding=function(){function d(a,b,d,e,f){this.view=a,this.el=b,this.type=d,this.keypath=e,this.options=null!=f?f:{},this.update=c(this.update,this),this.unbind=c(this.unbind,this),this.bind=c(this.bind,this),this.publish=c(this.publish,this),this.sync=c(this.sync,this),this.set=c(this.set,this),this.eventHandler=c(this.eventHandler,this),this.formattedValue=c(this.formattedValue,this),this.setObserver=c(this.setObserver,this),this.setBinder=c(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.setBinder(),this.setObserver()}return d.prototype.setBinder=function(){var a,b,c,d;if(!(this.binder=this.view.binders[this.type])){d=this.view.binders;for(a in d)c=d[a],"*"!==a&&-1!==a.indexOf("*")&&(b=new RegExp("^"+a.replace("*",".+")+"$"),b.test(this.type)&&(this.binder=c,this.args=new RegExp("^"+a.replace("*","(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},d.prototype.setObserver=function(){var b=this;return this.observer=new a(this.view,this.view.models,this.keypath,function(a){return b.key&&b.unbind(!0),b.model=a.target,b.key&&b.bind(!0),b.sync()}),this.key=this.observer.key,this.model=this.observer.target},d.prototype.formattedValue=function(a){var b,c,d,f,g,h;for(h=this.formatters,f=0,g=h.length;g>f;f++)c=h[f],b=c.split(/\s+/),d=b.shift(),c=this.view.formatters[d],(null!=c?c.read:void 0)instanceof Function?a=c.read.apply(c,[a].concat(e.call(b))):c instanceof Function&&(a=c.apply(null,[a].concat(e.call(b))));return a},d.prototype.eventHandler=function(a){var b,c;return c=(b=this).view.config.handler,function(d){return c.call(a,this,d,b)}},d.prototype.set=function(a){var b;return a=a instanceof Function&&!this.binder["function"]?this.formattedValue(a.call(this.model)):this.formattedValue(a),null!=(b=this.binder.routine)?b.call(this,this.el,a):void 0},d.prototype.sync=function(){return this.set(this.key?this.view.adapters[this.key["interface"]].read(this.model,this.key.path):this.model)},d.prototype.publish=function(){var a,c,d,f,g,h,i,j,k;for(f=b.Util.getInputValue(this.el),i=this.formatters.slice(0).reverse(),g=0,h=i.length;h>g;g++)c=i[g],a=c.split(/\s+/),d=a.shift(),(null!=(j=this.view.formatters[d])?j.publish:void 0)&&(f=(k=this.view.formatters[d]).publish.apply(k,[f].concat(e.call(a))));return this.view.adapters[this.key["interface"]].publish(this.model,this.key.path,f)},d.prototype.bind=function(b){var c,d,e,f,g,h,i,j,k,l=this;if(null==b&&(b=!1),b||null!=(h=this.binder.bind)&&h.call(this,this.el),this.key&&this.view.adapters[this.key["interface"]].subscribe(this.model,this.key.path,this.sync),(b?void 0:this.view.config.preloadData)&&this.sync(),null!=(i=this.options.dependencies)?i.length:void 0){for(j=this.options.dependencies,k=[],f=0,g=j.length;g>f;f++)c=j[f],e=new a(this.view,this.model,c,function(a,b){var c;return c=a.key,l.view.adapters[c["interface"]].unsubscribe(b,c.path,l.sync),l.view.adapters[c["interface"]].subscribe(a.target,c.path,l.sync),l.sync()}),d=e.key,this.view.adapters[d["interface"]].subscribe(e.target,d.path,this.sync),k.push(this.dependencies.push(e));return k}},d.prototype.unbind=function(a){var b,c,d,e,f,g;if(null==a&&(a=!1),a||null!=(f=this.binder.unbind)&&f.call(this,this.el),this.key&&this.view.adapters[this.key["interface"]].unsubscribe(this.model,this.key.path,this.sync),this.dependencies.length){for(g=this.dependencies,d=0,e=g.length;e>d;d++)c=g[d],b=c.key,this.view.adapters[b["interface"]].unsubscribe(c.target,b.path,this.sync);return this.dependencies=[]}},d.prototype.update=function(a){var b;return null==a&&(a={}),null!=(b=this.binder.update)?b.call(this,a):void 0},d}(),b.ComponentBinding=function(a){function e(a,e,f){var g,h,i,j,k;for(this.view=a,this.el=e,this.type=f,this.unbind=c(this.unbind,this),this.bind=c(this.bind,this),this.update=c(this.update,this),this.locals=c(this.locals,this),this.component=b.components[this.type],this.attributes={},this.inflections={},j=this.el.attributes||[],h=0,i=j.length;i>h;h++)g=j[h],k=g.name,d.call(this.component.attributes,k)>=0?this.attributes[g.name]=g.value:this.inflections[g.name]=g.value}return g(e,a),e.prototype.sync=function(){},e.prototype.locals=function(a){var b,c,d,e,f,g,h,i,j;null==a&&(a=this.view.models),f={},i=this.inflections;for(c in i)for(b=i[c],j=b.split("."),g=0,h=j.length;h>g;g++)e=j[g],f[c]=(f[c]||a)[e];for(c in a)d=a[c],null==f[c]&&(f[c]=d);return f},e.prototype.update=function(a){var b;return null!=(b=this.componentView)?b.update(this.locals(a)):void 0},e.prototype.bind=function(){var a,c;return null!=this.componentView?null!=(c=this.componentView)?c.bind():void 0:(a=this.component.build.call(this.attributes),(this.componentView=new b.View(a,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(a,this.el))},e.prototype.unbind=function(){var a;return null!=(a=this.componentView)?a.unbind():void 0},e}(b.Binding),b.TextBinding=function(a){function b(a,b,d,e,f){this.view=a,this.el=b,this.type=d,this.keypath=e,this.options=null!=f?f:{},this.sync=c(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.setObserver()}return g(b,a),b.prototype.binder={routine:function(a,b){return a.data=null!=b?b:""}},b.prototype.sync=function(){return b.__super__.sync.apply(this,arguments)},b}(b.Binding),b.KeypathParser=function(){function a(){}return a.parse=function(a,b,c){var e,f,g,h;h=[],f={"interface":c,path:""};for(g in a)e=a[g],d.call(b,e)>=0?(h.push(f),f={"interface":e,path:""}):f.path+=e;return h.push(f),h},a}(),b.TextTemplateParser=function(){function a(){}return a.types={text:0,binding:1},a.parse=function(a,b){var c,d,e,f,g,h,i;for(h=[],f=a.length,c=0,d=0;f>d;){if(c=a.indexOf(b[0],d),0>c){h.push({type:this.types.text,value:a.slice(d)});break}if(c>0&&c>d&&h.push({type:this.types.text,value:a.slice(d,c)}),d=c+2,c=a.indexOf(b[1],d),0>c){g=a.slice(d-2),e=h[h.length-1],(null!=e?e.type:void 0)===this.types.text?e.value+=g:h.push({type:this.types.text,value:g});break}i=a.slice(d,c).trim(),h.push({type:this.types.binding,value:i}),d=c+2}return h},a}(),a=function(){function a(a,b,d,e){this.view=a,this.model=b,this.keypath=d,this.callback=e,this.realize=c(this.realize,this),this.update=c(this.update,this),this.parse=c(this.parse,this),this.parse(),this.objectPath=[],this.target=this.realize()}return a.prototype.parse=function(){var a,c,e,f,g,h;return a=function(){var a,b;a=this.view.adapters,b=[];for(c in a)g=a[c],b.push(c);return b}.call(this),h=this.keypath[0],d.call(a,h)>=0?(f=this.keypath[0],e=this.keypath.substr(1)):(f=this.view.config.rootInterface,e=this.keypath),this.tokens=b.KeypathParser.parse(e,a,f),this.key=this.tokens.pop()},a.prototype.update=function(){var a,b;return(a=this.realize())!==this.target?(b=this.target,this.target=a,this.callback(this,b)):void 0},a.prototype.realize=function(){var a,b,c,d,e,f,g;for(a=this.model,g=this.tokens,b=e=0,f=g.length;f>e;b=++e)d=g[b],null!=this.objectPath[b]?a!==(c=this.objectPath[b])&&(this.view.adapters[d["interface"]].unsubscribe(c,d.path,this.update),this.view.adapters[d["interface"]].subscribe(a,d.path,this.update),this.objectPath[b]=a):(this.view.adapters[d["interface"]].subscribe(a,d.path,this.update),this.objectPath[b]=a),a=this.view.adapters[d["interface"]].read(a,d.path);return a},a}(),b.binders.enabled=function(a,b){return a.disabled=!b},b.binders.disabled=function(a,b){return a.disabled=!!b},b.binders.checked={publishes:!0,bind:function(a){return b.Util.bindEvent(a,"change",this.publish)},unbind:function(a){return b.Util.unbindEvent(a,"change",this.publish)},routine:function(a,b){var c;return a.checked="radio"===a.type?(null!=(c=a.value)?c.toString():void 0)===(null!=b?b.toString():void 0):!!b}},b.binders.unchecked={publishes:!0,bind:function(a){return b.Util.bindEvent(a,"change",this.publish)},unbind:function(a){return b.Util.unbindEvent(a,"change",this.publish)},routine:function(a,b){var c;return a.checked="radio"===a.type?(null!=(c=a.value)?c.toString():void 0)!==(null!=b?b.toString():void 0):!b}},b.binders.show=function(a,b){return a.style.display=b?"":"none"},b.binders.hide=function(a,b){return a.style.display=b?"none":""},b.binders.html=function(a,b){return a.innerHTML=null!=b?b:""},b.binders.value={publishes:!0,bind:function(a){return b.Util.bindEvent(a,"change",this.publish)},unbind:function(a){return b.Util.unbindEvent(a,"change",this.publish)},routine:function(a,b){var c,e,f,g,h,i,j;if(null!=window.jQuery){if(a=jQuery(a),(null!=b?b.toString():void 0)!==(null!=(g=a.val())?g.toString():void 0))return a.val(null!=b?b:"")}else if("select-multiple"===a.type){if(null!=b){for(j=[],e=0,f=a.length;f>e;e++)c=a[e],j.push(c.selected=(h=c.value,d.call(b,h)>=0));return j}}else if((null!=b?b.toString():void 0)!==(null!=(i=a.value)?i.toString():void 0))return a.value=null!=b?b:""}},b.binders.text=function(a,b){return null!=a.innerText?a.innerText=null!=b?b:"":a.textContent=null!=b?b:""},b.binders["if"]={block:!0,bind:function(a){var b,c;return null==this.marker?(b=[this.view.config.prefix,this.type].join("-").replace("--","-"),c=a.getAttribute(b),this.marker=document.createComment(" rivets: "+this.type+" "+c+" "),a.removeAttribute(b),a.parentNode.insertBefore(this.marker,a),a.parentNode.removeChild(a)):void 0},unbind:function(){var a;return null!=(a=this.nested)?a.unbind():void 0},routine:function(a,c){var d,e,f,g,h;if(!!c==(null==this.nested)){if(c){f={},h=this.view.models;for(d in h)e=h[d],f[d]=e;return g={binders:this.view.options.binders,formatters:this.view.options.formatters,adapters:this.view.options.adapters,config:this.view.options.config},(this.nested=new b.View(a,f,g)).bind(),this.marker.parentNode.insertBefore(a,this.marker.nextSibling)}return a.parentNode.removeChild(a),this.nested.unbind(),delete this.nested}},update:function(a){var b;return null!=(b=this.nested)?b.update(a):void 0}},b.binders.unless={block:!0,bind:function(a){return b.binders["if"].bind.call(this,a)},unbind:function(){return b.binders["if"].unbind.call(this)},routine:function(a,c){return b.binders["if"].routine.call(this,a,!c)},update:function(a){return b.binders["if"].update.call(this,a)}},b.binders["on-*"]={"function":!0,unbind:function(a){return this.handler?b.Util.unbindEvent(a,this.args[0],this.handler):void 0},routine:function(a,c){return this.handler&&b.Util.unbindEvent(a,this.args[0],this.handler),b.Util.bindEvent(a,this.args[0],this.handler=this.eventHandler(c))}},b.binders["each-*"]={block:!0,bind:function(a){var b;return null==this.marker?(b=[this.view.config.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],a.removeAttribute(b),a.parentNode.insertBefore(this.marker,a),a.parentNode.removeChild(a)):void 0},unbind:function(){var a,b,c,d,e;if(null!=this.iterated){for(d=this.iterated,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.unbind());return e}},routine:function(a,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A;if(k=this.args[0],c=c||[],this.iterated.length>c.length)for(w=Array(this.iterated.length-c.length),q=0,t=w.length;t>q;q++)f=w[q],p=this.iterated.pop(),p.unbind(),this.marker.parentNode.removeChild(p.els[0]);for(g=r=0,u=c.length;u>r;g=++r)if(j=c[g],e={},e[k]=j,null==this.iterated[g]){x=this.view.models;for(i in x)j=x[i],null==e[i]&&(e[i]=j);m=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,l={binders:this.view.options.binders,formatters:this.view.options.formatters,adapters:this.view.options.adapters,config:{}},y=this.view.options.config;for(h in y)o=y[h],l.config[h]=o;l.config.preloadData=!0,n=a.cloneNode(!0),p=new b.View(n,e,l),p.bind(),this.iterated.push(p),this.marker.parentNode.insertBefore(n,m.nextSibling)}else this.iterated[g].models[k]!==j&&this.iterated[g].update(e);if("OPTION"===a.nodeName){for(z=this.view.bindings,A=[],s=0,v=z.length;v>s;s++)d=z[s],d.el===this.marker.parentNode&&"value"===d.type?A.push(d.sync()):A.push(void 0);return A}},update:function(a){var b,c,d,e,f,g,h,i;b={};for(c in a)d=a[c],c!==this.args[0]&&(b[c]=d);for(h=this.iterated,i=[],f=0,g=h.length;g>f;f++)e=h[f],i.push(e.update(b));return i}},b.binders["class-*"]=function(a,b){var c;return c=" "+a.className+" ",!b==(-1!==c.indexOf(" "+this.args[0]+" "))?a.className=b?""+a.className+" "+this.args[0]:c.replace(" "+this.args[0]+" "," ").trim():void 0},b.binders["*"]=function(a,b){return b?a.setAttribute(this.type,b):a.removeAttribute(this.type)},b.adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(a){var b;return null==a[this.id]&&(b=this.counter++,this.weakmap[b]={callbacks:{}},Object.defineProperty(a,this.id,{value:b})),this.weakmap[a[this.id]]},stubFunction:function(a,b){var c,d,e;return d=a[b],c=this.weakReference(a),e=this.weakmap,a[b]=function(){var b,f,g,h,i,j,k,l,m,n;h=d.apply(a,arguments),k=c.pointers;for(g in k)for(f=k[g],n=null!=(l=null!=(m=e[g])?m.callbacks[f]:void 0)?l:[],i=0,j=n.length;j>i;i++)b=n[i],b();return h}},observeMutations:function(a,b,c){var e,f,g,h,i,j;if(Array.isArray(a)){if(g=this.weakReference(a),null==g.pointers)for(g.pointers={},f=["push","pop","shift","unshift","sort","reverse","splice"],i=0,j=f.length;j>i;i++)e=f[i],this.stubFunction(a,e);if(null==(h=g.pointers)[b]&&(h[b]=[]),d.call(g.pointers[b],c)<0)return g.pointers[b].push(c)}},unobserveMutations:function(a,b,c){var d,e;return Array.isArray(a&&null!=a[this.id])&&(d=null!=(e=this.weakReference(a).pointers)?e[b]:void 0)?d.splice(d.indexOf(c),1):void 0},subscribe:function(a,b,c){var e,f,g=this;return e=this.weakReference(a).callbacks,null==e[b]&&(e[b]=[],f=a[b],Object.defineProperty(a,b,{get:function(){return f},set:function(d){var h,i,j;if(d!==f){for(f=d,j=e[b],h=0,i=j.length;i>h;h++)c=j[h],c();return g.observeMutations(d,a[g.id],b)}}})),d.call(e[b],c)<0&&e[b].push(c),this.observeMutations(a[b],a[this.id],b)},unsubscribe:function(a,b,c){var d;return d=this.weakmap[a[this.id]].callbacks[b],d.splice(d.indexOf(c),1),this.unobserveMutations(a[b],a[this.id],b)},read:function(a,b){return a[b]},publish:function(a,b,c){return a[b]=c}},b.factory=function(a){return a._=b,a.binders=b.binders,a.components=b.components,a.formatters=b.formatters,a.adapters=b.adapters,a.config=b.config,a.configure=function(a){var c,d;null==a&&(a={});for(c in a)d=a[c],b.config[c]=d},a.bind=function(a,c,d){var e;return null==c&&(c={}),null==d&&(d={}),e=new b.View(a,c,d),e.bind(),e}},"object"==typeof exports?b.factory(exports):"function"==typeof define&&define.amd?define(["exports"],function(a){return b.factory(this.rivets=a),a}):b.factory(this.rivets={})}).call(this);
\ No newline at end of file
......
{
"name": "rivets",
"description": "Declarative data binding facility.",
"version": "0.5.13",
"description": "Declarative data binding + templating solution.",
"version": "0.6.0",
"author": "Michael Richards",
"url": "http://rivetsjs.com",
"main": "./dist/rivets.js",
......