javascripts/batman.js in dashing-1.0.4 vs javascripts/batman.js in dashing-1.0.5

- old
+ new

@@ -1,20 +1,21 @@ (function() { - var Batman, - __slice = [].slice; + var Batman, __slice = [].slice; Batman = function() { var mixins; mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return (function(func, args, ctor) { ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; + var child = new ctor, + result = func.apply(child, args), + t = typeof result; return t == "object" || t == "function" ? result || child : child; - })(Batman.Object, mixins, function(){}); + })(Batman.Object, mixins, function() {}); }; - Batman.version = '0.13.0'; + Batman.version = '0.14.1'; Batman.config = { pathPrefix: '/', viewPrefix: 'views', fetchRemoteViews: true, @@ -47,14 +48,133 @@ }; }).call(this); (function() { - var _implementImmediates, _objectToString, - __slice = [].slice, + var _Batman; + + Batman._Batman = _Batman = (function() { + + function _Batman(object) { + this.object = object; + } + + _Batman.prototype.check = function(object) { + if (object !== this.object) { + object._batman = new Batman._Batman(object); + return false; + } + return true; + }; + + _Batman.prototype.get = function(key) { + var reduction, results; + results = this.getAll(key); + switch (results.length) { + case 0: + return void 0; + case 1: + return results[0]; + default: + reduction = results[0].concat != null ? + function(a, b) { + return a.concat(b); + } : results[0].merge != null ? + function(a, b) { + return a.merge(b); + } : results.every(function(x) { + return typeof x === 'object'; + }) ? (results.unshift({}), function(a, b) { + return Batman.extend(a, b); + }) : void 0; + if (reduction) { + return results.reduceRight(reduction); + } else { + return results; + } + } + }; + + _Batman.prototype.getFirst = function(key) { + var results; + results = this.getAll(key); + return results[0]; + }; + + _Batman.prototype.getAll = function(keyOrGetter) { + var getter, results, val; + if (typeof keyOrGetter === 'function') { + getter = keyOrGetter; + } else { + getter = function(ancestor) { + var _ref; + return (_ref = ancestor._batman) != null ? _ref[keyOrGetter] : void 0; + }; + } + results = this.ancestors(getter); + if (val = getter(this.object)) { + results.unshift(val); + } + return results; + }; + + _Batman.prototype.ancestors = function(getter) { + var ancestor, results, val, _i, _len, _ref; + this._allAncestors || (this._allAncestors = this.allAncestors()); + if (getter) { + results = []; + _ref = this._allAncestors; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + ancestor = _ref[_i]; + val = getter(ancestor); + if (val != null) { + results.push(val); + } + } + return results; + } else { + return this._allAncestors; + } + }; + + _Batman.prototype.allAncestors = function() { + var isClass, parent, proto, results, _ref, _ref1; + results = []; + isClass = !! this.object.prototype; + parent = isClass ? (_ref = this.object.__super__) != null ? _ref.constructor : void 0 : (proto = Object.getPrototypeOf(this.object)) === this.object ? this.object.constructor.__super__ : proto; + if (parent != null) { + if ((_ref1 = parent._batman) != null) { + _ref1.check(parent); + } + results.push(parent); + if (parent._batman != null) { + results = results.concat(parent._batman.allAncestors()); + } + } + return results; + }; + + _Batman.prototype.set = function(key, value) { + return this[key] = value; + }; + + return _Batman; + + })(); + +}).call(this); + +(function() { + var chr, _encodedChars, _encodedCharsPattern, _entityMap, _implementImmediates, _objectToString, _unsafeChars, _unsafeCharsPattern, __slice = [].slice, __hasProp = {}.hasOwnProperty, - __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; }; + __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; + }; Batman.typeOf = function(object) { if (typeof object === 'undefined') { return "Undefined"; } @@ -145,12 +265,10 @@ node = node.parentNode; } return false; }; - Batman.setImmediate = Batman.clearImmediate = null; - _implementImmediates = function(container) { var canUsePostMessage, count, functions, getHandle, handler, prefix, tasks; canUsePostMessage = function() { var async, oldMessage; if (!container.postMessage) { @@ -168,26 +286,23 @@ tasks = new Batman.SimpleHash; count = 0; getHandle = function() { return "go" + (++count); }; - if (container.setImmediate) { + if (container.setImmediate && container.clearImmediate) { Batman.setImmediate = container.setImmediate; - Batman.clearImmediate = container.clearImmediate; - } else if (container.msSetImmediate) { - Batman.setImmediate = msSetImmediate; - Batman.clearImmediate = msClearImmediate; + return Batman.clearImmediate = container.clearImmediate; } else if (canUsePostMessage()) { prefix = 'com.batman.'; functions = new Batman.SimpleHash; handler = function(e) { var handle, _base; if (!~e.data.search(prefix)) { return; } handle = e.data.substring(prefix.length); - return typeof (_base = tasks.unset(handle)) === "function" ? _base() : void 0; + return typeof(_base = tasks.unset(handle)) === "function" ? _base() : void 0; }; if (container.addEventListener) { container.addEventListener('message', handler, false); } else { container.attachEvent('onmessage', handler); @@ -196,31 +311,31 @@ var handle; tasks.set(handle = getHandle(), f); container.postMessage(prefix + handle, "*"); return handle; }; - Batman.clearImmediate = function(handle) { + return Batman.clearImmediate = function(handle) { return tasks.unset(handle); }; } else if (typeof document !== 'undefined' && __indexOf.call(document.createElement("script"), "onreadystatechange") >= 0) { Batman.setImmediate = function(f) { var handle, script; handle = getHandle(); script = document.createElement("script"); script.onreadystatechange = function() { var _base; - if (typeof (_base = tasks.get(handle)) === "function") { + if (typeof(_base = tasks.get(handle)) === "function") { _base(); } script.onreadystatechange = null; script.parentNode.removeChild(script); return script = null; }; document.documentElement.appendChild(script); return handle; }; - Batman.clearImmediate = function(handle) { + return Batman.clearImmediate = function(handle) { return tasks.unset(handle); }; } else if (typeof process !== "undefined" && process !== null ? process.nextTick : void 0) { functions = {}; Batman.setImmediate = function(f) { @@ -233,23 +348,21 @@ } return delete functions[handle]; }); return handle; }; - Batman.clearImmediate = function(handle) { + return Batman.clearImmediate = function(handle) { return delete functions[handle]; }; } else { Batman.setImmediate = function(f) { return setTimeout(f, 0); }; - Batman.clearImmediate = function(handle) { + return Batman.clearImmediate = function(handle) { return clearTimeout(handle); }; } - Batman.setImmediate = Batman.setImmediate; - return Batman.clearImmediate = Batman.clearImmediate; }; Batman.setImmediate = function() { _implementImmediates(Batman.container); return Batman.setImmediate.apply(this, arguments); @@ -321,26 +434,51 @@ } } return base; }; + _entityMap = { + "&": "&amp;", + "<": "&lt;", + ">": "&gt;", + "\"": "&#34;", + "'": "&#39;" + }; + + _unsafeChars = []; + + _encodedChars = []; + + for (chr in _entityMap) { + _unsafeChars.push(chr); + _encodedChars.push(_entityMap[chr]); + } + + _unsafeCharsPattern = new RegExp("[" + (_unsafeChars.join('')) + "]", "g"); + + _encodedCharsPattern = new RegExp("(" + (_encodedChars.join('|')) + ")", "g"); + Batman.escapeHTML = (function() { - var replacements; - replacements = { - "&": "&amp;", - "<": "&lt;", - ">": "&gt;", - "\"": "&#34;", - "'": "&#39;" - }; return function(s) { - return ("" + s).replace(/[&<>'"]/g, function(c) { - return replacements[c]; + return ("" + s).replace(_unsafeCharsPattern, function(c) { + return _entityMap[c]; }); }; })(); + Batman.unescapeHTML = (function() { + return function(s) { + var node; + if (s == null) { + return; + } + node = Batman._unescapeHTMLNode || (Batman._unescapeHTMLNode = document.createElement('DIV')); + node.innerHTML = s; + return Batman.DOM.innerText(node); + }; + })(); + Batman.translate = function(x, values) { if (values == null) { values = {}; } return Batman.helpers.interpolate(Batman.get(Batman.translate.messages, x), values); @@ -367,11 +505,17 @@ }).call(this); (function() { var __slice = [].slice, - __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; }; + __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; + }; Batman.Inflector = (function() { Inflector.prototype.plural = function(regex, replacement) { return this._plural.unshift([regex, replacement]); @@ -417,18 +561,18 @@ absNumber = Math.abs(parseInt(number)); if (_ref = absNumber % 100, __indexOf.call([11, 12, 13], _ref) >= 0) { return number + "th"; } else { switch (absNumber % 10) { - case 1: - return number + "st"; - case 2: - return number + "nd"; - case 3: - return number + "rd"; - default: - return number + "th"; + case 1: + return number + "st"; + case 2: + return number + "nd"; + case 3: + return number + "rd"; + default: + return number + "th"; } } }; Inflector.prototype.pluralize = function(word) { @@ -778,122 +922,24 @@ } } return value; } }); + }, + deprecated: function(deprecatedName, upgradeString) { + return Batman.developer.warn("" + deprecatedName + " has been deprecated.", upgradeString || ''); } }; developer = Batman.developer; Batman.developer.assert((function() {}).bind, "Error! Batman needs Function.bind to work! Please shim it using something like es5-shim or augmentjs!"); }).call(this); (function() { - var _Batman; - Batman._Batman = _Batman = (function() { - - function _Batman(object) { - this.object = object; - } - - _Batman.prototype.check = function(object) { - if (object !== this.object) { - object._batman = new Batman._Batman(object); - return false; - } - return true; - }; - - _Batman.prototype.get = function(key) { - var reduction, results; - results = this.getAll(key); - switch (results.length) { - case 0: - return void 0; - case 1: - return results[0]; - default: - reduction = results[0].concat != null ? function(a, b) { - return a.concat(b); - } : results[0].merge != null ? function(a, b) { - return a.merge(b); - } : results.every(function(x) { - return typeof x === 'object'; - }) ? (results.unshift({}), function(a, b) { - return Batman.extend(a, b); - }) : void 0; - if (reduction) { - return results.reduceRight(reduction); - } else { - return results; - } - } - }; - - _Batman.prototype.getFirst = function(key) { - var results; - results = this.getAll(key); - return results[0]; - }; - - _Batman.prototype.getAll = function(keyOrGetter) { - var getter, results, val; - if (typeof keyOrGetter === 'function') { - getter = keyOrGetter; - } else { - getter = function(ancestor) { - var _ref; - return (_ref = ancestor._batman) != null ? _ref[keyOrGetter] : void 0; - }; - } - results = this.ancestors(getter); - if (val = getter(this.object)) { - results.unshift(val); - } - return results; - }; - - _Batman.prototype.ancestors = function(getter) { - var isClass, parent, proto, results, val, _ref, _ref1; - if (getter == null) { - getter = function(x) { - return x; - }; - } - results = []; - isClass = !!this.object.prototype; - parent = isClass ? (_ref = this.object.__super__) != null ? _ref.constructor : void 0 : (proto = Object.getPrototypeOf(this.object)) === this.object ? this.object.constructor.__super__ : proto; - if (parent != null) { - if ((_ref1 = parent._batman) != null) { - _ref1.check(parent); - } - val = getter(parent); - if (val != null) { - results.push(val); - } - if (parent._batman != null) { - results = results.concat(parent._batman.ancestors(getter)); - } - } - return results; - }; - - _Batman.prototype.set = function(key, value) { - return this[key] = value; - }; - - return _Batman; - - })(); - -}).call(this); - -(function() { - Batman.Event = (function() { Event.forBaseAndKey = function(base, key) { if (base.isEventEmitter) { return base.event(key); @@ -903,11 +949,10 @@ }; function Event(base, key) { this.base = base; this.key = key; - this.handlers = []; this._preventCount = 0; } Event.prototype.isEvent = true; @@ -922,10 +967,11 @@ }; return key = "<Batman.Event base: " + (Batman.Hash.prototype.hashKeyFor(this.base)) + ", key: \"" + (Batman.Hash.prototype.hashKeyFor(this.key)) + "\">"; }; Event.prototype.addHandler = function(handler) { + this.handlers || (this.handlers = []); if (this.handlers.indexOf(handler) === -1) { this.handlers.push(handler); } if (this.oneShot) { this.autofireHandler(handler); @@ -933,33 +979,39 @@ return this; }; Event.prototype.removeHandler = function(handler) { var index; - if ((index = this.handlers.indexOf(handler)) !== -1) { + if (this.handlers && (index = this.handlers.indexOf(handler)) !== -1) { this.handlers.splice(index, 1); } return this; }; Event.prototype.eachHandler = function(iterator) { - var key, _ref, _ref1; - this.handlers.slice().forEach(iterator); - if ((_ref = this.base) != null ? _ref.isEventEmitter : void 0) { + var ancestor, key, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _results; + if ((_ref = this.handlers) != null) { + _ref.slice().forEach(iterator); + } + if ((_ref1 = this.base) != null ? _ref1.isEventEmitter : void 0) { key = this.key; - return (_ref1 = this.base._batman) != null ? _ref1.ancestors(function(ancestor) { - var handlers, _ref2, _ref3; - if (ancestor.isEventEmitter && ((_ref2 = ancestor._batman) != null ? (_ref3 = _ref2.events) != null ? _ref3.hasOwnProperty(key) : void 0 : void 0)) { - handlers = ancestor.event(key).handlers; - return handlers.slice().forEach(iterator); + _ref3 = (_ref2 = this.base._batman) != null ? _ref2.ancestors() : void 0; + _results = []; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + ancestor = _ref3[_i]; + if (ancestor.isEventEmitter && ((_ref4 = ancestor._batman) != null ? (_ref5 = _ref4.events) != null ? _ref5.hasOwnProperty(key) : void 0 : void 0)) { + _results.push((_ref6 = ancestor.event(key, false)) != null ? (_ref7 = _ref6.handlers) != null ? _ref7.slice().forEach(iterator) : void 0 : void 0); + } else { + _results.push(void 0); } - }) : void 0; + } + return _results; } }; Event.prototype.clearHandlers = function() { - return this.handlers = []; + return this.handlers = void 0; }; Event.prototype.handlerContext = function() { return this.base; }; @@ -989,39 +1041,55 @@ this._oneShotFired = false; return this._oneShotArgs = null; }; Event.prototype.fire = function() { - var args, context; + return this.fireWithContext(this.handlerContext(), arguments); + }; + + Event.prototype.fireWithContext = function(context, args) { if (this.isPrevented() || this._oneShotFired) { return false; } - context = this.handlerContext(); - args = arguments; if (this.oneShot) { this._oneShotFired = true; - this._oneShotArgs = arguments; + this._oneShotArgs = args; } return this.eachHandler(function(handler) { return handler.apply(context, args); }); }; Event.prototype.allowAndFire = function() { + return this.allowAndFireWithContext(this.handlerContext, arguments); + }; + + Event.prototype.allowAndFireWithContext = function(context, args) { this.allow(); - return this.fire.apply(this, arguments); + return this.fireWithContext(context, args); }; return Event; })(); }).call(this); (function() { var __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; }; + __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; + }; Batman.PropertyEvent = (function(_super) { __extends(PropertyEvent, _super); @@ -1050,25 +1118,36 @@ isEventEmitter: true, hasEvent: function(key) { var _ref, _ref1; return (_ref = this._batman) != null ? typeof _ref.get === "function" ? (_ref1 = _ref.get('events')) != null ? _ref1.hasOwnProperty(key) : void 0 : void 0 : void 0; }, - event: function(key) { - var eventClass, events, existingEvent, newEvent, _base; + event: function(key, createEvent) { + var ancestor, eventClass, events, existingEvent, newEvent, _base, _i, _len, _ref, _ref1, _ref2, _ref3; + if (createEvent == null) { + createEvent = true; + } Batman.initializeObject(this); eventClass = this.eventClass || Batman.Event; - events = (_base = this._batman).events || (_base.events = {}); - if (events.hasOwnProperty(key)) { - return existingEvent = events[key]; + if ((_ref = this._batman.events) != null ? _ref.hasOwnProperty(key) : void 0) { + return existingEvent = this._batman.events[key]; } else { - this._batman.ancestors(function(ancestor) { - var _ref, _ref1; - return existingEvent || (existingEvent = (_ref = ancestor._batman) != null ? (_ref1 = _ref.events) != null ? _ref1[key] : void 0 : void 0); - }); - newEvent = events[key] = new eventClass(this, key); - newEvent.oneShot = existingEvent != null ? existingEvent.oneShot : void 0; - return newEvent; + _ref1 = this._batman.ancestors(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + ancestor = _ref1[_i]; + existingEvent = (_ref2 = ancestor._batman) != null ? (_ref3 = _ref2.events) != null ? _ref3[key] : void 0 : void 0; + if (existingEvent) { + break; + } + } + if (createEvent || (existingEvent != null ? existingEvent.oneShot : void 0)) { + events = (_base = this._batman).events || (_base.events = {}); + newEvent = events[key] = new eventClass(this, key); + newEvent.oneShot = existingEvent != null ? existingEvent.oneShot : void 0; + return newEvent; + } else { + return existingEvent; + } } }, on: function() { var handler, key, keys, _i, _j, _len, _results; keys = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), handler = arguments[_i++]; @@ -1091,13 +1170,15 @@ registerAsMutableSource: function() { return Batman.Property.registerSource(this); }, mutation: function(wrappedFunction) { return function() { - var result; + var result, _ref; result = wrappedFunction.apply(this, arguments); - this.event('change').fire(this, this); + if ((_ref = this.event('change', false)) != null) { + _ref.fire(this, this); + } return result; }; }, prevent: function(key) { this.event(key).prevent(); @@ -1106,21 +1187,22 @@ allow: function(key) { this.event(key).allow(); return this; }, isPrevented: function(key) { - return this.event(key).isPrevented(); + var _ref; + return (_ref = this.event(key, false)) != null ? _ref.isPrevented() : void 0; }, fire: function() { var args, key, _ref; key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - return (_ref = this.event(key)).fire.apply(_ref, args); + return (_ref = this.event(key, false)) != null ? _ref.fireWithContext(this, args) : void 0; }, allowAndFire: function() { var args, key, _ref; key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - return (_ref = this.event(key)).allowAndFire.apply(_ref, args); + return (_ref = this.event(key, false)) != null ? _ref.allowAndFireWithContext(this, args) : void 0; } }; }).call(this); @@ -1128,114 +1210,122 @@ var __slice = [].slice; Batman.Enumerable = { isEnumerable: true, map: function(f, ctx) { - var r; + var result; if (ctx == null) { ctx = Batman.container; } - r = []; + result = []; this.forEach(function() { - return r.push(f.apply(ctx, arguments)); + return result.push(f.apply(ctx, arguments)); }); - return r; + return result; }, mapToProperty: function(key) { - var r; - r = []; + var result; + result = []; this.forEach(function(item) { - return r.push(item.get(key)); + return result.push(item.get(key)); }); - return r; + return result; }, every: function(f, ctx) { - var r; + var result; if (ctx == null) { ctx = Batman.container; } - r = true; + result = true; this.forEach(function() { - return r = r && f.apply(ctx, arguments); + return result = result && f.apply(ctx, arguments); }); - return r; + return result; }, some: function(f, ctx) { - var r; + var result; if (ctx == null) { ctx = Batman.container; } - r = false; + result = false; this.forEach(function() { - return r = r || f.apply(ctx, arguments); + return result = result || f.apply(ctx, arguments); }); - return r; + return result; }, - reduce: function(f, r) { - var count, self; + reduce: function(f, accumulator) { + var count, initialValuePassed, self; count = 0; self = this; + if (accumulator != null) { + initialValuePassed = true; + } else { + initialValuePassed = false; + } this.forEach(function() { - if (r != null) { - return r = f.apply(null, [r].concat(__slice.call(arguments), [count], [self])); - } else { - return r = arguments[0]; + if (!initialValuePassed) { + accumulator = arguments[0]; + initialValuePassed = true; + return; } + return accumulator = f.apply(null, [accumulator].concat(__slice.call(arguments), [count], [self])); }); - return r; + return accumulator; }, filter: function(f) { - var r, wrap; - r = new this.constructor; - if (r.add) { - wrap = function(r, e) { - if (f(e)) { - r.add(e); + var result, wrap; + result = new this.constructor; + if (result.add) { + wrap = function(result, element) { + if (f(element)) { + result.add(element); } - return r; + return result; }; - } else if (r.set) { - wrap = function(r, k, v) { - if (f(k, v)) { - r.set(k, v); + } else if (result.set) { + wrap = function(result, key, value) { + if (f(key, value)) { + result.set(key, value); } - return r; + return result; }; } else { - if (!r.push) { - r = []; + if (!result.push) { + result = []; } - wrap = function(r, e) { - if (f(e)) { - r.push(e); + wrap = function(result, element) { + if (f(element)) { + result.push(element); } - return r; + return result; }; } - return this.reduce(wrap, r); + return this.reduce(wrap, result); }, - inGroupsOf: function(n) { - var current, i, r; - r = []; + inGroupsOf: function(groupSize) { + var current, i, result; + result = []; current = false; i = 0; - this.forEach(function(x) { - if (i++ % n === 0) { + this.forEach(function(element) { + if (i++ % groupSize === 0) { current = []; - r.push(current); + result.push(current); } - return current.push(x); + return current.push(element); }); - return r; + return result; } }; }).call(this); (function() { - var __slice = [].slice; + var _objectToString, __slice = [].slice; + _objectToString = Object.prototype.toString; + Batman.SimpleHash = (function() { function SimpleHash(obj) { this._storage = {}; this.length = 0; @@ -1244,12 +1334,10 @@ } } Batman.extend(SimpleHash.prototype, Batman.Enumerable); - SimpleHash.prototype.propertyClass = Batman.Property; - SimpleHash.prototype.hasKey = function(key) { var pair, pairs, _i, _len; if (this.objectKey(key)) { if (!this._objectStorage) { return false; @@ -1359,11 +1447,21 @@ SimpleHash.prototype.unprefixedKey = function(key) { return key.slice(1); }; SimpleHash.prototype.hashKeyFor = function(obj) { - return (obj != null ? typeof obj.hashKey === "function" ? obj.hashKey() : void 0 : void 0) || obj; + var hashKey, typeString; + if (hashKey = obj != null ? typeof obj.hashKey === "function" ? obj.hashKey() : void 0 : void 0) { + return hashKey; + } else { + typeString = _objectToString.call(obj); + if (typeString === "[object Array]") { + return typeString; + } else { + return obj; + } + } }; SimpleHash.prototype.equality = function(lhs, rhs) { if (lhs === rhs) { return true; @@ -1484,11 +1582,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.AssociationCurator = (function(_super) { __extends(AssociationCurator, _super); @@ -1557,14 +1666,26 @@ var __slice = [].slice; Batman.SimpleSet = (function() { function SimpleSet() { + var item, itemsToAdd; this._storage = []; this.length = 0; - if (arguments.length > 0) { - this.add.apply(this, arguments); + itemsToAdd = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = arguments.length; _i < _len; _i++) { + item = arguments[_i]; + if (item != null) { + _results.push(item); + } + } + return _results; + }).apply(this, arguments); + if (itemsToAdd.length > 0) { + this.add.apply(this, itemsToAdd); } } Batman.extend(SimpleSet.prototype, Batman.Enumerable); @@ -1596,11 +1717,11 @@ var index, item, items, removedItems, _i, _len; items = 1 <= arguments.length ? __slice.call(arguments, 0) : []; removedItems = []; for (_i = 0, _len = items.length; _i < _len; _i++) { item = items[_i]; - if (!(~(index = this._indexOfItem(item)))) { + if (!(~ (index = this._indexOfItem(item)))) { continue; } this._storage.splice(index, 1); removedItems.push(item); } @@ -1622,15 +1743,18 @@ } } }; SimpleSet.prototype.forEach = function(iterator, ctx) { - var container; - container = this; - return this._storage.slice().forEach(function(key) { - return iterator.call(ctx, key, null, container); - }); + var key, _i, _len, _ref, _results; + _ref = this._storage; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + key = _ref[_i]; + _results.push(iterator.call(ctx, key, null, this)); + } + return _results; }; SimpleSet.prototype.isEmpty = function() { return this.length === 0; }; @@ -1719,22 +1843,23 @@ })(); }).call(this); (function() { - var __slice = [].slice; + var SOURCE_TRACKER_STACK, SOURCE_TRACKER_STACK_VALID, __slice = [].slice; + SOURCE_TRACKER_STACK = []; + + SOURCE_TRACKER_STACK_VALID = true; + Batman.Property = (function() { Batman.mixin(Property.prototype, Batman.EventEmitter); - Property._sourceTrackerStack = []; + Property._sourceTrackerStack = SOURCE_TRACKER_STACK; - Property.sourceTracker = function() { - var stack; - return (stack = this._sourceTrackerStack)[stack.length - 1]; - }; + Property._sourceTrackerStackValid = SOURCE_TRACKER_STACK_VALID; Property.defaultAccessor = { get: function(key) { return this[key]; }, @@ -1754,19 +1879,22 @@ var _ref; return ((_ref = base._batman) != null ? _ref.getFirst('defaultAccessor') : void 0) || Batman.Property.defaultAccessor; }; Property.accessorForBaseAndKey = function(base, key) { - var accessor, _bm, _ref, - _this = this; + var accessor, ancestor, _bm, _i, _len, _ref, _ref1, _ref2, _ref3; if ((_bm = base._batman) != null) { accessor = (_ref = _bm.keyAccessors) != null ? _ref.get(key) : void 0; if (!accessor) { - _bm.ancestors(function(ancestor) { - var _ref1, _ref2; - return accessor || (accessor = (_ref1 = ancestor._batman) != null ? (_ref2 = _ref1.keyAccessors) != null ? _ref2.get(key) : void 0 : void 0); - }); + _ref1 = _bm.ancestors(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + ancestor = _ref1[_i]; + accessor = (_ref2 = ancestor._batman) != null ? (_ref3 = _ref2.keyAccessors) != null ? _ref3.get(key) : void 0 : void 0; + if (accessor) { + break; + } + } } } return accessor || this.defaultAccessorForBase(base); }; @@ -1792,27 +1920,50 @@ } }; }; Property.registerSource = function(obj) { - var _ref; + var set; if (!obj.isEventEmitter) { return; } - return (_ref = this.sourceTracker()) != null ? _ref.add(obj) : void 0; + if (SOURCE_TRACKER_STACK_VALID) { + set = SOURCE_TRACKER_STACK[SOURCE_TRACKER_STACK.length - 1]; + } else { + set = []; + SOURCE_TRACKER_STACK.push(set); + SOURCE_TRACKER_STACK_VALID = true; + } + if (set != null) { + set.push(obj); + } + return void 0; }; Property.pushSourceTracker = function() { - return Batman.Property._sourceTrackerStack.push(new Batman.SimpleSet); + if (SOURCE_TRACKER_STACK_VALID) { + return SOURCE_TRACKER_STACK_VALID = false; + } else { + return SOURCE_TRACKER_STACK.push([]); + } }; - Property.pushDummySourceTracker = function() { - return Batman.Property._sourceTrackerStack.push(null); + Property.popSourceTracker = function() { + if (SOURCE_TRACKER_STACK_VALID) { + return SOURCE_TRACKER_STACK.pop(); + } else { + SOURCE_TRACKER_STACK_VALID = true; + return void 0; + } }; - Property.popSourceTracker = function() { - return Batman.Property._sourceTrackerStack.pop(); + Property.pushDummySourceTracker = function() { + if (!SOURCE_TRACKER_STACK_VALID) { + SOURCE_TRACKER_STACK.push([]); + SOURCE_TRACKER_STACK_VALID = true; + } + return SOURCE_TRACKER_STACK.push(null); }; function Property(base, key) { this.base = base; this.key = key; @@ -1835,15 +1986,11 @@ Property.prototype.isEqual = function(other) { return this.constructor === other.constructor && this.base === other.base && this.key === other.key; }; Property.prototype.hashKey = function() { - var key; - this.hashKey = function() { - return key; - }; - return key = "<Batman.Property base: " + (Batman.Hash.prototype.hashKeyFor(this.base)) + ", key: \"" + (Batman.Hash.prototype.hashKeyFor(this.key)) + "\">"; + return this._hashKey || (this._hashKey = "<Batman.Property base: " + (Batman.Hash.prototype.hashKeyFor(this.base)) + ", key: \"" + (Batman.Hash.prototype.hashKeyFor(this.key)) + "\">"); }; Property.prototype.event = function(key) { var eventClass, _base; eventClass = this.eventClass || Batman.Event; @@ -1851,40 +1998,53 @@ (_base = this.events)[key] || (_base[key] = new eventClass(this, key)); return this.events[key]; }; Property.prototype.changeEvent = function() { - var event; - event = this.event('change'); - this.changeEvent = function() { - return event; - }; - return event; + return this._changeEvent || (this._changeEvent = this.event('change')); }; Property.prototype.accessor = function() { - var accessor; - accessor = this.constructor.accessorForBaseAndKey(this.base, this.key); - this.accessor = function() { - return accessor; - }; - return accessor; + return this._accessor || (this._accessor = this.constructor.accessorForBaseAndKey(this.base, this.key)); }; Property.prototype.eachObserver = function(iterator) { - var key; + var ancestor, handlers, key, object, property, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results; key = this.key; - this.changeEvent().handlers.slice().forEach(iterator); + handlers = (_ref = this.changeEvent().handlers) != null ? _ref.slice() : void 0; + if (handlers) { + for (_i = 0, _len = handlers.length; _i < _len; _i++) { + object = handlers[_i]; + iterator(object); + } + } if (this.base.isObservable) { - return this.base._batman.ancestors(function(ancestor) { - var handlers, property; + _ref1 = this.base._batman.ancestors(); + _results = []; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + ancestor = _ref1[_j]; if (ancestor.isObservable && ancestor.hasProperty(key)) { property = ancestor.property(key); - handlers = property.changeEvent().handlers; - return handlers.slice().forEach(iterator); + handlers = (_ref2 = property.changeEvent().handlers) != null ? _ref2.slice() : void 0; + if (handlers) { + _results.push((function() { + var _k, _len2, _results1; + _results1 = []; + for (_k = 0, _len2 = handlers.length; _k < _len2; _k++) { + object = handlers[_k]; + _results1.push(iterator(object)); + } + return _results1; + })()); + } else { + _results.push(void 0); + } + } else { + _results.push(void 0); } - }); + } + return _results; } }; Property.prototype.observers = function() { var results; @@ -1898,29 +2058,32 @@ Property.prototype.hasObservers = function() { return this.observers().length > 0; }; Property.prototype.updateSourcesFromTracker = function() { - var handler, newSources; + var handler, newSources, source, _i, _j, _len, _len1, _ref, _ref1, _results; newSources = this.constructor.popSourceTracker(); handler = this.sourceChangeHandler(); - this._eachSourceChangeEvent(function(e) { - return e.removeHandler(handler); - }); + if (this.sources) { + _ref = this.sources; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + source = _ref[_i]; + if (source != null) { + source.event('change').removeHandler(handler); + } + } + } this.sources = newSources; - return this._eachSourceChangeEvent(function(e) { - return e.addHandler(handler); - }); - }; - - Property.prototype._eachSourceChangeEvent = function(iterator) { - if (this.sources == null) { - return; + if (this.sources) { + _ref1 = this.sources; + _results = []; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + source = _ref1[_j]; + _results.push(source != null ? source.event('change').addHandler(handler) : void 0); + } + return _results; } - return this.sources.forEach(function(source) { - return iterator(source.event('change')); - }); }; Property.prototype.getValue = function() { this.registerAsMutableSource(); if (!this.isCached()) { @@ -1968,20 +2131,16 @@ return this.lockValue(); } }; Property.prototype.sourceChangeHandler = function() { - var handler, - _this = this; - handler = this._handleSourceChange.bind(this); + var _this = this; + this._sourceChangeHandler || (this._sourceChangeHandler = this._handleSourceChange.bind(this)); Batman.developer["do"](function() { - return handler.property = _this; + return _this._sourceChangeHandler.property = _this; }); - this.sourceChangeHandler = function() { - return handler; - }; - return handler; + return this._sourceChangeHandler; }; Property.prototype._handleSourceChange = function() { if (this.isIsolated()) { return this._needsRefresh = true; @@ -2067,15 +2226,19 @@ } return this; }; Property.prototype._removeHandlers = function() { - var handler; + var handler, source, _i, _len, _ref; handler = this.sourceChangeHandler(); - this._eachSourceChangeEvent(function(e) { - return e.removeHandler(handler); - }); + if (this.sources) { + _ref = this.sources; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + source = _ref[_i]; + source.event('change').removeHandler(handler); + } + } delete this.sources; return this.changeEvent().clearHandlers(); }; Property.prototype.lockValue = function() { @@ -2134,11 +2297,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.Keypath = (function(_super) { __extends(Keypath, _super); @@ -2377,29 +2551,29 @@ if (escapeValue == null) { escapeValue = true; } isSetting = arguments.length > 1; switch (node.nodeName.toUpperCase()) { - case 'INPUT': - case 'TEXTAREA': - if (isSetting) { - return node.value = value; - } else { - return node.value; - } - break; - case 'SELECT': - if (isSetting) { - return node.value = value; - } - break; - default: - if (isSetting) { - return Batman.DOM.setInnerHTML(node, escapeValue ? Batman.escapeHTML(value) : value); - } else { - return node.innerHTML; - } + case 'INPUT': + case 'TEXTAREA': + if (isSetting) { + return node.value = value; + } else { + return node.value; + } + break; + case 'SELECT': + if (isSetting) { + return node.value = value; + } + break; + default: + if (isSetting) { + return Batman.DOM.setInnerHTML(node, escapeValue ? Batman.escapeHTML(value) : value); + } else { + return node.innerHTML; + } } }, nodeIsEditable: function(node) { var _ref; return (_ref = node.nodeName.toUpperCase()) === 'INPUT' || _ref === 'TEXTAREA' || _ref === 'SELECT'; @@ -2433,11 +2607,11 @@ return node.removeEventListener(eventName, callback, false); } else { return node.detachEvent('on' + eventName, callback); } }, - hasAddEventListener: !!(typeof window !== "undefined" && window !== null ? window.addEventListener : void 0), + hasAddEventListener: !! (typeof window !== "undefined" && window !== null ? window.addEventListener : void 0), preventDefault: function(e) { if (typeof e.preventDefault === "function") { return e.preventDefault(); } else { return e.returnValue = false; @@ -2534,20 +2708,11 @@ }, didDestroyNode: function(node) { var bindings, child, eventListeners, eventName, listeners, view, _i, _len, _ref; view = Batman._data(node, 'view'); if (view) { - view.fire('destroy', node); - view.get('yields').forEach(function(name, actions) { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = actions.length; _i < _len; _i++) { - node = actions[_i].node; - _results.push(Batman.DOM.didDestroyNode(node)); - } - return _results; - }); + view.die(); } if (bindings = Batman._data(node, 'bindings')) { bindings.forEach(function(binding) { return binding.die(); }); @@ -2576,143 +2741,154 @@ Batman.DOM.event('bindingAdded'); }).call(this); (function() { - var __slice = [].slice; + Batman.DOM.ReaderBindingDefinition = (function() { + + function ReaderBindingDefinition(node, keyPath, context, renderer) { + this.node = node; + this.keyPath = keyPath; + this.context = context; + this.renderer = renderer; + } + + return ReaderBindingDefinition; + + })(); + + Batman.BindingDefinitionOnlyObserve = { + Data: 'data', + Node: 'node', + All: 'all', + None: 'none' + }; + Batman.DOM.readers = { - target: function(node, key, context, renderer) { - Batman.DOM.readers.bind(node, key, context, renderer, 'nodeChange'); - return true; + target: function(definition) { + definition.onlyObserve = Batman.BindingDefinitionOnlyObserve.Node; + return Batman.DOM.readers.bind(definition); }, - source: function(node, key, context, renderer) { - Batman.DOM.readers.bind(node, key, context, renderer, 'dataChange'); - return true; + source: function(definition) { + definition.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + return Batman.DOM.readers.bind(definition); }, - bind: function(node, key, context, renderer, only) { - var bindingClass; - bindingClass = false; + bind: function(definition) { + var bindingClass, node; + node = definition.node; switch (node.nodeName.toLowerCase()) { - case 'input': - switch (node.getAttribute('type')) { - case 'checkbox': - Batman.DOM.attrReaders.bind(node, 'checked', key, context, renderer, only); - return true; - case 'radio': - bindingClass = Batman.DOM.RadioBinding; - break; - case 'file': - bindingClass = Batman.DOM.FileBinding; - } + case 'input': + switch (node.getAttribute('type')) { + case 'checkbox': + definition.attr = 'checked'; + Batman.DOM.attrReaders.bind(definition); + return true; + case 'radio': + bindingClass = Batman.DOM.RadioBinding; break; - case 'select': - bindingClass = Batman.DOM.SelectBinding; + case 'file': + bindingClass = Batman.DOM.FileBinding; + } + break; + case 'select': + bindingClass = Batman.DOM.SelectBinding; } - bindingClass || (bindingClass = Batman.DOM.Binding); - (function(func, args, ctor) { - ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; - return t == "object" || t == "function" ? result || child : child; - })(bindingClass, arguments, function(){}); - return true; + bindingClass || (bindingClass = Batman.DOM.ValueBinding); + return new bindingClass(definition); }, - context: function(node, key, context, renderer) { - return context.descendWithKey(key); + context: function(definition) { + return definition.context.descendWithDefinition(definition); }, - mixin: function(node, key, context, renderer) { - new Batman.DOM.MixinBinding(node, key, context.descend(Batman.mixins), renderer); - return true; + mixin: function(definition) { + definition.context = definition.context.descend(Batman.mixins); + return new Batman.DOM.MixinBinding(definition); }, - showif: function(node, key, context, parentRenderer, invert) { - new Batman.DOM.ShowHideBinding(node, key, context, parentRenderer, false, invert); - return true; + showif: function(definition) { + return new Batman.DOM.ShowHideBinding(definition); }, - hideif: function() { - var _ref; - return (_ref = Batman.DOM.readers).showif.apply(_ref, __slice.call(arguments).concat([true])); + hideif: function(definition) { + definition.invert = true; + return new Batman.DOM.ShowHideBinding(definition); }, - insertif: function(node, key, context, parentRenderer, invert) { - new Batman.DOM.InsertionBinding(node, key, context, parentRenderer, false, invert); - return true; + insertif: function(definition) { + return new Batman.DOM.InsertionBinding(definition); }, - removeif: function() { - var _ref; - return (_ref = Batman.DOM.readers).insertif.apply(_ref, __slice.call(arguments).concat([true])); + removeif: function(definition) { + definition.invert = true; + return new Batman.DOM.InsertionBinding(definition); }, - route: function() { - (function(func, args, ctor) { - ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; - return t == "object" || t == "function" ? result || child : child; - })(Batman.DOM.RouteBinding, arguments, function(){}); - return true; + route: function(definition) { + return new Batman.DOM.RouteBinding(definition); }, - view: function() { - (function(func, args, ctor) { - ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; - return t == "object" || t == "function" ? result || child : child; - })(Batman.DOM.ViewBinding, arguments, function(){}); - return false; + view: function(definition) { + return new Batman.DOM.ViewBinding(definition); }, - partial: function(node, path, context, renderer) { - Batman.DOM.partial(node, path, context, renderer); - return true; + partial: function(definition) { + return Batman.DOM.partial(definition.node, definition.keyPath, definition.context, definition.renderer); }, - defineview: function(node, name, context, renderer) { + defineview: function(definition) { + var node; + node = definition.node; Batman.DOM.onParseExit(node, function() { var _ref; return (_ref = node.parentNode) != null ? _ref.removeChild(node) : void 0; }); - Batman.DOM.defineView(name, node); - return false; + Batman.DOM.defineView(definition.keyPath, node); + return { + skipChildren: true + }; }, - renderif: function(node, key, context, renderer) { - new Batman.DOM.DeferredRenderingBinding(node, key, context, renderer); - return false; + renderif: function(definition) { + return new Batman.DOM.DeferredRenderingBinding(definition); }, - "yield": function(node, key) { - Batman.DOM.onParseExit(node, function() { - return Batman.DOM.Yield.withName(key).set('containerNode', node); + "yield": function(definition) { + var keyPath, node; + node = definition.node, keyPath = definition.keyPath; + return Batman.DOM.onParseExit(node, function() { + return Batman.DOM.Yield.withName(keyPath).set('containerNode', node); }); - return true; }, - contentfor: function(node, key, context, renderer, action) { - if (action == null) { - action = 'append'; - } - Batman.DOM.onParseExit(node, function() { + contentfor: function(definition) { + var keyPath, node, renderer, swapMethod, value; + node = definition.node, value = definition.value, swapMethod = definition.swapMethod, renderer = definition.renderer, keyPath = definition.keyPath; + swapMethod || (swapMethod = 'append'); + return Batman.DOM.onParseExit(node, function() { var _ref; if ((_ref = node.parentNode) != null) { _ref.removeChild(node); } - return renderer.view.pushYieldAction(key, action, node); + return renderer.view.pushYieldAction(keyPath, swapMethod, node); }); - return true; }, - replace: function(node, key, context, renderer) { - Batman.DOM.readers.contentfor(node, key, context, renderer, 'replace'); - return true; + replace: function(definition) { + definition.swapMethod = 'replace'; + return Batman.DOM.readers.contentfor(definition); } }; }).call(this); (function() { var __slice = [].slice, - __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; }; + __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; + }; Batman.DOM.events = { click: function(node, callback, context, eventName) { if (eventName == null) { eventName = 'click'; } Batman.DOM.addEventListener(node, eventName, function() { var args, event; event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (event.metaKey || event.ctrlKey) { + if (event.metaKey || event.ctrlKey || event.button === 1) { return; } Batman.DOM.preventDefault(event); if (!Batman.DOM.eventIsAllowed(eventName, event)) { return; @@ -2730,28 +2906,28 @@ change: function(node, callback, context) { var eventName, eventNames, oldCallback, _i, _len, _results; eventNames = (function() { var _ref; switch (node.nodeName.toUpperCase()) { - case 'TEXTAREA': + case 'TEXTAREA': + return ['input', 'keyup', 'change']; + case 'INPUT': + if (_ref = node.type.toLowerCase(), __indexOf.call(Batman.DOM.textInputTypes, _ref) >= 0) { + oldCallback = callback; + callback = function(node, event) { + if (event.type === 'keyup' && Batman.DOM.events.isEnter(event)) { + return; + } + return oldCallback(node, event); + }; return ['input', 'keyup', 'change']; - case 'INPUT': - if (_ref = node.type.toLowerCase(), __indexOf.call(Batman.DOM.textInputTypes, _ref) >= 0) { - oldCallback = callback; - callback = function(node, event) { - if (event.type === 'keyup' && Batman.DOM.events.isEnter(event)) { - return; - } - return oldCallback.apply(null, arguments); - }; - return ['input', 'keyup', 'change']; - } else { - return ['input', 'change']; - } - break; - default: - return ['change']; + } else { + return ['input', 'change']; + } + break; + default: + return ['change']; } })(); _results = []; for (_i = 0, _len = eventNames.length; _i < _len; _i++) { eventName = eventNames[_i]; @@ -2818,94 +2994,100 @@ }).call(this); (function() { + Batman.DOM.AttrReaderBindingDefinition = (function() { + + function AttrReaderBindingDefinition(node, attr, keyPath, context, renderer) { + this.node = node; + this.attr = attr; + this.keyPath = keyPath; + this.context = context; + this.renderer = renderer; + } + + return AttrReaderBindingDefinition; + + })(); + Batman.DOM.attrReaders = { _parseAttribute: function(value) { if (value === 'false') { value = false; } if (value === 'true') { value = true; } return value; }, - source: function(node, attr, key, context, renderer) { - return Batman.DOM.attrReaders.bind(node, attr, key, context, renderer, 'dataChange'); + source: function(definition) { + definition.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + return Batman.DOM.attrReaders.bind(definition); }, - bind: function(node, attr, key, context, renderer, only) { + bind: function(definition) { var bindingClass; bindingClass = (function() { - switch (attr) { - case 'checked': - case 'disabled': - case 'selected': - return Batman.DOM.CheckedBinding; - case 'value': - case 'href': - case 'src': - case 'size': - return Batman.DOM.NodeAttributeBinding; - case 'class': - return Batman.DOM.ClassBinding; - case 'style': - return Batman.DOM.StyleBinding; - default: - return Batman.DOM.AttributeBinding; + switch (definition.attr) { + case 'checked': + case 'disabled': + case 'selected': + return Batman.DOM.CheckedBinding; + case 'value': + case 'href': + case 'src': + case 'size': + return Batman.DOM.NodeAttributeBinding; + case 'class': + return Batman.DOM.ClassBinding; + case 'style': + return Batman.DOM.StyleBinding; + default: + return Batman.DOM.AttributeBinding; } })(); - (function(func, args, ctor) { - ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; - return t == "object" || t == "function" ? result || child : child; - })(bindingClass, arguments, function(){}); - return true; + return new bindingClass(definition); }, - context: function(node, contextName, key, context) { - return context.descendWithKey(key, contextName); + context: function(definition) { + return definition.context.descendWithDefinition(definition); }, - event: function(node, eventName, key, context) { - (function(func, args, ctor) { - ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; - return t == "object" || t == "function" ? result || child : child; - })(Batman.DOM.EventBinding, arguments, function(){}); - return true; + event: function(definition) { + return new Batman.DOM.EventBinding(definition); }, - addclass: function(node, className, key, context, parentRenderer, invert) { - new Batman.DOM.AddClassBinding(node, className, key, context, parentRenderer, false, invert); - return true; + addclass: function(definition) { + return new Batman.DOM.AddClassBinding(definition); }, - removeclass: function(node, className, key, context, parentRenderer) { - return Batman.DOM.attrReaders.addclass(node, className, key, context, parentRenderer, true); + removeclass: function(definition) { + definition.invert = true; + return new Batman.DOM.AddClassBinding(definition); }, - foreach: function(node, iteratorName, key, context, parentRenderer) { - (function(func, args, ctor) { - ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; - return t == "object" || t == "function" ? result || child : child; - })(Batman.DOM.IteratorBinding, arguments, function(){}); - return false; + foreach: function(definition) { + return new Batman.DOM.IteratorBinding(definition); }, - formfor: function(node, localName, key, context) { - (function(func, args, ctor) { - ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; - return t == "object" || t == "function" ? result || child : child; - })(Batman.DOM.FormBinding, arguments, function(){}); - return context.descendWithKey(key, localName); + formfor: function(definition) { + new Batman.DOM.FormBinding(definition); + return definition.context.descendWithDefinition(definition); } }; }).call(this); (function() { - var BatmanObject, ObjectFunctions, getAccessorObject, promiseWrapper, wrapSingleAccessor, - __slice = [].slice, + var BatmanObject, ObjectFunctions, getAccessorObject, promiseWrapper, wrapSingleAccessor, __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; }; + __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; + }; getAccessorObject = function(base, accessor) { var deprecated, _i, _len, _ref; if (typeof accessor === 'function') { accessor = { @@ -2927,12 +3109,11 @@ promiseWrapper = function(fetcher) { return function(defaultAccessor) { return { get: function(key) { - var asyncDeliver, existingValue, newValue, _base, _base1, _ref, _ref1, - _this = this; + var asyncDeliver, existingValue, newValue, _base, _base1, _ref, _ref1, _this = this; if ((existingValue = defaultAccessor.get.apply(this, arguments)) != null) { return existingValue; } asyncDeliver = false; newValue = void 0; @@ -3108,18 +3289,15 @@ } return this._batman.id; }; BatmanObject.prototype.hashKey = function() { - var key; + var _base; if (typeof this.isEqual === 'function') { return; } - this.hashKey = function() { - return key; - }; - return key = "<Batman.Object " + (this._batmanID()) + ">"; + return (_base = this._batman).hashKey || (_base.hashKey = "<Batman.Object " + (this._batmanID()) + ">"); }; BatmanObject.prototype.toJSON = function() { var key, obj, value; obj = {}; @@ -3140,13 +3318,28 @@ Batman.Object = BatmanObject; }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }; + __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; + }; Batman.Renderer = (function(_super) { var bindingRegexp, bindingSortOrder, bindingSortPositions, k, name, pos, _i, _j, _len, _len1, _ref; __extends(Renderer, _super); @@ -3231,12 +3424,11 @@ return 0; } }; Renderer.prototype.parseNode = function(node) { - var argument, attribute, bindings, keypath, names, nextNode, oldContext, result, skipChildren, _base, _base1, _k, _l, _len2, _len3, _ref1, _ref2, _ref3, _ref4, - _this = this; + var attr, attribute, binding, bindingDefinition, bindings, names, nextNode, oldContext, reader, skipChildren, value, _k, _l, _len2, _len3, _ref1, _ref2, _ref3, _ref4, _this = this; if (this.deferEvery && (new Date - this.startTime) > this.deferEvery) { this.resumeNode = node; this.timeout = Batman.setImmediate(this.resume); return; } @@ -3251,21 +3443,21 @@ } bindings.push((names = name.split('-')).length > 1 ? [names[0], names.slice(1, names.length + 1 || 9e9).join('-'), attribute.value] : [name, void 0, attribute.value]); } _ref3 = bindings.sort(this._sortBindings); for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { - _ref4 = _ref3[_l], name = _ref4[0], argument = _ref4[1], keypath = _ref4[2]; - result = argument ? typeof (_base = Batman.DOM.attrReaders)[name] === "function" ? _base[name](node, argument, keypath, this.context, this) : void 0 : typeof (_base1 = Batman.DOM.readers)[name] === "function" ? _base1[name](node, keypath, this.context, this) : void 0; - if (result === false) { - skipChildren = true; - break; - } else if (result instanceof Batman.RenderContext) { + _ref4 = _ref3[_l], name = _ref4[0], attr = _ref4[1], value = _ref4[2]; + binding = attr ? (reader = Batman.DOM.attrReaders[name]) ? (bindingDefinition = new Batman.DOM.AttrReaderBindingDefinition(node, attr, value, this.context, this), reader(bindingDefinition)) : void 0 : (reader = Batman.DOM.readers[name]) ? (bindingDefinition = new Batman.DOM.ReaderBindingDefinition(node, value, this.context, this), reader(bindingDefinition)) : void 0; + if (binding instanceof Batman.RenderContext) { oldContext = this.context; - this.context = result; + this.context = binding; Batman.DOM.onParseExit(node, function() { return _this.context = oldContext; }); + } else if (binding != null ? binding.skipChildren : void 0) { + skipChildren = true; + break; } } } if ((nextNode = this.nextNode(node, skipChildren))) { return this.parseNode(nextNode); @@ -3318,20 +3510,35 @@ })(Batman.Object); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }; + __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; + }; Batman.DOM.AbstractBinding = (function(_super) { - var get_dot_rx, get_rx, keypath_rx; + var get_dot_rx, get_rx, keypath_rx, onlyAll, onlyData, onlyNode; __extends(AbstractBinding, _super); - keypath_rx = /(^|,)\s*(?:(true|false)|("[^"]*")|(\{[^\}]*\})|([a-zA-Z][\w\-\.]*[\?\!]?))\s*(?=$|,)/g; + keypath_rx = /(^|,)\s*(?:(true|false)|("[^"]*")|(\{[^\}]*\})|(([0-9]+[a-zA-Z\_]|[a-zA-Z])[\w\-\.]*[\?\!]?))\s*(?=$|,)/g; get_dot_rx = /(?:\]\.)(.+?)(?=[\[\.]|\s*\||$)/; get_rx = /(?!^\s*)\[(.*?)\]/g; @@ -3395,29 +3602,40 @@ AbstractBinding.accessor('keyContext', function() { return this.renderContext.contextForKey(this.key); }); + onlyAll = Batman.BindingDefinitionOnlyObserve.All; + + onlyData = Batman.BindingDefinitionOnlyObserve.Data; + + onlyNode = Batman.BindingDefinitionOnlyObserve.Node; + AbstractBinding.prototype.bindImmediately = true; AbstractBinding.prototype.shouldSet = true; AbstractBinding.prototype.isInputBinding = false; AbstractBinding.prototype.escapeValue = true; - function AbstractBinding(node, keyPath, renderContext, renderer, only) { - this.node = node; - this.keyPath = keyPath; - this.renderContext = renderContext; - this.renderer = renderer; - this.only = only != null ? only : false; - this._fireDataChange = __bind(this._fireDataChange, this); + AbstractBinding.prototype.onlyObserve = onlyAll; - this._fireNodeChange = __bind(this._fireNodeChange, this); + AbstractBinding.prototype.skipParseFilter = false; - this.parseFilter(); + function AbstractBinding(definition) { + this._fireDataChange = __bind(this._fireDataChange, this); + this.node = definition.node, this.keyPath = definition.keyPath, this.renderContext = definition.context, this.renderer = definition.renderer; + if (definition.onlyObserve) { + this.onlyObserve = definition.onlyObserve; + } + if (definition.skipParseFilter != null) { + this.skipParseFilter = definition.skipParseFilter; + } + if (!this.skipParseFilter) { + this.parseFilter(); + } if (this.bindImmediately) { this.bind(); } } @@ -3425,20 +3643,20 @@ return (this.key != null) && this.filterFunctions.length === 0; }; AbstractBinding.prototype.bind = function() { var _ref, _ref1; - if ((this.node != null) && ((_ref = this.only) === false || _ref === 'nodeChange') && Batman.DOM.nodeIsEditable(this.node)) { - Batman.DOM.events.change(this.node, this._fireNodeChange); - if (this.only === 'nodeChange') { + if (this.node && ((_ref = this.onlyObserve) === onlyAll || _ref === onlyNode) && Batman.DOM.nodeIsEditable(this.node)) { + Batman.DOM.events.change(this.node, this._fireNodeChange.bind(this)); + if (this.onlyObserve === onlyNode) { this._fireNodeChange(); } } - if ((_ref1 = this.only) === false || _ref1 === 'dataChange') { + if ((_ref1 = this.onlyObserve) === onlyAll || _ref1 === onlyData) { this.observeAndFire('filteredValue', this._fireDataChange); } - if (this.node != null) { + if (this.node) { return Batman.DOM.trackBinding(this, this.node); } }; AbstractBinding.prototype._fireNodeChange = function(event) { @@ -3468,10 +3686,14 @@ _ref.forEach(function(key, property) { return property.die(); }); } this.fire('die'); + this.node = null; + this.keyPath = null; + this.renderContext = null; + this.renderer = null; this.dead = true; return true; }; AbstractBinding.prototype.parseFilter = function() { @@ -3534,24 +3756,39 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.ViewBinding = (function(_super) { __extends(ViewBinding, _super); + ViewBinding.prototype.skipChildren = true; + + ViewBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + function ViewBinding() { ViewBinding.__super__.constructor.apply(this, arguments); this.renderer.prevent('rendered'); this.node.removeAttribute('data-view'); } ViewBinding.prototype.dataChange = function(viewClassOrInstance) { - var _this = this; + var _ref, _this = this; if (viewClassOrInstance == null) { return; } if (viewClassOrInstance.isView) { this.view = viewClassOrInstance; @@ -3565,60 +3802,135 @@ }); } this.view.on('ready', function() { return _this.renderer.allowAndFire('rendered'); }); - return this.die(); + this.forget(); + return (_ref = this._batman.properties) != null ? _ref.forEach(function(key, property) { + return property.die(); + }) : void 0; }; + ViewBinding.prototype.die = function() { + this.view = null; + return ViewBinding.__super__.die.apply(this, arguments); + }; + return ViewBinding; })(Batman.DOM.AbstractBinding); }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.ViewArgumentBinding = (function(_super) { __extends(ViewArgumentBinding, _super); function ViewArgumentBinding() { return ViewArgumentBinding.__super__.constructor.apply(this, arguments); } + ViewArgumentBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.None; + return ViewArgumentBinding; })(Batman.DOM.AbstractBinding); }).call(this); (function() { var __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; }; + __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; + }; + Batman.DOM.ValueBinding = (function(_super) { + + __extends(ValueBinding, _super); + + function ValueBinding(definition) { + var _ref; + this.isInputBinding = (_ref = definition.node.nodeName.toLowerCase()) === 'input' || _ref === 'textarea'; + ValueBinding.__super__.constructor.apply(this, arguments); + } + + ValueBinding.prototype.nodeChange = function(node, context) { + if (this.isTwoWay()) { + return this.set('filteredValue', this.node.value); + } + }; + + ValueBinding.prototype.dataChange = function(value, node) { + return Batman.DOM.valueForNode(this.node, value, this.escapeValue); + }; + + return ValueBinding; + + })(Batman.DOM.AbstractBinding); + +}).call(this); + +(function() { + var __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; + }; + Batman.DOM.ShowHideBinding = (function(_super) { __extends(ShowHideBinding, _super); - function ShowHideBinding(node, className, key, context, parentRenderer, invert) { + ShowHideBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + + function ShowHideBinding(definition) { var display; - this.invert = invert != null ? invert : false; - display = node.style.display; + display = definition.node.style.display; if (!display || display === 'none') { display = ''; } this.originalDisplay = display; + this.invert = definition.invert; ShowHideBinding.__super__.constructor.apply(this, arguments); } ShowHideBinding.prototype.dataChange = function(value) { var hide, view, _ref; view = Batman._data(this.node, 'view'); - if (!!value === !this.invert) { + if ( !! value === !this.invert) { if (view != null) { view.fire('beforeAppear', this.node); } if ((_ref = Batman.data(this.node, 'show')) != null) { _ref.call(this.node); @@ -3627,11 +3939,11 @@ return view != null ? view.fire('appear', this.node) : void 0; } else { if (view != null) { view.fire('beforeDisappear', this.node); } - if (typeof (hide = Batman.data(this.node, 'hide')) === 'function') { + if (typeof(hide = Batman.data(this.node, 'hide')) === 'function') { hide.call(this.node); } else { Batman.DOM.setStyleProperty(this.node, 'display', 'none', 'important'); } return view != null ? view.fire('disappear', this.node) : void 0; @@ -3643,13 +3955,28 @@ })(Batman.DOM.AbstractBinding); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }; + __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; + }; Batman.DOM.SelectBinding = (function(_super) { __extends(SelectBinding, _super); @@ -3668,12 +3995,11 @@ this.selectedBindings = new Batman.SimpleSet; SelectBinding.__super__.constructor.apply(this, arguments); } SelectBinding.prototype.childBindingAdded = function(binding) { - var dataChangeHandler, - _this = this; + var dataChangeHandler, _this = this; if (binding instanceof Batman.DOM.CheckedBinding) { binding.on('dataChange', dataChangeHandler = function() { return _this.nodeChange(); }); binding.on('die', function() { @@ -3697,12 +4023,11 @@ }; SelectBinding.prototype.lastKeyContext = null; SelectBinding.prototype.dataChange = function(newValue) { - var child, matches, valueToChild, _i, _len, _name, _ref, - _this = this; + var child, matches, valueToChild, _i, _len, _name, _ref, _this = this; this.lastKeyContext || (this.lastKeyContext = this.get('keyContext')); if (this.lastKeyContext !== this.get('keyContext')) { this.canSetImplicitly = true; this.lastKeyContext = this.get('keyContext'); } @@ -3775,30 +4100,43 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.RouteBinding = (function(_super) { __extends(RouteBinding, _super); function RouteBinding() { return RouteBinding.__super__.constructor.apply(this, arguments); } - RouteBinding.prototype.onATag = false; + RouteBinding.prototype.onAnchorTag = false; + RouteBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + RouteBinding.accessor('dispatcher', function() { return this.renderContext.get('dispatcher') || Batman.App.get('current.dispatcher'); }); RouteBinding.prototype.bind = function() { var _this = this; if (this.node.nodeName.toUpperCase() === 'A') { - this.onATag = true; + this.onAnchorTag = true; } RouteBinding.__super__.bind.apply(this, arguments); return Batman.DOM.events.click(this.node, function(node, event) { var params; if (event.__batmanActionTaken) { @@ -3812,26 +4150,26 @@ }); }; RouteBinding.prototype.dataChange = function(value) { var path; - if (value != null) { + if (value) { path = this.pathFromValue(value); } - if (this.onATag) { - if ((path != null) && (Batman.navigator != null)) { + if (this.onAnchorTag) { + if (path && Batman.navigator) { path = Batman.navigator.linkTo(path); } else { path = "#"; } return this.node.href = path; } }; RouteBinding.prototype.pathFromValue = function(value) { var _ref; - if (value != null) { + if (value) { if (value.isNamedRouteQuery) { return value.get('path'); } else { return (_ref = this.get('dispatcher')) != null ? _ref.pathFromParams(value) : void 0; } @@ -3844,11 +4182,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.RadioBinding = (function(_super) { __extends(RadioBinding, _super); @@ -3887,20 +4236,33 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.MixinBinding = (function(_super) { __extends(MixinBinding, _super); function MixinBinding() { return MixinBinding.__super__.constructor.apply(this, arguments); } + MixinBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + MixinBinding.prototype.dataChange = function(value) { if (value != null) { return Batman.mixin(this.node, value); } }; @@ -3911,11 +4273,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.FileBinding = (function(_super) { __extends(FileBinding, _super); @@ -3942,18 +4315,31 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.DeferredRenderingBinding = (function(_super) { __extends(DeferredRenderingBinding, _super); DeferredRenderingBinding.prototype.rendered = false; + DeferredRenderingBinding.prototype.skipChildren = true; + function DeferredRenderingBinding() { DeferredRenderingBinding.__super__.constructor.apply(this, arguments); this.node.removeAttribute("data-renderif"); } @@ -3976,64 +4362,57 @@ }).call(this); (function() { var __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; }; - - Batman.DOM.Binding = (function(_super) { - - __extends(Binding, _super); - - function Binding(node) { - var _ref; - this.isInputBinding = (_ref = node.nodeName.toLowerCase()) === 'input' || _ref === 'textarea'; - Binding.__super__.constructor.apply(this, arguments); - } - - Binding.prototype.nodeChange = function(node, context) { - if (this.isTwoWay()) { - return this.set('filteredValue', this.node.value); + __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; }; - Binding.prototype.dataChange = function(value, node) { - return Batman.DOM.valueForNode(this.node, value, this.escapeValue); - }; - - return Binding; - - })(Batman.DOM.AbstractBinding); - -}).call(this); - -(function() { - var __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; }, - __slice = [].slice; - Batman.DOM.AbstractAttributeBinding = (function(_super) { __extends(AbstractAttributeBinding, _super); - function AbstractAttributeBinding() { - var args, attributeName, node; - node = arguments[0], attributeName = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : []; - this.attributeName = attributeName; - AbstractAttributeBinding.__super__.constructor.apply(this, [node].concat(__slice.call(args))); + function AbstractAttributeBinding(definition) { + this.attributeName = definition.attr; + AbstractAttributeBinding.__super__.constructor.apply(this, arguments); } return AbstractAttributeBinding; })(Batman.DOM.AbstractBinding); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }; + __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; + }; Batman.DOM.FormBinding = (function(_super) { __extends(FormBinding, _super); @@ -4041,32 +4420,35 @@ FormBinding.prototype.errorClass = 'error'; FormBinding.prototype.defaultErrorsListSelector = 'div.errors'; + FormBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.None; + FormBinding.accessor('errorsListSelector', function() { return this.get('node').getAttribute('data-errors-list') || this.defaultErrorsListSelector; }); - function FormBinding(node, contextName, keyPath, renderContext, renderer, only) { + function FormBinding() { this.childBindingAdded = __bind(this.childBindingAdded, this); FormBinding.__super__.constructor.apply(this, arguments); - this.contextName = contextName; + this.contextName = this.attributeName; delete this.attributeName; Batman.DOM.events.submit(this.get('node'), function(node, e) { return Batman.DOM.preventDefault(e); }); this.setupErrorsList(); } FormBinding.prototype.childBindingAdded = function(binding) { - var field, index, node; + var definition, field, index, node; if (binding.isInputBinding && Batman.isChildOf(this.get('node'), binding.get('node'))) { - if (~(index = binding.get('key').indexOf(this.contextName))) { + if (~ (index = binding.get('key').indexOf(this.contextName))) { node = binding.get('node'); field = binding.get('key').slice(index + this.contextName.length + 1); - return new Batman.DOM.AddClassBinding(node, this.errorClass, this.get('keyPath') + (" | get 'errors." + field + ".length'"), this.renderContext, this.renderer); + definition = new Batman.DOM.AttrReaderBindingDefinition(node, this.errorClass, this.get('keyPath') + (" | get 'errors." + field + ".length'"), this.renderContext, this.renderer); + return new Batman.DOM.AddClassBinding(definition); } } }; FormBinding.prototype.setupErrorsList = function() { @@ -4088,32 +4470,47 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.EventBinding = (function(_super) { __extends(EventBinding, _super); - EventBinding.prototype.bindImmediately = false; + EventBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.None; - function EventBinding(node, eventName, key, context) { - var attacher, callback, - _this = this; + function EventBinding() { + var attacher, callback, confirmText, _this = this; EventBinding.__super__.constructor.apply(this, arguments); + if (confirmText = this.node.getAttribute('data-confirm')) { + Batman.developer.deprecated("data-confirm"); + } callback = function() { var _ref; + if (confirmText && !confirm(confirmText)) { + return; + } return (_ref = _this.get('filteredValue')) != null ? _ref.apply(_this.get('callbackContext'), arguments) : void 0; }; if (attacher = Batman.DOM.events[this.attributeName]) { - attacher(this.node, callback, context); + attacher(this.node, callback, this.renderContext); } else { - Batman.DOM.events.other(this.node, this.attributeName, callback, context); + Batman.DOM.events.other(this.node, this.attributeName, callback, this.renderContext); } - this.bind(); } EventBinding.accessor('callbackContext', function() { var contextKeySegments; contextKeySegments = this.key.split('.'); @@ -4151,11 +4548,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.NodeAttributeBinding = (function(_super) { __extends(NodeAttributeBinding, _super); @@ -4182,11 +4590,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.CheckedBinding = (function(_super) { __extends(CheckedBinding, _super); @@ -4195,31 +4614,44 @@ } CheckedBinding.prototype.isInputBinding = true; CheckedBinding.prototype.dataChange = function(value) { - return this.node[this.attributeName] = !!value; + return this.node[this.attributeName] = !! value; }; return CheckedBinding; })(Batman.DOM.NodeAttributeBinding); }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.AttributeBinding = (function(_super) { __extends(AttributeBinding, _super); function AttributeBinding() { return AttributeBinding.__super__.constructor.apply(this, arguments); } + AttributeBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + AttributeBinding.prototype.dataChange = function(value) { return this.node.setAttribute(this.attributeName, value); }; AttributeBinding.prototype.nodeChange = function(node) { @@ -4234,44 +4666,56 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.AddClassBinding = (function(_super) { __extends(AddClassBinding, _super); - function AddClassBinding(node, className, keyPath, renderContext, renderer, only, invert) { - var name, names; - this.invert = invert != null ? invert : false; - names = className.split('|'); + AddClassBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + + function AddClassBinding(definition) { + var name; + this.invert = definition.invert; this.classes = (function() { - var _i, _len, _results; + var _i, _len, _ref, _results; + _ref = definition.attr.split('|'); _results = []; - for (_i = 0, _len = names.length; _i < _len; _i++) { - name = names[_i]; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + name = _ref[_i]; _results.push({ name: name, pattern: new RegExp("(?:^|\\s)" + name + "(?:$|\\s)", 'i') }); } return _results; })(); AddClassBinding.__super__.constructor.apply(this, arguments); - delete this.attributeName; } AddClassBinding.prototype.dataChange = function(value) { var currentName, includesClassName, name, pattern, _i, _len, _ref, _ref1; currentName = this.node.className; _ref = this.classes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { _ref1 = _ref[_i], name = _ref1.name, pattern = _ref1.pattern; includesClassName = pattern.test(currentName); - if (!!value === !this.invert) { + if ( !! value === !this.invert) { if (!includesClassName) { this.node.className = "" + currentName + " " + name; } } else { if (includesClassName) { @@ -4288,11 +4732,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.AbstractCollectionBinding = (function(_super) { __extends(AbstractCollectionBinding, _super); @@ -4337,42 +4792,36 @@ })(Batman.DOM.AbstractAttributeBinding); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }, + __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; + }, __slice = [].slice; Batman.DOM.StyleBinding = (function(_super) { __extends(StyleBinding, _super); - StyleBinding.SingleStyleBinding = (function(_super1) { + StyleBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; - __extends(SingleStyleBinding, _super1); - - SingleStyleBinding.prototype.isTwoWay = function() { - return false; - }; - - function SingleStyleBinding() { - var args, parent, _i; - args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), parent = arguments[_i++]; - this.parent = parent; - SingleStyleBinding.__super__.constructor.apply(this, args); - } - - SingleStyleBinding.prototype.dataChange = function(value) { - return this.parent.setStyle(this.attributeName, value); - }; - - return SingleStyleBinding; - - })(Batman.DOM.AbstractAttributeBinding); - function StyleBinding() { this.setStyle = __bind(this.setStyle, this); this.handleArrayChanged = __bind(this.handleArrayChanged, this); this.oldStyles = {}; @@ -4419,11 +4868,13 @@ return _this.bindSingleAttribute(key, "" + _this.keyPath + "." + key); }); }; StyleBinding.prototype.bindSingleAttribute = function(attr, keyPath) { - return this.styleBindings[attr] = new this.constructor.SingleStyleBinding(this.node, attr, keyPath, this.renderContext, this.renderer, this.only, this); + var definition; + definition = new Batman.DOM.AttrReaderBindingDefinition(this.node, attr, keyPath, this.renderContext, this.renderer); + return this.styleBindings[attr] = new Batman.DOM.StyleBinding.SingleStyleBinding(definition, this); }; StyleBinding.prototype.setStyle = function(key, value) { key = Batman.helpers.camelize(key.trim(), true); if (this.oldStyles[key] == null) { @@ -4464,20 +4915,58 @@ StyleBinding.prototype.unbindCollection = function() { this.resetBindings(); return StyleBinding.__super__.unbindCollection.apply(this, arguments); }; + StyleBinding.SingleStyleBinding = (function(_super1) { + + __extends(SingleStyleBinding, _super1); + + SingleStyleBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + + SingleStyleBinding.prototype.isTwoWay = function() { + return false; + }; + + function SingleStyleBinding(definition, parent) { + this.parent = parent; + SingleStyleBinding.__super__.constructor.call(this, definition); + } + + SingleStyleBinding.prototype.dataChange = function(value) { + return this.parent.setStyle(this.attributeName, value); + }; + + return SingleStyleBinding; + + })(Batman.DOM.AbstractAttributeBinding); + return StyleBinding; })(Batman.DOM.AbstractCollectionBinding); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }; + __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; + }; Batman.DOM.IteratorBinding = (function(_super) { __extends(IteratorBinding, _super); @@ -4485,22 +4974,21 @@ IteratorBinding.prototype.queuedActionNumber = 0; IteratorBinding.prototype.bindImmediately = false; - function IteratorBinding(sourceNode, iteratorName, key, context, parentRenderer) { - var previousSiblingNode, - _this = this; - this.iteratorName = iteratorName; - this.key = key; - this.context = context; - this.parentRenderer = parentRenderer; + IteratorBinding.prototype.skipChildren = true; + + IteratorBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + + function IteratorBinding(definition) { this.handleArrayChanged = __bind(this.handleArrayChanged, this); + var previousSiblingNode, sourceNode, _this = this; + sourceNode = definition.node, this.iteratorName = definition.attr, this.key = definition.keyPath, this.parentRenderer = definition.renderer; this.nodeMap = new Batman.SimpleHash; this.rendererMap = new Batman.SimpleHash; - this.fragment = document.createDocumentFragment(); this.prototypeNode = sourceNode.cloneNode(true); this.prototypeNode.removeAttribute("data-foreach-" + this.iteratorName); previousSiblingNode = sourceNode.nextSibling; this.startNode = document.createComment("start " + this.iteratorName + "-" + (this.get('_batmanID'))); this.endNode = document.createComment("end " + this.iteratorName + "-" + (this.get('_batmanID'))); @@ -4514,22 +5002,18 @@ Batman.DOM.onParseExit(sourceNode.parentNode, function() { Batman.DOM.destroyNode(sourceNode); _this.bind(); return _this.parentRenderer.allowAndFire('rendered'); }); - IteratorBinding.__super__.constructor.call(this, this.endNode, this.iteratorName, this.key, this.context, this.parentRenderer); + definition.node = this.endNode; + IteratorBinding.__super__.constructor.apply(this, arguments); } IteratorBinding.prototype.parentNode = function() { return this.endNode.parentNode; }; - IteratorBinding.prototype.die = function() { - this.dead = true; - return IteratorBinding.__super__.die.apply(this, arguments); - }; - IteratorBinding.prototype.dataChange = function(collection) { var items, _items; if (collection != null) { if (!this.bindCollection(collection)) { items = (collection != null ? collection.forEach : void 0) ? (_items = [], collection.forEach(function(item) { @@ -4541,16 +5025,15 @@ return this.handleArrayChanged([]); } }; IteratorBinding.prototype.handleArrayChanged = function(newItems) { - var existingNode, index, newItem, node, nodeAtIndex, parentNode, startIndex, unseenNodeMap, _i, _len, - _this = this; + var existingNode, index, newItem, node, nodeAtIndex, parentNode, startIndex, unseenNodeMap, _i, _len, _this = this; parentNode = this.parentNode(); startIndex = this._getStartNodeIndex() + 1; unseenNodeMap = this.nodeMap.merge(); - if (newItems != null) { + if (newItems) { for (index = _i = 0, _len = newItems.length; _i < _len; index = ++_i) { newItem = newItems[index]; nodeAtIndex = parentNode.childNodes[startIndex + index]; if ((nodeAtIndex != null) && this._itemForNode(nodeAtIndex) === newItem) { unseenNodeMap.unset(newItem); @@ -4560,29 +5043,42 @@ Batman.DOM.insertBefore(this.parentNode(), node, nodeAtIndex); } } } unseenNodeMap.forEach(function(item, node) { - return _this._removeItem(item); + if (_this._nodesToBeRendered.has(node)) { + _this._nodesToBeRemoved || (_this._nodesToBeRemoved = new Batman.SimpleSet); + return _this._nodesToBeRemoved.add(node); + } else { + return _this._removeItem(item); + } }); }; IteratorBinding.prototype._itemForNode = function(node) { return Batman._data(node, "" + this.iteratorName + "Item"); }; IteratorBinding.prototype._newNodeForItem = function(newItem) { - var newNode, renderer, - _this = this; + var newNode, renderer, _this = this; newNode = this.prototypeNode.cloneNode(true); + this._nodesToBeRendered || (this._nodesToBeRendered = new Batman.SimpleSet); + this._nodesToBeRendered.add(newNode); Batman._data(newNode, "" + this.iteratorName + "Item", newItem); this.nodeMap.set(newItem, newNode); this.parentRenderer.prevent('rendered'); renderer = new Batman.Renderer(newNode, this.renderContext.descend(newItem, this.iteratorName), this.parentRenderer.view); - renderer.on('rendered', function() { - Batman.DOM.propagateBindingEvents(newNode); - _this.fire('nodeAdded', newNode, newItem); + renderer.once('rendered', function() { + var _ref; + _this._nodesToBeRendered.remove(newNode); + if ((_ref = _this._nodesToBeRemoved) != null ? _ref.has(newNode) : void 0) { + _this._nodesToBeRemoved.remove(newNode); + _this._removeItem(newItem); + } else { + Batman.DOM.propagateBindingEvents(newNode); + _this.fire('nodeAdded', newNode, newItem); + } return _this.parentRenderer.allowAndFire('rendered'); }); return newNode; }; @@ -4603,30 +5099,56 @@ node = this.nodeMap.unset(item); Batman.DOM.destroyNode(node); return this.fire('nodeRemoved', node, item); }; + IteratorBinding.prototype.die = function() { + var _ref; + if (this._nodesToBeRendered && !this._nodesToBeRendered.isEmpty()) { + this._nodesToBeRemoved || (this._nodesToBeRemoved = new Batman.SimpleSet); + (_ref = this._nodesToBeRemoved).add.apply(_ref, this._nodesToBeRendered.toArray()); + } + return IteratorBinding.__super__.die.apply(this, arguments); + }; + return IteratorBinding; })(Batman.DOM.AbstractCollectionBinding); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }; + __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; + }; Batman.DOM.ClassBinding = (function(_super) { __extends(ClassBinding, _super); function ClassBinding() { this.handleArrayChanged = __bind(this.handleArrayChanged, this); return ClassBinding.__super__.constructor.apply(this, arguments); } + ClassBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + ClassBinding.prototype.dataChange = function(value) { if (value != null) { this.unbindCollection(); if (typeof value === 'string') { return this.node.className = value; @@ -4670,11 +5192,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.ValidationError = (function(_super) { __extends(ValidationError, _super); @@ -4698,11 +5231,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.StorageAdapter = (function(_super) { __extends(StorageAdapter, _super); @@ -4910,12 +5454,11 @@ } return true; }; StorageAdapter.prototype.runFilter = function(position, action, env, callback) { - var actionFilters, allFilters, filters, next, - _this = this; + var actionFilters, allFilters, filters, next, _this = this; this._inheritFilters(); allFilters = this._batman.filters[position].all || []; actionFilters = this._batman.filters[position][action] || []; env.action = action; filters = position === 'before' ? actionFilters.concat(allFilters) : allFilters.concat(actionFilters); @@ -4950,12 +5493,11 @@ StorageAdapter.prototype._jsonToAttributes = function(json) { return JSON.parse(json); }; StorageAdapter.prototype.perform = function(key, subject, options, callback) { - var env, next, - _this = this; + var env, next, _this = this; options || (options = {}); env = { options: options, subject: subject }; @@ -4977,17 +5519,33 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice, - __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; }; + __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; + }; Batman.RestStorage = (function(_super) { - var key, _fn, _i, _len, _ref, - _this = this; + var key, _fn, _i, _len, _ref, _this = this; __extends(RestStorage, _super); RestStorage.CommunicationError = (function(_super1) { @@ -5327,10 +5885,11 @@ RestStorage._statusCodeErrors = { '0': RestStorage.CommunicationError, '403': RestStorage.NotAllowedError, '404': RestStorage.NotFoundError, '406': RestStorage.NotAcceptableError, + '409': RestStorage.RecordExistsError, '422': RestStorage.UnprocessableRecordError, '500': RestStorage.InternalStorageError, '501': RestStorage.NotImplementedError }; @@ -5354,11 +5913,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.LocalStorage = (function(_super) { __extends(LocalStorage, _super); @@ -5531,11 +6101,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.SessionStorage = (function(_super) { __extends(SessionStorage, _super); @@ -5559,11 +6140,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.ParamsReplacer = (function(_super) { __extends(ParamsReplacer, _super); @@ -5625,11 +6217,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.ParamsPusher = (function(_super) { __extends(ParamsPusher, _super); @@ -5647,11 +6250,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.NamedRouteQuery = (function(_super) { __extends(NamedRouteQuery, _super); @@ -5789,11 +6403,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.Dispatcher = (function(_super) { var ControllerDirectory; __extends(Dispatcher, _super); @@ -5920,11 +6545,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.Route = (function(_super) { __extends(Route, _super); @@ -6078,13 +6714,28 @@ })(Batman.Object); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }; + __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; + }; Batman.ControllerActionRoute = (function(_super) { __extends(ControllerActionRoute, _super); @@ -6116,11 +6767,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.CallbackActionRoute = (function(_super) { __extends(CallbackActionRoute, _super); @@ -6140,16 +6802,26 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.Hash = (function(_super) { - var k, _fn, _i, _j, _len, _len1, _ref, _ref1, - _this = this; + var k, _fn, _i, _j, _len, _len1, _ref, _ref1, _this = this; __extends(Hash, _super); Hash.Metadata = (function(_super1) { @@ -6306,11 +6978,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.RenderCache = (function(_super) { __extends(RenderCache, _super); @@ -6426,15 +7109,36 @@ })(Batman.Hash); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }, + __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; + }, __slice = [].slice, - __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; }; + __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; + }; Batman.Controller = (function(_super) { var _optionsFromFilterArguments; __extends(Controller, _super); @@ -6518,12 +7222,11 @@ } return _results; }; Controller.prototype.errorHandler = function(callback) { - var errorFrame, _ref, - _this = this; + var errorFrame, _ref, _this = this; errorFrame = (_ref = this._actionFrames) != null ? _ref[this._actionFrames.length - 1] : void 0; return function(err, result, env) { if (err) { if (errorFrame != null ? errorFrame.error : void 0) { return; @@ -6539,12 +7242,11 @@ } }; }; Controller.prototype.handleError = function(error) { - var handled, _ref, - _this = this; + var handled, _ref, _this = this; handled = false; if ((_ref = this.constructor._batman.getAll('errorHandlers')) != null) { _ref.forEach(function(hash) { return hash.forEach(function(key, value) { var handler, _i, _len, _results; @@ -6599,12 +7301,11 @@ return Batman.redirect(redirectTo); } }; Controller.prototype.executeAction = function(action, params) { - var frame, oldRedirect, parentFrame, result, _ref, _ref1, - _this = this; + var frame, oldRedirect, parentFrame, result, _ref, _ref1, _this = this; if (params == null) { params = this.get('params'); } Batman.developer.assert(this[action], "Error! Controller action " + (this.get('routingKey')) + "." + action + " couldn't be found!"); parentFrame = this._actionFrames[this._actionFrames.length - 1]; @@ -6660,12 +7361,11 @@ return Batman.redirect(url); } }; Controller.prototype.render = function(options) { - var action, frame, view, _ref, _ref1, - _this = this; + var action, frame, view, _ref, _ref1, _this = this; if (options == null) { options = {}; } if (frame = (_ref = this._actionFrames) != null ? _ref[this._actionFrames.length - 1] : void 0) { frame.startOperation(); @@ -6689,11 +7389,11 @@ } if (view) { if ((_ref1 = Batman.currentApp) != null) { _ref1.prevent('ready'); } - view.on('ready', function() { + view.once('ready', function() { var _ref2; Batman.DOM.Yield.withName(options.into).replace(view.get('node')); if ((_ref2 = Batman.currentApp) != null) { _ref2.allowAndFire('ready'); } @@ -6752,15 +7452,25 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.Set = (function(_super) { - var k, _fn, _i, _j, _len, _len1, _ref, _ref1, - _this = this; + var k, _fn, _i, _j, _len, _len1, _ref, _ref1, _this = this; __extends(Set, _super); function Set() { Batman.SimpleSet.apply(this, arguments); @@ -6848,11 +7558,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.ErrorsSet = (function(_super) { __extends(ErrorsSet, _super); @@ -6874,16 +7595,26 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.SetProxy = (function(_super) { - var k, _fn, _i, _len, _ref, - _this = this; + var k, _fn, _i, _len, _ref, _this = this; __extends(SetProxy, _super); function SetProxy(base) { var _this = this; @@ -6905,18 +7636,16 @@ } Batman.extend(SetProxy.prototype, Batman.Enumerable); SetProxy.prototype.filter = function(f) { - var r; - r = new Batman.Set(); - return this.reduce((function(r, e) { - if (f(e)) { - r.add(e); + return this.reduce(function(accumulator, element) { + if (f(element)) { + accumulator.add(element); } - return r; - }), r); + return accumulator; + }, new Batman.Set()); }; SetProxy.prototype.replace = function() { var length, result; length = this.property('length'); @@ -6955,13 +7684,28 @@ }).call(this, Batman.Object); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __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; }, + __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; + }, __slice = [].slice; Batman.BinarySetOperation = (function(_super) { __extends(BinarySetOperation, _super); @@ -7013,11 +7757,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.SetUnion = (function(_super) { __extends(SetUnion, _super); @@ -7055,11 +7810,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.SetIntersection = (function(_super) { __extends(SetIntersection, _super); @@ -7080,11 +7846,13 @@ _results.push(item); } } return _results; })(); - return this.add.apply(this, itemsToAdd); + if (itemsToAdd.length > 0) { + return this.add.apply(this, itemsToAdd); + } }; SetIntersection.prototype._itemsWereRemovedFromSource = function() { var items, opposite, source; source = arguments[0], opposite = arguments[1], items = 3 <= arguments.length ? __slice.call(arguments, 2) : []; @@ -7097,11 +7865,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.SetComplement = (function(_super) { __extends(SetComplement, _super); @@ -7123,11 +7902,13 @@ _results.push(item); } } return _results; })(); - return this.add.apply(this, itemsToAdd); + if (itemsToAdd.length > 0) { + return this.add.apply(this, itemsToAdd); + } } else { itemsToRemove = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = items.length; _i < _len; _i++) { @@ -7136,11 +7917,13 @@ _results.push(item); } } return _results; })(); - return this.remove.apply(this, itemsToRemove); + if (itemsToRemove.length > 0) { + return this.remove.apply(this, itemsToRemove); + } } }; SetComplement.prototype._itemsWereRemovedFromSource = function() { var item, items, itemsToAdd, opposite, source; @@ -7157,38 +7940,54 @@ _results.push(item); } } return _results; })(); - return this.add.apply(this, itemsToAdd); + if (itemsToAdd.length > 0) { + return this.add.apply(this, itemsToAdd); + } } }; SetComplement.prototype._addComplement = function(items, opposite) { - var item; - return this.add.apply(this, (function() { + var item, itemsToAdd; + itemsToAdd = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = items.length; _i < _len; _i++) { item = items[_i]; if (opposite.has(item)) { _results.push(item); } } return _results; - })()); + })(); + if (itemsToAdd.length > 0) { + return this.add.apply(this, itemsToAdd); + } }; return SetComplement; })(Batman.BinarySetOperation); }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.StateMachine = (function(_super) { __extends(StateMachine, _super); @@ -7198,12 +7997,11 @@ }; StateMachine.InvalidTransitionError.prototype = new Error; StateMachine.transitions = function(table) { - var definePredicate, fromState, k, object, predicateKeys, toState, transitions, v, _fn, _ref, - _this = this; + var definePredicate, fromState, k, object, predicateKeys, toState, transitions, v, _fn, _ref, _this = this; for (k in table) { v = table[k]; if (!(v.from && v.to)) { continue; } @@ -7345,13 +8143,23 @@ })(Batman.StateMachine); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __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; }, + var __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; + }, __slice = [].slice; Batman.Model = (function(_super) { var functionName, _i, _j, _len, _len1, _ref, _ref1; @@ -7383,18 +8191,18 @@ keys = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), encoderOrLastKey = arguments[_i++]; Batman.initializeObject(this.prototype); (_base = this.prototype._batman).encoders || (_base.encoders = new Batman.SimpleHash); encoder = {}; switch (Batman.typeOf(encoderOrLastKey)) { - case 'String': - keys.push(encoderOrLastKey); - break; - case 'Function': - encoder.encode = encoderOrLastKey; - break; - default: - encoder = encoderOrLastKey; + case 'String': + keys.push(encoderOrLastKey); + break; + case 'Function': + encoder.encode = encoderOrLastKey; + break; + default: + encoder = encoderOrLastKey; } for (_j = 0, _len = keys.length; _j < _len; _j++) { key = keys[_j]; encoderForKey = Batman.extend({ as: key @@ -7541,34 +8349,27 @@ Model.loadWithOptions = function(options, callback) { var _this = this; this.fire('loading', options); return this._doStorageOperation('readAll', options, function(err, records, env) { - var mappedRecords, record; + var mappedRecords; if (err != null) { _this.fire('error', err); return typeof callback === "function" ? callback(err, []) : void 0; } else { - mappedRecords = (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = records.length; _i < _len; _i++) { - record = records[_i]; - _results.push(this._mapIdentity(record)); - } - return _results; - }).call(_this); + mappedRecords = _this._mapIdentities(records); _this.fire('loaded', mappedRecords, env); return typeof callback === "function" ? callback(err, mappedRecords, env) : void 0; } }); }; Model.create = function(attrs, callback) { var obj, _ref; if (!callback) { - _ref = [{}, attrs], attrs = _ref[0], callback = _ref[1]; + _ref = [{}, + attrs], attrs = _ref[0], callback = _ref[1]; } obj = new this(attrs); obj.save(callback); return obj; }; @@ -7593,26 +8394,34 @@ }); return this._mapIdentity(record); }; Model._mapIdentity = function(record) { - var existing, id, _ref; - if (typeof (id = record.get('id')) === 'undefined' || id === '') { - return record; - } else { - existing = (_ref = this.get("loaded.indexedBy.id").get(id)) != null ? _ref.toArray()[0] : void 0; - if (existing) { + return this._mapIdentities([record])[0]; + }; + + Model._mapIdentities = function(records) { + var existing, id, index, newRecords, record, _i, _len, _ref, _ref1; + newRecords = []; + for (index = _i = 0, _len = records.length; _i < _len; index = ++_i) { + record = records[index]; + if (!((id = record.get('id')) != null)) { + continue; + } else if (existing = (_ref = this.get('loaded.indexedBy.id').get(id)) != null ? _ref.toArray()[0] : void 0) { existing._withoutDirtyTracking(function() { var _ref1; return this.updateAttributes(((_ref1 = record.get('attributes')) != null ? _ref1.toObject() : void 0) || {}); }); - return existing; + records[index] = existing; } else { - this.get('loaded').add(record); - return record; + newRecords.push(record); } } + if (newRecords.length) { + (_ref1 = this.get('loaded')).add.apply(_ref1, newRecords); + } + return records; }; Model._doStorageOperation = function(operation, options, callback) { var adapter; Batman.developer.assert(this.prototype.hasStorage(), "Can't " + operation + " model " + (Batman.functionName(this.constructor)) + " without any storage adapters!"); @@ -7683,18 +8492,10 @@ function Model(idOrAttributes) { if (idOrAttributes == null) { idOrAttributes = {}; } - this.destroy = __bind(this.destroy, this); - - this.save = __bind(this.save, this); - - this.loadWithOptions = __bind(this.loadWithOptions, this); - - this.load = __bind(this.load, this); - Batman.developer.assert(this instanceof Batman.Object, "constructors must be called with new"); if (Batman.typeOf(idOrAttributes) === 'Object') { Model.__super__.constructor.call(this, idOrAttributes); } else { Model.__super__.constructor.call(this); @@ -7793,12 +8594,11 @@ Model.prototype.toParam = function() { return this.get('id'); }; Model.prototype.toJSON = function() { - var encoders, obj, - _this = this; + var encoders, obj, _this = this; obj = {}; encoders = this._batman.get('encoders'); if (!(!encoders || encoders.isEmpty())) { encoders.forEach(function(key, encoder) { var encodedVal, val; @@ -7815,12 +8615,11 @@ } return obj; }; Model.prototype.fromJSON = function(data) { - var encoders, key, obj, value, - _this = this; + var encoders, key, obj, value, _this = this; obj = {}; encoders = this._batman.get('encoders'); if (!encoders || encoders.isEmpty() || !encoders.some(function(key, encoder) { return encoder.decode != null; })) { @@ -7851,22 +8650,22 @@ }; Model.prototype.load = function(options, callback) { var _ref1; if (!callback) { - _ref1 = [{}, options], options = _ref1[0], callback = _ref1[1]; + _ref1 = [{}, + options], options = _ref1[0], callback = _ref1[1]; } else { options = { data: options }; } return this.loadWithOptions(options, callback); }; Model.prototype.loadWithOptions = function(options, callback) { - var callbackQueue, hasOptions, _ref1, - _this = this; + var callbackQueue, hasOptions, _ref1, _this = this; hasOptions = Object.keys(options).length !== 0; if ((_ref1 = this.get('lifecycle.state')) === 'destroying' || _ref1 === 'destroyed') { if (typeof callback === "function") { callback(new Error("Can't load a destroyed record!")); } @@ -7906,14 +8705,14 @@ } } }; Model.prototype.save = function(options, callback) { - var endState, isNew, startState, storageOperation, _ref1, _ref2, - _this = this; + var endState, isNew, startState, storageOperation, _ref1, _ref2, _this = this; if (!callback) { - _ref1 = [{}, options], options = _ref1[0], callback = _ref1[1]; + _ref1 = [{}, + options], options = _ref1[0], callback = _ref1[1]; } isNew = this.isNew(); _ref2 = isNew ? ['create', 'create', 'created'] : ['save', 'update', 'saved'], startState = _ref2[0], storageOperation = _ref2[1], endState = _ref2[2]; if (this.get('lifecycle').startTransition(startState)) { return this.validate(function(error, errors) { @@ -7922,12 +8721,11 @@ _this.get('lifecycle').failedValidation(); return typeof callback === "function" ? callback(error || errors, _this) : void 0; } associations = _this.constructor._batman.get('associations'); _this._withoutDirtyTracking(function() { - var _ref3, - _this = this; + var _ref3, _this = this; return associations != null ? (_ref3 = associations.getByType('belongsTo')) != null ? _ref3.forEach(function(association, label) { return association.apply(_this); }) : void 0 : void 0; }); return _this._doStorageOperation(storageOperation, { @@ -7965,14 +8763,14 @@ return typeof callback === "function" ? callback(new Batman.StateMachine.InvalidTransitionError("Can't save while in state " + (this.get('lifecycle.state')))) : void 0; } }; Model.prototype.destroy = function(options, callback) { - var _ref1, - _this = this; + var _ref1, _this = this; if (!callback) { - _ref1 = [{}, options], options = _ref1[0], callback = _ref1[1]; + _ref1 = [{}, + options], options = _ref1[0], callback = _ref1[1]; } if (this.get('lifecycle').destroy()) { return this._doStorageOperation('destroy', { data: options }, function(err, record, env) { @@ -8051,12 +8849,11 @@ return false; } }; Model.prototype._doStorageOperation = function(operation, options, callback) { - var adapter, - _this = this; + var adapter, _this = this; Batman.developer.assert(this.hasStorage(), "Can't " + operation + " model " + (Batman.functionName(this.constructor)) + " without any storage adapters!"); adapter = this._batman.get('storage'); return adapter.perform(operation, this, options, function() { return callback.apply(null, arguments); }); @@ -8081,12 +8878,11 @@ }).call(this, Batman.Object); }).call(this); (function() { - var k, _fn, _i, _len, _ref, - _this = this; + var k, _fn, _i, _len, _ref, _this = this; _ref = Batman.AssociationCurator.availableAssociations; _fn = function(k) { return Batman.Model[k] = function(label, scope) { var collection, _base; @@ -8102,11 +8898,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.Proxy = (function(_super) { __extends(Proxy, _super); @@ -8142,11 +8949,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.AssociationProxy = (function(_super) { __extends(AssociationProxy, _super); @@ -8228,11 +9046,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.HasOneProxy = (function(_super) { __extends(HasOneProxy, _super); @@ -8247,12 +9076,11 @@ HasOneProxy.prototype.fetchFromLocal = function() { return this.association.setIndex().get(this.get('primaryValue')); }; HasOneProxy.prototype.fetchFromRemote = function(callback) { - var loadOptions, - _this = this; + var loadOptions, _this = this; loadOptions = { data: {} }; loadOptions.data[this.association.foreignKey] = this.get('primaryValue'); if (this.association.options.url) { @@ -8277,11 +9105,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.BelongsToProxy = (function(_super) { __extends(BelongsToProxy, _super); @@ -8296,12 +9135,11 @@ BelongsToProxy.prototype.fetchFromLocal = function() { return this.association.setIndex().get(this.get('foreignValue')); }; BelongsToProxy.prototype.fetchFromRemote = function(callback) { - var loadOptions, - _this = this; + var loadOptions, _this = this; loadOptions = {}; if (this.association.options.url) { loadOptions.recordUrl = this.association.options.url; } return this.association.getRelatedModel().findWithOptions(this.get('foreignValue'), loadOptions, function(error, loadedRecord) { @@ -8318,11 +9156,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PolymorphicBelongsToProxy = (function(_super) { __extends(PolymorphicBelongsToProxy, _super); @@ -8337,12 +9186,11 @@ PolymorphicBelongsToProxy.prototype.fetchFromLocal = function() { return this.association.setIndexForType(this.get('foreignTypeValue')).get(this.get('foreignValue')); }; PolymorphicBelongsToProxy.prototype.fetchFromRemote = function(callback) { - var loadOptions, - _this = this; + var loadOptions, _this = this; loadOptions = {}; if (this.association.options.url) { loadOptions.recordUrl = this.association.options.url; } return this.association.getRelatedModelForType(this.get('foreignTypeValue')).findWithOptions(this.get('foreignValue'), loadOptions, function(error, loadedRecord) { @@ -8359,11 +9207,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.Accessible = (function(_super) { __extends(Accessible, _super); @@ -8555,40 +9414,40 @@ valueType = Batman.typeOf(value); if (!((prefix != null) || valueType === 'Object')) { throw new Error("value must be an Object"); } switch (valueType) { - case 'Array': - return ((function() { - var _i, _len; - arrayResults = []; - if (value.length === 0) { - arrayResults.push(queryFromParams(null, "" + prefix + "[]")); - } else { - for (_i = 0, _len = value.length; _i < _len; _i++) { - v = value[_i]; - arrayResults.push(queryFromParams(v, "" + prefix + "[]")); - } - } - return arrayResults; - })()).join("&"); - case 'Object': - return ((function() { - var _results; - _results = []; - for (k in value) { - v = value[k]; - _results.push(queryFromParams(v, prefix ? "" + prefix + "[" + (encodeQueryComponent(k)) + "]" : encodeQueryComponent(k))); - } - return _results; - })()).join("&"); - default: - if (prefix != null) { - return "" + prefix + "=" + (encodeQueryComponent(value)); + case 'Array': + return ((function() { + var _i, _len; + arrayResults = []; + if (value.length === 0) { + arrayResults.push(queryFromParams(null, "" + prefix + "[]")); } else { - return encodeQueryComponent(value); + for (_i = 0, _len = value.length; _i < _len; _i++) { + v = value[_i]; + arrayResults.push(queryFromParams(v, "" + prefix + "[]")); + } } + return arrayResults; + })()).join("&"); + case 'Object': + return ((function() { + var _results; + _results = []; + for (k in value) { + v = value[k]; + _results.push(queryFromParams(v, prefix ? "" + prefix + "[" + (encodeQueryComponent(k)) + "]" : encodeQueryComponent(k))); + } + return _results; + })()).join("&"); + default: + if (prefix != null) { + return "" + prefix + "=" + (encodeQueryComponent(value)); + } else { + return encodeQueryComponent(value); + } } }; URI.encodeComponent = encodeComponent = function(str) { if (str != null) { @@ -8608,11 +9467,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.Request = (function(_super) { var dataHasFileUploads; __extends(Request, _super); @@ -8627,29 +9497,29 @@ if (object instanceof Batman.container.File) { return [[key, object]]; } return list = (function() { switch (Batman.typeOf(object)) { - case 'Object': - list = (function() { - var _results; - _results = []; - for (k in object) { - v = object[k]; - _results.push(pairForList((first ? k : "" + key + "[" + k + "]"), v)); - } - return _results; - })(); - return list.reduce(function(acc, list) { - return acc.concat(list); - }, []); - case 'Array': - return object.reduce(function(acc, element) { - return acc.concat(pairForList("" + key + "[]", element)); - }, []); - default: - return [[key, object != null ? object : ""]]; + case 'Object': + list = (function() { + var _results; + _results = []; + for (k in object) { + v = object[k]; + _results.push(pairForList((first ? k : "" + key + "[" + k + "]"), v)); + } + return _results; + })(); + return list.reduce(function(acc, list) { + return acc.concat(list); + }, []); + case 'Array': + return object.reduce(function(acc, element) { + return acc.concat(pairForList("" + key + "[]", element)); + }, []); + default: + return [[key, object != null ? object : ""]]; } })(); }; formData = new Batman.container.FormData(); _ref = pairForList("", data, true); @@ -8665,25 +9535,25 @@ if ((typeof File !== "undefined" && File !== null) && data instanceof File) { return true; } type = Batman.typeOf(data); switch (type) { - case 'Object': - for (k in data) { - v = data[k]; - if (dataHasFileUploads(v)) { - return true; - } + case 'Object': + for (k in data) { + v = data[k]; + if (dataHasFileUploads(v)) { + return true; } - break; - case 'Array': - for (_i = 0, _len = data.length; _i < _len; _i++) { - v = data[_i]; - if (dataHasFileUploads(v)) { - return true; - } + } + break; + case 'Array': + for (_i = 0, _len = data.length; _i < _len; _i++) { + v = data[_i]; + if (dataHasFileUploads(v)) { + return true; } + } } return false; }; Request.wrapAccessor('method', function(core) { @@ -8743,11 +9613,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.SetObserver = (function(_super) { __extends(SetObserver, _super); @@ -8852,28 +9733,41 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.SetSort = (function(_super) { __extends(SetSort, _super); function SetSort(base, key, order) { - var boundReIndex; + var boundReIndex, _this = this; this.key = key; if (order == null) { order = "asc"; } SetSort.__super__.constructor.call(this, base); this.descending = order.toLowerCase() === "desc"; if (this.base.isObservable) { this._setObserver = new Batman.SetObserver(this.base); this._setObserver.observedItemKeys = [this.key]; - boundReIndex = this._reIndex.bind(this); + boundReIndex = function() { + return _this._reIndex(); + }; this._setObserver.observerForItemAndKey = function() { return boundReIndex; }; this._setObserver.on('itemsWereAdded', boundReIndex); this._setObserver.on('itemsWereRemoved', boundReIndex); @@ -8921,13 +9815,15 @@ SetSort.prototype.merge = function(other) { this.base.registerAsMutableSource(); return (function(func, args, ctor) { ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; + var child = new ctor, + result = func.apply(child, args), + t = typeof result; return t == "object" || t == "function" ? result || child : child; - })(Batman.Set, this._storage, function(){}).merge(other).sortedBy(this.key, this.order); + })(Batman.Set, this._storage, function() {}).merge(other).sortedBy(this.key, this.order); }; SetSort.prototype.compare = function(a, b) { if (a === b) { return 0; @@ -8974,12 +9870,11 @@ } return 0; }; SetSort.prototype._reIndex = function() { - var newOrder, _ref, - _this = this; + var newOrder, _ref, _this = this; newOrder = this.base.toArray().sort(function(a, b) { var multiple, valueA, valueB; valueA = Batman.get(a, _this.key); if (typeof valueA === 'function') { valueA = valueA.call(a); @@ -9009,11 +9904,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.AssociationSet = (function(_super) { __extends(AssociationSet, _super); @@ -9066,11 +9972,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PolymorphicAssociationSet = (function(_super) { __extends(PolymorphicAssociationSet, _super); @@ -9101,11 +10018,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.SetIndex = (function(_super) { __extends(SetIndex, _super); @@ -9227,38 +10155,71 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PolymorphicAssociationSetIndex = (function(_super) { __extends(PolymorphicAssociationSetIndex, _super); function PolymorphicAssociationSetIndex(association, type, key) { this.association = association; this.type = type; - PolymorphicAssociationSetIndex.__super__.constructor.call(this, this.association.getRelatedModelForType(type).get('loaded'), key); + PolymorphicAssociationSetIndex.__super__.constructor.call(this, this.association.getRelatedModel().get('loaded'), key); } PolymorphicAssociationSetIndex.prototype._resultSetForKey = function(key) { - var _this = this; - return this._storage.getOrSet(key, function() { - return new _this.association.proxyClass(key, _this.type, _this.association); - }); + return this.association.setForKey(key); }; + PolymorphicAssociationSetIndex.prototype._addItem = function(item) { + if (this.association.modelType() !== item.get(this.association.foreignTypeKey)) { + return; + } + return PolymorphicAssociationSetIndex.__super__._addItem.apply(this, arguments); + }; + + PolymorphicAssociationSetIndex.prototype._removeItem = function(item) { + if (this.association.modelType() !== item.get(this.association.foreignTypeKey)) { + return; + } + return PolymorphicAssociationSetIndex.__super__._removeItem.apply(this, arguments); + }; + return PolymorphicAssociationSetIndex; })(Batman.SetIndex); }).call(this); (function() { var __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; }; + __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; + }; Batman.AssociationSetIndex = (function(_super) { __extends(AssociationSetIndex, _super); @@ -9297,11 +10258,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.UniqueSetIndex = (function(_super) { __extends(UniqueSetIndex, _super); @@ -9338,11 +10310,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.UniqueAssociationSetIndex = (function(_super) { __extends(UniqueAssociationSetIndex, _super); @@ -9357,11 +10340,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PolymorphicUniqueAssociationSetIndex = (function(_super) { __extends(PolymorphicUniqueAssociationSetIndex, _super); @@ -9376,11 +10370,15 @@ })(Batman.UniqueSetIndex); }).call(this); (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + var __bind = function(fn, me) { + return function() { + return fn.apply(me, arguments); + }; + }, __slice = [].slice; Batman.Navigator = (function() { Navigator.defaultClass = function() { @@ -9390,11 +10388,11 @@ return Batman.HashbangNavigator; } }; Navigator.forApp = function(app) { - return new (this.defaultClass())(app); + return new(this.defaultClass())(app); }; function Navigator(app) { this.app = app; this.handleCurrentLocation = __bind(this.handleCurrentLocation, this); @@ -9446,11 +10444,11 @@ return this.cachedPath; }; Navigator.prototype.push = function(params) { var path, pathFromParams, _base; - pathFromParams = typeof (_base = this.app.get('dispatcher')).pathFromParams === "function" ? _base.pathFromParams(params) : void 0; + pathFromParams = typeof(_base = this.app.get('dispatcher')).pathFromParams === "function" ? _base.pathFromParams(params) : void 0; if (pathFromParams) { this._lastRedirect = pathFromParams; } path = this.dispatch(params); if (!this._lastRedirect || this._lastRedirect === path) { @@ -9459,11 +10457,11 @@ return path; }; Navigator.prototype.replace = function(params) { var path, pathFromParams, _base; - pathFromParams = typeof (_base = this.app.get('dispatcher')).pathFromParams === "function" ? _base.pathFromParams(params) : void 0; + pathFromParams = typeof(_base = this.app.get('dispatcher')).pathFromParams === "function" ? _base.pathFromParams(params) : void 0; if (pathFromParams) { this._lastRedirect = pathFromParams; } path = this.dispatch(params); if (!this._lastRedirect || this._lastRedirect === path) { @@ -9497,11 +10495,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PushStateNavigator = (function(_super) { __extends(PushStateNavigator, _super); @@ -9561,11 +10570,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.HashbangNavigator = (function(_super) { __extends(HashbangNavigator, _super); @@ -9658,12 +10678,11 @@ } return void 0; }; RouteMap.prototype.addRoute = function(name, route) { - var base, names, - _this = this; + var base, names, _this = this; this.childrenByOrder.push(route); if (name.length > 0 && (names = name.split('.')).length > 0) { base = names.shift(); if (!this.childrenByName[base]) { this.childrenByName[base] = new Batman.RouteMap; @@ -9946,19 +10965,19 @@ if (!this.parent) { return ""; } else { nestingParam = ":" + Batman.helpers.singularize(this.baseOptions.controller) + "Id"; nestingSegment = Batman.helpers.underscore(this.baseOptions.controller); - return "" + (this.parent._nestingPath()) + "/" + nestingSegment + "/" + nestingParam + "/"; + return "" + (this.parent._nestingPath()) + nestingSegment + "/" + nestingParam + "/"; } }; RouteMapBuilder.prototype._nestingName = function() { if (!this.parent) { return ""; } else { - return this.baseOptions.controller + "."; + return this.parent._nestingName() + this.baseOptions.controller + "."; } }; RouteMapBuilder.prototype._childBuilder = function(baseOptions) { if (baseOptions == null) { @@ -9973,16 +10992,26 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.App = (function(_super) { - var name, _fn, _i, _len, _ref, - _this = this; + var name, _fn, _i, _len, _ref, _this = this; __extends(App, _super); function App() { return App.__super__.constructor.apply(this, arguments); @@ -10044,14 +11073,16 @@ }); App.requirePath = ''; Batman.developer["do"](function() { + var requireDeprecated; + requireDeprecated = "Please use whatever means you'd like to load your code before calling App.run."; App.require = function() { - var base, name, names, path, _i, _len, - _this = this; + var base, name, names, path, _i, _len, _this = this; path = arguments[0], names = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + Batman.developer.deprecated("App.require", requireDeprecated); base = this.requirePath + path; for (_i = 0, _len = names.length; _i < _len; _i++) { name = names[_i]; this.prevent('run'); path = base + '/' + name + '.coffee'; @@ -10073,19 +11104,22 @@ return this; }; App.controller = function() { var names; names = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + Batman.developer.deprecated("App.controller", requireDeprecated); names = names.map(function(n) { return n + '_controller'; }); return this.require.apply(this, ['controllers'].concat(__slice.call(names))); }; App.model = function() { + Batman.developer.deprecated("App.model", requireDeprecated); return this.require.apply(this, ['models'].concat(__slice.call(arguments))); }; return App.view = function() { + Batman.developer.deprecated("App.view", requireDeprecated); return this.require.apply(this, ['views'].concat(__slice.call(arguments))); }; }); App.layout = void 0; @@ -10107,12 +11141,11 @@ App.event('ready').oneShot = true; App.event('run').oneShot = true; App.run = function() { - var layout, layoutClass, - _this = this; + var layout, layoutClass, _this = this; if (Batman.currentApp) { if (Batman.currentApp === this) { return; } Batman.currentApp.stop(); @@ -10214,11 +11247,11 @@ name: Batman.helpers.camelize(Batman.helpers.singularize(this.label)) }; this.options = Batman.extend(defaultOptions, this.defaultOptions, options); if (this.options.nestUrl) { if (!(this.model.urlNestsUnder != null)) { - developer.error("You must persist the the model " + this.model.constructor.name + " to use the url helpers on an association"); + Batman.developer.error("You must persist the the model " + this.model.constructor.name + " to use the url helpers on an association"); } this.model.urlNestsUnder(Batman.helpers.underscore(this.getRelatedModel().get('resourceName'))); } if (this.options.extend != null) { Batman.extend(this, this.options.extend); @@ -10259,12 +11292,11 @@ Association.prototype.setIntoAttributes = function(record, value) { return record.get('attributes').set(this.label, value); }; Association.prototype.inverse = function() { - var inverse, relatedAssocs, - _this = this; + var inverse, relatedAssocs, _this = this; if (relatedAssocs = this.getRelatedModel()._batman.get('associations')) { if (this.options.inverseOf) { return relatedAssocs.getByLabel(this.options.inverseOf); } inverse = null; @@ -10288,11 +11320,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PluralAssociation = (function(_super) { __extends(PluralAssociation, _super); @@ -10304,12 +11347,11 @@ PluralAssociation.__super__.constructor.apply(this, arguments); this._resetSetHashes(); } PluralAssociation.prototype.setForRecord = function(record) { - var childModelSetIndex, indexValue, - _this = this; + var childModelSetIndex, indexValue, _this = this; indexValue = this.indexValueForRecord(record); childModelSetIndex = this.setIndex(); Batman.Property.withoutTracking(function() { return _this._setsByRecord.getOrSet(record, function() { var existingValueSet, newSet; @@ -10317,11 +11359,11 @@ existingValueSet = _this._setsByValue.get(indexValue); if (existingValueSet != null) { return existingValueSet; } } - newSet = new _this.proxyClass(indexValue, _this); + newSet = _this.proxyClassInstanceForKey(indexValue); if (indexValue != null) { _this._setsByValue.set(indexValue, newSet); } return newSet; }); @@ -10332,12 +11374,11 @@ return this._setsByRecord.get(record); } }; PluralAssociation.prototype.setForKey = Batman.Property.wrapTrackingPrevention(function(indexValue) { - var foundSet, - _this = this; + var foundSet, _this = this; foundSet = void 0; this._setsByRecord.forEach(function(record, set) { if (foundSet != null) { return; } @@ -10348,17 +11389,20 @@ if (foundSet != null) { foundSet.foreignKeyValue = indexValue; return foundSet; } return this._setsByValue.getOrSet(indexValue, function() { - return new _this.proxyClass(indexValue, _this); + return _this.proxyClassInstanceForKey(indexValue); }); }); + PluralAssociation.prototype.proxyClassInstanceForKey = function(indexValue) { + return new this.proxyClass(indexValue, this); + }; + PluralAssociation.prototype.getAccessor = function(self, model, label) { - var relatedRecords, setInAttributes, - _this = this; + var relatedRecords, setInAttributes, _this = this; if (!self.getRelatedModel()) { return; } if (setInAttributes = self.getFromAttributes(this)) { return setInAttributes; @@ -10408,11 +11452,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.HasManyAssociation = (function(_super) { __extends(HasManyAssociation, _super); @@ -10422,22 +11477,23 @@ function HasManyAssociation(model, label, options) { if (options != null ? options.as : void 0) { return (function(func, args, ctor) { ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; + var child = new ctor, + result = func.apply(child, args), + t = typeof result; return t == "object" || t == "function" ? result || child : child; - })(Batman.PolymorphicHasManyAssociation, arguments, function(){}); + })(Batman.PolymorphicHasManyAssociation, arguments, function() {}); } HasManyAssociation.__super__.constructor.apply(this, arguments); this.primaryKey = this.options.primaryKey || "id"; this.foreignKey = this.options.foreignKey || ("" + (Batman.helpers.underscore(model.get('resourceName'))) + "_id"); } HasManyAssociation.prototype.apply = function(baseSaveError, base) { - var relations, set, - _this = this; + var relations, set, _this = this; if (!baseSaveError) { if (relations = this.getFromAttributes(base)) { relations.forEach(function(model) { return model.set(_this.foreignKey, base.get(_this.primaryKey)); }); @@ -10520,11 +11576,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PolymorphicHasManyAssociation = (function(_super) { __extends(PolymorphicHasManyAssociation, _super); @@ -10540,12 +11607,11 @@ this.foreignTypeKey = options.foreignTypeKey || ("" + this.foreignLabel + "_type"); this.model.encode(this.foreignTypeKey); } PolymorphicHasManyAssociation.prototype.apply = function(baseSaveError, base) { - var relations, - _this = this; + var relations, _this = this; if (!baseSaveError) { if (relations = this.getFromAttributes(base)) { PolymorphicHasManyAssociation.__super__.apply.apply(this, arguments); relations.forEach(function(model) { return model.set(_this.foreignTypeKey, _this.modelType()); @@ -10553,22 +11619,37 @@ } } return true; }; - PolymorphicHasManyAssociation.prototype.getRelatedModelForType = function() { - return this.getRelatedModel(); + PolymorphicHasManyAssociation.prototype.proxyClassInstanceForKey = function(indexValue) { + return new this.proxyClass(indexValue, this.modelType(), this); }; + PolymorphicHasManyAssociation.prototype.getRelatedModelForType = function(type) { + var relatedModel, scope; + scope = this.options.namespace || Batman.currentApp; + if (type) { + relatedModel = scope != null ? scope[type] : void 0; + relatedModel || (relatedModel = scope != null ? scope[Batman.helpers.camelize(type)] : void 0); + } else { + relatedModel = this.getRelatedModel(); + } + Batman.developer["do"](function() { + if ((Batman.currentApp != null) && !relatedModel) { + return Batman.developer.warn("Related model " + type + " for polymorphic association not found."); + } + }); + return relatedModel; + }; + PolymorphicHasManyAssociation.prototype.modelType = function() { return this.model.get('resourceName'); }; PolymorphicHasManyAssociation.prototype.setIndex = function() { - if (!this.typeIndex) { - this.typeIndex = new Batman.PolymorphicAssociationSetIndex(this, this.modelType(), this[this.indexRelatedModelOn]); - } + this.typeIndex || (this.typeIndex = new Batman.PolymorphicAssociationSetIndex(this, this.modelType(), this[this.indexRelatedModelOn])); return this.typeIndex; }; PolymorphicHasManyAssociation.prototype.encoder = function() { var association; @@ -10587,19 +11668,77 @@ } return jsonArray; }; }; + PolymorphicHasManyAssociation.prototype.decoder = function() { + var association; + association = this; + return function(data, key, _, __, parentRecord) { + var existingRecord, existingRelations, jsonObject, newRelations, record, relatedModel, savedRecord, subType, type, _i, _len; + if (relatedModel = association.getRelatedModel()) { + existingRelations = association.getFromAttributes(parentRecord) || association.setForRecord(parentRecord); + newRelations = existingRelations.filter(function(relation) { + return relation.isNew(); + }).toArray(); + for (_i = 0, _len = data.length; _i < _len; _i++) { + jsonObject = data[_i]; + type = jsonObject[association.options.foreignTypeKey]; + subType = association.getRelatedModelForType(type); + record = new subType(); + record._withoutDirtyTracking(function() { + return this.fromJSON(jsonObject); + }); + existingRecord = relatedModel.get('loaded').indexedByUnique('id').get(record.get('id')); + if (existingRecord != null) { + existingRecord._withoutDirtyTracking(function() { + return this.fromJSON(jsonObject); + }); + record = existingRecord; + } else { + if (newRelations.length > 0) { + savedRecord = newRelations.shift(); + savedRecord._withoutDirtyTracking(function() { + return this.fromJSON(jsonObject); + }); + record = savedRecord; + } + } + record = relatedModel._mapIdentity(record); + existingRelations.add(record); + if (association.options.inverseOf) { + record.set(association.options.inverseOf, parentRecord); + } + } + existingRelations.markAsLoaded(); + } else { + Batman.developer.error("Can't decode model " + association.options.name + " because it hasn't been loaded yet!"); + } + return existingRelations; + }; + }; + return PolymorphicHasManyAssociation; })(Batman.HasManyAssociation); }).call(this); (function() { var __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; }; + __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; + }; Batman.SingularAssociation = (function(_super) { __extends(SingularAssociation, _super); @@ -10651,11 +11790,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.HasOneAssociation = (function(_super) { __extends(HasOneAssociation, _super); @@ -10716,11 +11866,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.BelongsToAssociation = (function(_super) { __extends(BelongsToAssociation, _super); @@ -10739,13 +11900,15 @@ function BelongsToAssociation(model, label, options) { if (options != null ? options.polymorphic : void 0) { delete options.polymorphic; return (function(func, args, ctor) { ctor.prototype = func.prototype; - var child = new ctor, result = func.apply(child, args), t = typeof result; + var child = new ctor, + result = func.apply(child, args), + t = typeof result; return t == "object" || t == "function" ? result || child : child; - })(Batman.PolymorphicBelongsToAssociation, arguments, function(){}); + })(Batman.PolymorphicBelongsToAssociation, arguments, function() {}); } BelongsToAssociation.__super__.constructor.apply(this, arguments); this.foreignKey = this.options.foreignKey || ("" + this.label + "_id"); this.primaryKey = this.options.primaryKey || "id"; if (this.options.encodeForeignKey) { @@ -10796,11 +11959,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PolymorphicBelongsToAssociation = (function(_super) { __extends(PolymorphicBelongsToAssociation, _super); @@ -10826,19 +12000,14 @@ PolymorphicBelongsToAssociation.prototype.setIndex = false; PolymorphicBelongsToAssociation.prototype.inverse = false; PolymorphicBelongsToAssociation.prototype.apply = function(base) { - var foreignTypeValue, instanceOrProxy, model; + var foreignTypeValue, instanceOrProxy; PolymorphicBelongsToAssociation.__super__.apply.apply(this, arguments); if (instanceOrProxy = base.get(this.label)) { - if (instanceOrProxy instanceof Batman.AssociationProxy) { - model = instanceOrProxy.association.model; - } else { - model = instanceOrProxy.constructor; - } - foreignTypeValue = model.get('resourceName'); + foreignTypeValue = instanceOrProxy instanceof Batman.PolymorphicBelongsToProxy ? instanceOrProxy.get('foreignTypeValue') : instanceOrProxy.constructor.get('resourceName'); return base.set(this.foreignTypeKey, foreignTypeValue); } }; PolymorphicBelongsToAssociation.prototype.getAccessor = function(self, model, label) { @@ -10889,12 +12058,11 @@ (_base = this.typeIndicies)[type] || (_base[type] = new Batman.PolymorphicUniqueAssociationSetIndex(this, type, this.primaryKey)); return this.typeIndicies[type]; }; PolymorphicBelongsToAssociation.prototype.inverseForType = function(type) { - var inverse, relatedAssocs, _ref, - _this = this; + var inverse, relatedAssocs, _ref, _this = this; if (relatedAssocs = (_ref = this.getRelatedModelForType(type)) != null ? _ref._batman.get('associations') : void 0) { if (this.options.inverseOf) { return relatedAssocs.getByLabel(this.options.inverseOf); } inverse = null; @@ -10936,11 +12104,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.Validator = (function(_super) { __extends(Validator, _super); @@ -10969,14 +12148,14 @@ var key, results, shouldReturn, value, _ref, _ref1; results = {}; shouldReturn = false; for (key in options) { value = options[key]; - if (~((_ref = this._options) != null ? _ref.indexOf(key) : void 0)) { + if (~ ((_ref = this._options) != null ? _ref.indexOf(key) : void 0)) { results[key] = value; } - if (~((_ref1 = this._triggers) != null ? _ref1.indexOf(key) : void 0)) { + if (~ ((_ref1 = this._triggers) != null ? _ref1.indexOf(key) : void 0)) { results[key] = value; shouldReturn = true; } } if (shouldReturn) { @@ -11037,11 +12216,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.RegExpValidator = (function(_super) { __extends(RegExpValidator, _super); @@ -11075,11 +12265,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.PresenceValidator = (function(_super) { __extends(PresenceValidator, _super); @@ -11110,11 +12311,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.NumericValidator = (function(_super) { __extends(NumericValidator, _super); @@ -11181,11 +12393,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.LengthValidator = (function(_super) { __extends(LengthValidator, _super); @@ -11240,11 +12463,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.AssociatedValidator = (function(_super) { __extends(AssociatedValidator, _super); @@ -11253,12 +12487,11 @@ } AssociatedValidator.triggers('associated'); AssociatedValidator.prototype.validateEach = function(errors, record, key, callback) { - var childFinished, count, value, - _this = this; + var childFinished, count, value, _this = this; value = record.get(key); if (value != null) { if (value instanceof Batman.AssociationProxy) { value = typeof value.get === "function" ? value.get('target') : void 0; } @@ -11294,11 +12527,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.ControllerActionFrame = (function(_super) { __extends(ControllerActionFrame, _super); @@ -11308,11 +12552,11 @@ ControllerActionFrame.prototype.event('complete').oneShot = true; function ControllerActionFrame(options, onComplete) { ControllerActionFrame.__super__.constructor.call(this, options); - this.on('complete', onComplete); + this.once('complete', onComplete); } ControllerActionFrame.prototype.startOperation = function(options) { if (options == null) { options = {}; @@ -11352,40 +12596,50 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.DOM.InsertionBinding = (function(_super) { __extends(InsertionBinding, _super); InsertionBinding.prototype.isTwoWay = false; InsertionBinding.prototype.bindImmediately = false; - function InsertionBinding(node, className, key, context, parentRenderer, invert) { - var result, - _this = this; - this.invert = invert != null ? invert : false; + InsertionBinding.prototype.onlyObserve = Batman.BindingDefinitionOnlyObserve.Data; + + function InsertionBinding(definition) { + var _this = this; + this.invert = definition.invert; this.placeholderNode = document.createComment("detached node " + (this.get('_batmanID'))); - result = InsertionBinding.__super__.constructor.apply(this, arguments); + InsertionBinding.__super__.constructor.apply(this, arguments); Batman.DOM.onParseExit(this.node, function() { _this.bind(); if (_this.placeholderNode != null) { return Batman.DOM.trackBinding(_this, _this.placeholderNode); } }); - result; - } InsertionBinding.prototype.dataChange = function(value) { var parentNode; parentNode = this.placeholderNode.parentNode || this.node.parentNode; - if (!!value === !this.invert) { + if ( !! value === !this.invert) { if (!(this.node.parentNode != null)) { Batman.DOM.insertBefore(parentNode, this.node, this.placeholderNode); return parentNode.removeChild(this.placeholderNode); } } else { @@ -11395,18 +12649,21 @@ } } }; InsertionBinding.prototype.die = function() { + var filteredValue, node, placeholderNode; if (this.dead) { return; } + node = this.node, placeholderNode = this.placeholderNode; + filteredValue = this.get('filteredValue'); InsertionBinding.__super__.die.apply(this, arguments); - if (!!this.get('filteredValue') === !this.invert) { - return Batman.DOM.destroyNode(this.placeholderNode); + if ( !! filteredValue === !this.invert) { + return Batman.DOM.destroyNode(placeholderNode); } else { - return Batman.DOM.destroyNode(this.node); + return Batman.DOM.destroyNode(node); } }; return InsertionBinding; @@ -11553,12 +12810,11 @@ }); }).call(this); (function() { - var buntUndefined, defaultAndOr, - __slice = [].slice; + var buntUndefined, defaultAndOr, __slice = [].slice; buntUndefined = function(f) { return function(value) { if (value == null) { return void 0; @@ -11750,11 +13006,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.RenderContext = (function() { var ContextProxy; RenderContext.deProxy = function(object) { @@ -11813,14 +13080,14 @@ object[scopedKey] = oldObject; } return new this.constructor(object, this); }; - RenderContext.prototype.descendWithKey = function(key, scopedKey) { + RenderContext.prototype.descendWithDefinition = function(definition) { var proxy; - proxy = new ContextProxy(this, key); - return this.descend(proxy, scopedKey); + proxy = new ContextProxy(definition); + return this.descend(proxy, definition.attr); }; RenderContext.prototype.chain = function() { var parent, x; x = []; @@ -11852,15 +13119,12 @@ unset: function(key) { return this.unset("proxiedObject." + key); } }); - function ContextProxy(renderContext, keyPath, localKey) { - this.renderContext = renderContext; - this.keyPath = keyPath; - this.localKey = localKey; - this.binding = new Batman.DOM.AbstractBinding(void 0, this.keyPath, this.renderContext); + function ContextProxy(definition) { + this.binding = new Batman.DOM.AbstractBinding(definition); } return ContextProxy; })(Batman.Object); @@ -11873,11 +13137,22 @@ }).call(this); (function() { var __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; }; + __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; + }; Batman.ViewStore = (function(_super) { __extends(ViewStore, _super); @@ -11905,11 +13180,11 @@ ViewStore.accessor({ 'final': true, get: function(path) { var contents; - if (path[0] !== '/') { + if (path.charAt(0) !== '/') { return this.get("/" + path); } if (this._viewContents[path]) { return this._viewContents[path]; } @@ -11924,11 +13199,11 @@ } else { throw new Error("Couldn't find view source for \'" + path + "\'!"); } }, set: function(path, content) { - if (path[0] !== '/') { + if (path.charAt(0) !== '/') { return this.set("/" + path, content); } this._requestedPaths.add(path); return this._viewContents[path] = content; } @@ -11957,11 +13232,22 @@ }).call(this); (function() { var __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; }, + __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; + }, __slice = [].slice; Batman.View = (function(_super) { __extends(View, _super); @@ -12023,11 +13309,11 @@ View.prototype.event('ready').oneShot = true; View.accessor('argumentBindings', function() { var _this = this; return new Batman.TerminalAccessible(function(key) { - var bindingKey, context, keyPath, node, _ref; + var bindingKey, context, definition, keyPath, node, _ref; if (!((node = _this.get('node')) && (context = _this.get('context')))) { return; } keyPath = node.getAttribute(("data-view-" + key).toLowerCase()); if (keyPath == null) { @@ -12035,11 +13321,12 @@ } bindingKey = "_argumentBinding" + key; if ((_ref = _this[bindingKey]) != null) { _ref.die(); } - return _this[bindingKey] = new Batman.DOM.ViewArgumentBinding(node, keyPath, context); + definition = new Batman.DOM.ReaderBindingDefinition(node, keyPath, context); + return _this[bindingKey] = new Batman.DOM.ViewArgumentBinding(definition); }); }); View.accessor('html', { get: function() { @@ -12071,12 +13358,11 @@ Batman.DOM.setInnerHTML(this.node, html); } return this.node; }, set: function(_, node) { - var updateHTML, - _this = this; + var updateHTML, _this = this; this.node = node; this._setNodeOwner(node); updateHTML = function(html) { if (html != null) { Batman.DOM.setInnerHTML(_this.node, html); @@ -12100,12 +13386,11 @@ var _ref; return this.get('node') && (this.get('fetched?') ? ((_ref = this.get('html')) != null ? _ref.length : void 0) > 0 : true); }); function View(options) { - var context, - _this = this; + var context, _this = this; if (options == null) { options = {}; } context = options.context; if (context) { @@ -12125,18 +13410,17 @@ }); }); } View.prototype.render = function() { - var node, - _this = this; + var node, _this = this; if (this._rendered) { return; } this._rendered = true; this._renderer = new Batman.Renderer(node = this.get('node'), this.get('context'), this); - return this._renderer.on('rendered', function() { + return this._renderer.once('rendered', function() { return _this.fire('ready', node); }); }; View.prototype.isInDOM = function() { @@ -12155,10 +13439,30 @@ } else { return false; } }; + View.prototype.die = function() { + var _ref; + this.fire('destroy', this.node); + this.forget(); + if ((_ref = this._batman.properties) != null) { + _ref.forEach(function(key, property) { + return property.die(); + }); + } + return this.get('yields').forEach(function(name, actions) { + var node, _i, _len, _results; + _results = []; + for (_i = 0, _len = actions.length; _i < _len; _i++) { + node = actions[_i].node; + _results.push(Batman.DOM.didDestroyNode(node)); + } + return _results; + }); + }; + View.prototype.applyYields = function() { return this.get('yields').forEach(function(name, nodes) { var action, node, yieldObject, _i, _len, _ref, _results; yieldObject = Batman.DOM.Yield.withName(name); _results = []; @@ -12223,24 +13527,33 @@ }).call(this, Batman.Object); }).call(this); (function() { - var Yield, - __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; }, + var Yield, __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; + }, __slice = [].slice; Batman.DOM.Yield = Yield = (function(_super) { __extends(Yield, _super); Yield.yields = {}; Yield.queued = function(fn) { return function() { - var args, handler, - _this = this; + var args, handler, _this = this; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (this.containerNode != null) { return fn.apply(this, args); } else { return handler = this.observe('containerNode', function() { \ No newline at end of file