Commit 79bba43d authored by Artem Yavorsky's avatar Artem Yavorsky Committed by Sindre Sorhus

Close #1165 PR: Chaplin: Update to NPM, Fix bugs.

parent 9c5f7870
bower_components/ node_modules/chaplin/*
!bower_components/todomvc-common/ !node_modules/chaplin/chaplin.js
# NPM packages folder. node_modules/exoskeleton/*
node_modules/ !node_modules/exoskeleton/exoskeleton.js
# Brunch folder for temporary files. node_modules/backbone.localstorage/*
tmp/ !node_modules/backbone.localstorage/backbone.localStorage.js
node_modules/backbone.nativeview/*
!node_modules/backbone.nativeview/backbone.nativeview.js
node_modules/todomvc-app-css/*
!node_modules/todomvc-app-css/index.css
node_modules/todomvc-common/*
!node_modules/todomvc-common/base.css
!node_modules/todomvc-common/base.js
node_modules/coffee-script-brunch/*
node_modules/javascript-brunch/*
node_modules/handlebars-brunch/*
node_modules/uglify-js-brunch/*
tmp/*
...@@ -3,8 +3,14 @@ ...@@ -3,8 +3,14 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Chaplin &amp; Brunch • TodoMVC</title> <title>Chaplin &amp; Brunch • TodoMVC</title>
<link rel="stylesheet" href="../bower_components/todomvc-common/base.css"> <link rel="stylesheet" href="../node_modules/todomvc-common/base.css">
<link rel="stylesheet" href="../bower_components/todomvc-common/base.js"> <link rel="stylesheet" href="../node_modules/todomvc-app-css/index.css">
<script src="../node_modules/todomvc-common/base.js"></script>
<script src="../node_modules/exoskeleton/exoskeleton.js"></script>
<script src="../node_modules/backbone.nativeview/backbone.nativeview.js"></script>
<script src="../node_modules/backbone.localstorage/backbone.localStorage.js"></script>
<script src="vendor.js"></script>
<script src="../node_modules/chaplin/chaplin.js"></script>
<script src="app.js"></script> <script src="app.js"></script>
<script>require('initialize');</script> <script>require('initialize');</script>
</head> </head>
......
...@@ -14,7 +14,4 @@ ...@@ -14,7 +14,4 @@
<a href="#/completed">Completed</a> <a href="#/completed">Completed</a>
</li> </li>
</ul> </ul>
<button id="clear-completed"> <button id="clear-completed">Clear completed <span id="completed-count"></span></button>
Clear completed
<span id="completed-count"></span>
</button>
...@@ -14,6 +14,14 @@ module.exports = class TodoView extends View ...@@ -14,6 +14,14 @@ module.exports = class TodoView extends View
template: require './templates/todo' template: require './templates/todo'
tagName: 'li' tagName: 'li'
render: ->
super
@toggleClass()
toggleClass: ->
isCompleted = @model.get('completed')
@el.classList.toggle 'completed', isCompleted
clear: -> clear: ->
@model.destroy() @model.destroy()
...@@ -22,7 +30,9 @@ module.exports = class TodoView extends View ...@@ -22,7 +30,9 @@ module.exports = class TodoView extends View
edit: -> edit: ->
@el.classList.add 'editing' @el.classList.add 'editing'
@find('.edit').focus() input = @find('.edit')
input.focus()
input.value = input.value;
save: (event) -> save: (event) ->
ENTER_KEY = 13 ENTER_KEY = 13
......
...@@ -18,7 +18,7 @@ module.exports = class TodosView extends CollectionView ...@@ -18,7 +18,7 @@ module.exports = class TodosView extends CollectionView
@renderCheckbox() @renderCheckbox()
renderCheckbox: -> renderCheckbox: ->
@find('#toggle-all').setAttribute 'checked', @collection.allAreCompleted() @find('#toggle-all').checked = @collection.allAreCompleted()
utils.toggle @el, @collection.length isnt 0 utils.toggle @el, @collection.length isnt 0
toggleCompleted: (event) -> toggleCompleted: (event) ->
......
{
"name": "todomvc-chaplin-brunch",
"version": "0.0.0",
"dependencies": {
"todomvc-common": "~0.3.0",
"chaplin": "~1.0.0",
"exoskeleton": "~0.6.3",
"backbone.localStorage": "git://github.com/paulmillr/Backbone.localStorage.git#9c225b37bdea4ac21d4b2445fa8962fe74e3175b"
},
"overrides": {
"todomvc-common": {
"main": "bg.png"
},
"chaplin": {
"dependencies": {
"exoskeleton": "*"
}
}
}
}
...@@ -2,7 +2,9 @@ exports.config = ...@@ -2,7 +2,9 @@ exports.config =
# See http://brunch.readthedocs.org/en/latest/config.html for documentation. # See http://brunch.readthedocs.org/en/latest/config.html for documentation.
files: files:
javascripts: javascripts:
joinTo: 'app.js' joinTo:
'app.js': /^app/
'vendor.js': /^vendor/
stylesheets: stylesheets:
joinTo: 'app.css' joinTo: 'app.css'
......
/**
* Backbone localStorage Adapter
* Version 1.1.16
*
* https://github.com/jeromegn/Backbone.localStorage
*/
(function (root, factory) {
if (typeof exports === 'object' && typeof require === 'function') {
module.exports = factory(require("backbone"));
} else if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(["backbone"], function(Backbone) {
// Use global variables if the locals are undefined.
return factory(Backbone || root.Backbone);
});
} else {
factory(Backbone);
}
}(this, function(Backbone) {
// A simple module to replace `Backbone.sync` with *localStorage*-based
// persistence. Models are given GUIDS, and saved into a JSON object. Simple
// as that.
// Generate four random hex digits.
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
// Generate a pseudo-GUID by concatenating random hexadecimal.
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
};
function isObject(item) {
return item === Object(item);
}
function contains(array, item) {
var i = array.length;
while (i--) if (array[i] === item) return true;
return false;
}
function extend(obj, props) {
for (var key in props) obj[key] = props[key]
return obj;
}
function result(object, property) {
if (object == null) return void 0;
var value = object[property];
return (typeof value === 'function') ? object[property]() : value;
}
// Our Store is represented by a single JS object in *localStorage*. Create it
// with a meaningful name, like the name you'd give a table.
// window.Store is deprectated, use Backbone.LocalStorage instead
Backbone.LocalStorage = window.Store = function(name, serializer) {
if( !this.localStorage ) {
throw "Backbone.localStorage: Environment does not support localStorage."
}
this.name = name;
this.serializer = serializer || {
serialize: function(item) {
return isObject(item) ? JSON.stringify(item) : item;
},
// fix for "illegal access" error on Android when JSON.parse is passed null
deserialize: function (data) {
return data && JSON.parse(data);
}
};
var store = this.localStorage().getItem(this.name);
this.records = (store && store.split(",")) || [];
};
extend(Backbone.LocalStorage.prototype, {
// Save the current state of the **Store** to *localStorage*.
save: function() {
this.localStorage().setItem(this.name, this.records.join(","));
},
// Add a model, giving it a (hopefully)-unique GUID, if it doesn't already
// have an id of it's own.
create: function(model) {
if (!model.id && model.id !== 0) {
model.id = guid();
model.set(model.idAttribute, model.id);
}
this.localStorage().setItem(this._itemName(model.id), this.serializer.serialize(model));
this.records.push(model.id.toString());
this.save();
return this.find(model);
},
// Update a model by replacing its copy in `this.data`.
update: function(model) {
this.localStorage().setItem(this._itemName(model.id), this.serializer.serialize(model));
var modelId = model.id.toString();
if (!contains(this.records, modelId)) {
this.records.push(modelId);
this.save();
}
return this.find(model);
},
// Retrieve a model from `this.data` by id.
find: function(model) {
return this.serializer.deserialize(this.localStorage().getItem(this._itemName(model.id)));
},
// Return the array of all models currently in storage.
findAll: function() {
var result = [];
for (var i = 0, id, data; i < this.records.length; i++) {
id = this.records[i];
data = this.serializer.deserialize(this.localStorage().getItem(this._itemName(id)));
if (data != null) result.push(data);
}
return result;
},
// Delete a model from `this.data`, returning it.
destroy: function(model) {
this.localStorage().removeItem(this._itemName(model.id));
var modelId = model.id.toString();
for (var i = 0, id; i < this.records.length; i++) {
if (this.records[i] === modelId) {
this.records.splice(i, 1);
}
}
this.save();
return model;
},
localStorage: function() {
return localStorage;
},
// Clear localStorage for specific collection.
_clear: function() {
var local = this.localStorage(),
itemRe = new RegExp("^" + this.name + "-");
// Remove id-tracking item (e.g., "foo").
local.removeItem(this.name);
// Match all data items (e.g., "foo-ID") and remove.
for (var k in local) {
if (itemRe.test(k)) {
local.removeItem(k);
}
}
this.records.length = 0;
},
// Size of localStorage.
_storageSize: function() {
return this.localStorage().length;
},
_itemName: function(id) {
return this.name+"-"+id;
}
});
// localSync delegate to the model or collection's
// *localStorage* property, which should be an instance of `Store`.
// window.Store.sync and Backbone.localSync is deprecated, use Backbone.LocalStorage.sync instead
Backbone.LocalStorage.sync = window.Store.sync = Backbone.localSync = function(method, model, options) {
var store = result(model, 'localStorage') || result(model.collection, 'localStorage');
var resp, errorMessage;
//If $ is having Deferred - use it.
var syncDfd = Backbone.$ ?
(Backbone.$.Deferred && Backbone.$.Deferred()) :
(Backbone.Deferred && Backbone.Deferred());
try {
switch (method) {
case "read":
resp = model.id != undefined ? store.find(model) : store.findAll();
break;
case "create":
resp = store.create(model);
break;
case "update":
resp = store.update(model);
break;
case "delete":
resp = store.destroy(model);
break;
}
} catch(error) {
if (error.code === 22 && store._storageSize() === 0)
errorMessage = "Private browsing is unsupported";
else
errorMessage = error.message;
}
if (resp) {
if (options && options.success) {
if (Backbone.VERSION === "0.9.10") {
options.success(model, resp, options);
} else {
options.success(resp);
}
}
if (syncDfd) {
syncDfd.resolve(resp);
}
} else {
errorMessage = errorMessage ? errorMessage
: "Record Not Found";
if (options && options.error)
if (Backbone.VERSION === "0.9.10") {
options.error(model, errorMessage, options);
} else {
options.error(errorMessage);
}
if (syncDfd)
syncDfd.reject(errorMessage);
}
// add compatibility with $.ajax
// always execute callback for success and error
if (options && options.complete) options.complete(resp);
return syncDfd && syncDfd.promise();
};
Backbone.ajaxSync = Backbone.sync;
Backbone.getSyncMethod = function(model, options) {
var forceAjaxSync = options && options.ajaxSync;
if(!forceAjaxSync && (result(model, 'localStorage') || result(model.collection, 'localStorage'))) {
return Backbone.localSync;
}
return Backbone.ajaxSync;
};
// Override 'Backbone.sync' to default to localSync,
// the original 'Backbone.sync' is still available in 'Backbone.ajaxSync'
Backbone.sync = function(method, model, options) {
return Backbone.getSyncMethod(model, options).apply(this, [method, model, options]);
};
return Backbone.LocalStorage;
}));
// Backbone.NativeView.js 0.3.2
// ---------------
// (c) 2014 Adam Krebs, Jimmy Yuen Ho Wong
// Backbone.NativeView may be freely distributed under the MIT license.
// For all details and documentation:
// https://github.com/akre54/Backbone.NativeView
(function (factory) {
if (typeof define === 'function' && define.amd) { define(['backbone'], factory);
} else if (typeof exports === 'object') { factory(require('backbone'));
} else { factory(Backbone); }
}(function (Backbone) {
// Cached regex to match an opening '<' of an HTML tag, possibly left-padded
// with whitespace.
var paddedLt = /^\s*</;
// Caches a local reference to `Element.prototype` for faster access.
var ElementProto = (typeof Element !== 'undefined' && Element.prototype) || {};
// Cross-browser event listener shims
var elementAddEventListener = ElementProto.addEventListener || function(eventName, listener) {
return this.attachEvent('on' + eventName, listener);
}
var elementRemoveEventListener = ElementProto.removeEventListener || function(eventName, listener) {
return this.detachEvent('on' + eventName, listener);
}
var indexOf = function(array, item) {
for (var i = 0, len = array.length; i < len; i++) if (array[i] === item) return i;
return -1;
}
// Find the right `Element#matches` for IE>=9 and modern browsers.
var matchesSelector = ElementProto.matches ||
ElementProto.webkitMatchesSelector ||
ElementProto.mozMatchesSelector ||
ElementProto.msMatchesSelector ||
ElementProto.oMatchesSelector ||
// Make our own `Element#matches` for IE8
function(selector) {
// Use querySelectorAll to find all elements matching the selector,
// then check if the given element is included in that list.
// Executing the query on the parentNode reduces the resulting nodeList,
// (document doesn't have a parentNode).
var nodeList = (this.parentNode || document).querySelectorAll(selector) || [];
return !!~indexOf(nodeList, this);
};
// Cache Backbone.View for later access in constructor
var BBView = Backbone.View;
// To extend an existing view to use native methods, extend the View prototype
// with the mixin: _.extend(MyView.prototype, Backbone.NativeViewMixin);
Backbone.NativeViewMixin = {
_domEvents: null,
constructor: function() {
this._domEvents = [];
return BBView.apply(this, arguments);
},
$: function(selector) {
return this.el.querySelectorAll(selector);
},
_removeElement: function() {
this.undelegateEvents();
if (this.el.parentNode) this.el.parentNode.removeChild(this.el);
},
// Apply the `element` to the view. `element` can be a CSS selector,
// a string of HTML, or an Element node.
_setElement: function(element) {
if (typeof element == 'string') {
if (paddedLt.test(element)) {
var el = document.createElement('div');
el.innerHTML = element;
this.el = el.firstChild;
} else {
this.el = document.querySelector(element);
}
} else {
this.el = element;
}
},
// Set a hash of attributes to the view's `el`. We use the "prop" version
// if available, falling back to `setAttribute` for the catch-all.
_setAttributes: function(attrs) {
for (var attr in attrs) {
attr in this.el ? this.el[attr] = attrs[attr] : this.el.setAttribute(attr, attrs[attr]);
}
},
// Make a event delegation handler for the given `eventName` and `selector`
// and attach it to `this.el`.
// If selector is empty, the listener will be bound to `this.el`. If not, a
// new handler that will recursively traverse up the event target's DOM
// hierarchy looking for a node that matches the selector. If one is found,
// the event's `delegateTarget` property is set to it and the return the
// result of calling bound `listener` with the parameters given to the
// handler.
delegate: function(eventName, selector, listener) {
if (typeof selector === 'function') {
listener = selector;
selector = null;
}
var root = this.el;
var handler = selector ? function (e) {
var node = e.target || e.srcElement;
for (; node && node != root; node = node.parentNode) {
if (matchesSelector.call(node, selector)) {
e.delegateTarget = node;
listener(e);
}
}
} : listener;
elementAddEventListener.call(this.el, eventName, handler, false);
this._domEvents.push({eventName: eventName, handler: handler, listener: listener, selector: selector});
return handler;
},
// Remove a single delegated event. Either `eventName` or `selector` must
// be included, `selector` and `listener` are optional.
undelegate: function(eventName, selector, listener) {
if (typeof selector === 'function') {
listener = selector;
selector = null;
}
if (this.el) {
var handlers = this._domEvents.slice();
for (var i = 0, len = handlers.length; i < len; i++) {
var item = handlers[i];
var match = item.eventName === eventName &&
(listener ? item.listener === listener : true) &&
(selector ? item.selector === selector : true);
if (!match) continue;
elementRemoveEventListener.call(this.el, item.eventName, item.handler, false);
this._domEvents.splice(indexOf(handlers, item), 1);
}
}
return this;
},
// Remove all events created with `delegate` from `el`
undelegateEvents: function() {
if (this.el) {
for (var i = 0, len = this._domEvents.length; i < len; i++) {
var item = this._domEvents[i];
elementRemoveEventListener.call(this.el, item.eventName, item.handler, false);
};
this._domEvents.length = 0;
}
return this;
}
};
Backbone.NativeView = Backbone.View.extend(Backbone.NativeViewMixin);
return Backbone.NativeView;
}));
/*!
* Chaplin 1.0.1
*
* Chaplin may be freely distributed under the MIT license.
* For all details and documentation:
* http://chaplinjs.org
*/
(function(){
var loader = (function() {
var modules = {};
var cache = {};
var dummy = function() {return function() {};};
var initModule = function(name, definition) {
var module = {id: name, exports: {}};
definition(module.exports, dummy(), module);
var exports = cache[name] = module.exports;
return exports;
};
var loader = function(path) {
if (cache.hasOwnProperty(path)) return cache[path];
if (modules.hasOwnProperty(path)) return initModule(path, modules[path]);
throw new Error('Cannot find module "' + path + '"');
};
loader.register = function(bundle, fn) {
modules[bundle] = fn;
};
return loader;
})();
loader.register('chaplin/application', function(e, r, module) {
'use strict';
var Application, Backbone, Composer, Dispatcher, EventBroker, Layout, Router, mediator, _;
_ = loader('underscore');
Backbone = loader('backbone');
Dispatcher = loader('chaplin/dispatcher');
Layout = loader('chaplin/views/layout');
Composer = loader('chaplin/composer');
Router = loader('chaplin/lib/router');
EventBroker = loader('chaplin/lib/event_broker');
mediator = loader('chaplin/mediator');
module.exports = Application = (function() {
Application.extend = Backbone.Model.extend;
_.extend(Application.prototype, EventBroker);
Application.prototype.title = '';
Application.prototype.dispatcher = null;
Application.prototype.layout = null;
Application.prototype.router = null;
Application.prototype.composer = null;
Application.prototype.started = false;
function Application(options) {
if (options == null) {
options = {};
}
this.initialize(options);
}
Application.prototype.initialize = function(options) {
if (options == null) {
options = {};
}
if (this.started) {
throw new Error('Application#initialize: App was already started');
}
this.initRouter(options.routes, options);
this.initDispatcher(options);
this.initLayout(options);
this.initComposer(options);
this.initMediator();
return this.start();
};
Application.prototype.initDispatcher = function(options) {
return this.dispatcher = new Dispatcher(options);
};
Application.prototype.initLayout = function(options) {
var _ref;
if (options == null) {
options = {};
}
if ((_ref = options.title) == null) {
options.title = this.title;
}
return this.layout = new Layout(options);
};
Application.prototype.initComposer = function(options) {
if (options == null) {
options = {};
}
return this.composer = new Composer(options);
};
Application.prototype.initMediator = function() {
return mediator.seal();
};
Application.prototype.initRouter = function(routes, options) {
this.router = new Router(options);
return typeof routes === "function" ? routes(this.router.match) : void 0;
};
Application.prototype.start = function() {
this.router.startHistory();
this.started = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
Application.prototype.disposed = false;
Application.prototype.dispose = function() {
var prop, properties, _i, _len;
if (this.disposed) {
return;
}
properties = ['dispatcher', 'layout', 'router', 'composer'];
for (_i = 0, _len = properties.length; _i < _len; _i++) {
prop = properties[_i];
if (this[prop] != null) {
this[prop].dispose();
}
}
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Application;
})();
});;loader.register('chaplin/mediator', function(e, r, module) {
'use strict';
var Backbone, handlers, mediator, support, utils, _,
__slice = [].slice;
Backbone = loader('backbone');
_ = loader('underscore');
support = loader('chaplin/lib/support');
utils = loader('chaplin/lib/utils');
mediator = {};
mediator.subscribe = mediator.on = Backbone.Events.on;
mediator.subscribeOnce = mediator.once = Backbone.Events.once;
mediator.unsubscribe = mediator.off = Backbone.Events.off;
mediator.publish = mediator.trigger = Backbone.Events.trigger;
mediator._callbacks = null;
handlers = mediator._handlers = {};
mediator.setHandler = function(name, method, instance) {
return handlers[name] = {
instance: instance,
method: method
};
};
mediator.execute = function() {
var args, handler, name, nameOrObj, silent;
nameOrObj = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
silent = false;
if (typeof nameOrObj === 'object') {
silent = nameOrObj.silent;
name = nameOrObj.name;
} else {
name = nameOrObj;
}
handler = handlers[name];
if (handler) {
return handler.method.apply(handler.instance, args);
} else if (!silent) {
throw new Error("mediator.execute: " + name + " handler is not defined");
}
};
mediator.removeHandlers = function(instanceOrNames) {
var handler, name, _i, _len;
if (!instanceOrNames) {
mediator._handlers = {};
}
if (utils.isArray(instanceOrNames)) {
for (_i = 0, _len = instanceOrNames.length; _i < _len; _i++) {
name = instanceOrNames[_i];
delete handlers[name];
}
} else {
for (name in handlers) {
handler = handlers[name];
if (handler.instance === instanceOrNames) {
delete handlers[name];
}
}
}
};
utils.readonly(mediator, 'subscribe', 'subscribeOnce', 'unsubscribe', 'publish', 'setHandler', 'execute', 'removeHandlers');
mediator.seal = function() {
if (support.propertyDescriptors && Object.seal) {
return Object.seal(mediator);
}
};
utils.readonly(mediator, 'seal');
module.exports = mediator;
});;loader.register('chaplin/dispatcher', function(e, r, module) {
'use strict';
var Backbone, Dispatcher, EventBroker, mediator, utils, _;
_ = loader('underscore');
Backbone = loader('backbone');
mediator = loader('chaplin/mediator');
utils = loader('chaplin/lib/utils');
EventBroker = loader('chaplin/lib/event_broker');
module.exports = Dispatcher = (function() {
Dispatcher.extend = Backbone.Model.extend;
_.extend(Dispatcher.prototype, EventBroker);
Dispatcher.prototype.previousRoute = null;
Dispatcher.prototype.currentController = null;
Dispatcher.prototype.currentRoute = null;
Dispatcher.prototype.currentParams = null;
Dispatcher.prototype.currentQuery = null;
function Dispatcher() {
this.initialize.apply(this, arguments);
}
Dispatcher.prototype.initialize = function(options) {
if (options == null) {
options = {};
}
this.settings = _.defaults(options, {
controllerPath: 'controllers/',
controllerSuffix: '_controller'
});
return this.subscribeEvent('router:match', this.dispatch);
};
Dispatcher.prototype.dispatch = function(route, params, options) {
var _ref, _ref1,
_this = this;
params = params ? _.extend({}, params) : {};
options = options ? _.extend({}, options) : {};
if (!(options.query != null)) {
options.query = {};
}
if (options.forceStartup !== true) {
options.forceStartup = false;
}
if (!options.forceStartup && ((_ref = this.currentRoute) != null ? _ref.controller : void 0) === route.controller && ((_ref1 = this.currentRoute) != null ? _ref1.action : void 0) === route.action && _.isEqual(this.currentParams, params) && _.isEqual(this.currentQuery, options.query)) {
return;
}
return this.loadController(route.controller, function(Controller) {
return _this.controllerLoaded(route, params, options, Controller);
});
};
Dispatcher.prototype.loadController = function(name, handler) {
var fileName, moduleName,
_this = this;
fileName = name + this.settings.controllerSuffix;
moduleName = this.settings.controllerPath + fileName;
if (typeof define !== "undefined" && define !== null ? define.amd : void 0) {
return require([moduleName], handler);
} else {
return setTimeout(function() {
return handler(require(moduleName));
}, 0);
}
};
Dispatcher.prototype.controllerLoaded = function(route, params, options, Controller) {
var controller, prev, previous;
if (this.nextPreviousRoute = this.currentRoute) {
previous = _.extend({}, this.nextPreviousRoute);
if (this.currentParams != null) {
previous.params = this.currentParams;
}
if (previous.previous) {
delete previous.previous;
}
prev = {
previous: previous
};
}
this.nextCurrentRoute = _.extend({}, route, prev);
controller = new Controller(params, this.nextCurrentRoute, options);
return this.executeBeforeAction(controller, this.nextCurrentRoute, params, options);
};
Dispatcher.prototype.executeAction = function(controller, route, params, options) {
if (this.currentController) {
this.publishEvent('beforeControllerDispose', this.currentController);
this.currentController.dispose(params, route, options);
}
this.currentController = controller;
this.currentParams = params;
this.currentQuery = options.query;
controller[route.action](params, route, options);
if (controller.redirected) {
return;
}
return this.publishEvent('dispatcher:dispatch', this.currentController, params, route, options);
};
Dispatcher.prototype.executeBeforeAction = function(controller, route, params, options) {
var before, executeAction, promise,
_this = this;
before = controller.beforeAction;
executeAction = function() {
if (controller.redirected || _this.currentRoute && route === _this.currentRoute) {
_this.nextPreviousRoute = _this.nextCurrentRoute = null;
controller.dispose();
return;
}
_this.previousRoute = _this.nextPreviousRoute;
_this.currentRoute = _this.nextCurrentRoute;
_this.nextPreviousRoute = _this.nextCurrentRoute = null;
return _this.executeAction(controller, route, params, options);
};
if (!before) {
executeAction();
return;
}
if (typeof before !== 'function') {
throw new TypeError('Controller#beforeAction: function expected. ' + 'Old object-like form is not supported.');
}
promise = controller.beforeAction(params, route, options);
if (promise && promise.then) {
return promise.then(executeAction);
} else {
return executeAction();
}
};
Dispatcher.prototype.disposed = false;
Dispatcher.prototype.dispose = function() {
if (this.disposed) {
return;
}
this.unsubscribeAllEvents();
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Dispatcher;
})();
});;loader.register('chaplin/composer', function(e, r, module) {
'use strict';
var Backbone, Composer, Composition, EventBroker, mediator, utils, _;
_ = loader('underscore');
Backbone = loader('backbone');
mediator = loader('chaplin/mediator');
utils = loader('chaplin/lib/utils');
Composition = loader('chaplin/lib/composition');
EventBroker = loader('chaplin/lib/event_broker');
module.exports = Composer = (function() {
Composer.extend = Backbone.Model.extend;
_.extend(Composer.prototype, EventBroker);
Composer.prototype.compositions = null;
function Composer() {
this.initialize.apply(this, arguments);
}
Composer.prototype.initialize = function(options) {
if (options == null) {
options = {};
}
this.compositions = {};
mediator.setHandler('composer:compose', this.compose, this);
mediator.setHandler('composer:retrieve', this.retrieve, this);
return this.subscribeEvent('dispatcher:dispatch', this.cleanup);
};
Composer.prototype.compose = function(name, second, third) {
if (typeof second === 'function') {
if (third || second.prototype.dispose) {
if (second.prototype instanceof Composition) {
return this._compose(name, {
composition: second,
options: third
});
} else {
return this._compose(name, {
options: third,
compose: function() {
var autoRender, disabledAutoRender;
if (second.prototype instanceof Backbone.Model || second.prototype instanceof Backbone.Collection) {
this.item = new second(null, this.options);
} else {
this.item = new second(this.options);
}
autoRender = this.item.autoRender;
disabledAutoRender = autoRender === void 0 || !autoRender;
if (disabledAutoRender && typeof this.item.render === 'function') {
return this.item.render();
}
}
});
}
}
return this._compose(name, {
compose: second
});
}
if (typeof third === 'function') {
return this._compose(name, {
compose: third,
options: second
});
}
return this._compose(name, second);
};
Composer.prototype._compose = function(name, options) {
var composition, current, isPromise, returned;
if (typeof options.compose !== 'function' && !(options.composition != null)) {
throw new Error('Composer#compose was used incorrectly');
}
if (options.composition != null) {
composition = new options.composition(options.options);
} else {
composition = new Composition(options.options);
composition.compose = options.compose;
if (options.check) {
composition.check = options.check;
}
}
current = this.compositions[name];
isPromise = false;
if (current && current.check(composition.options)) {
current.stale(false);
} else {
if (current) {
current.dispose();
}
returned = composition.compose(composition.options);
isPromise = typeof (returned != null ? returned.then : void 0) === 'function';
composition.stale(false);
this.compositions[name] = composition;
}
if (isPromise) {
return returned;
} else {
return this.compositions[name].item;
}
};
Composer.prototype.retrieve = function(name) {
var active;
active = this.compositions[name];
if (active && !active.stale()) {
return active.item;
} else {
return void 0;
}
};
Composer.prototype.cleanup = function() {
var composition, name, _ref;
_ref = this.compositions;
for (name in _ref) {
composition = _ref[name];
if (composition.stale()) {
composition.dispose();
delete this.compositions[name];
} else {
composition.stale(true);
}
}
};
Composer.prototype.dispose = function() {
var composition, name, _ref;
if (this.disposed) {
return;
}
this.unsubscribeAllEvents();
mediator.removeHandlers(this);
_ref = this.compositions;
for (name in _ref) {
composition = _ref[name];
composition.dispose();
}
delete this.compositions;
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Composer;
})();
});;loader.register('chaplin/controllers/controller', function(e, r, module) {
'use strict';
var Backbone, Controller, EventBroker, mediator, utils, _,
__slice = [].slice,
__hasProp = {}.hasOwnProperty;
_ = loader('underscore');
Backbone = loader('backbone');
EventBroker = loader('chaplin/lib/event_broker');
utils = loader('chaplin/lib/utils');
mediator = loader('chaplin/mediator');
module.exports = Controller = (function() {
Controller.extend = Backbone.Model.extend;
_.extend(Controller.prototype, Backbone.Events);
_.extend(Controller.prototype, EventBroker);
Controller.prototype.view = null;
Controller.prototype.redirected = false;
function Controller() {
this.initialize.apply(this, arguments);
}
Controller.prototype.initialize = function() {};
Controller.prototype.beforeAction = function() {};
Controller.prototype.adjustTitle = function(subtitle) {
return mediator.execute('adjustTitle', subtitle);
};
Controller.prototype.reuse = function(name) {
var method;
method = arguments.length === 1 ? 'retrieve' : 'compose';
return mediator.execute.apply(mediator, ["composer:" + method].concat(__slice.call(arguments)));
};
Controller.prototype.compose = function() {
throw new Error('Controller#compose was moved to Controller#reuse');
};
Controller.prototype.redirectTo = function(pathDesc, params, options) {
this.redirected = true;
return utils.redirectTo(pathDesc, params, options);
};
Controller.prototype.disposed = false;
Controller.prototype.dispose = function() {
var obj, prop;
if (this.disposed) {
return;
}
for (prop in this) {
if (!__hasProp.call(this, prop)) continue;
obj = this[prop];
if (!(obj && typeof obj.dispose === 'function')) {
continue;
}
obj.dispose();
delete this[prop];
}
this.unsubscribeAllEvents();
this.stopListening();
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Controller;
})();
});;loader.register('chaplin/models/collection', function(e, r, module) {
'use strict';
var Backbone, Collection, EventBroker, Model, utils, _,
__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; };
_ = loader('underscore');
Backbone = loader('backbone');
EventBroker = loader('chaplin/lib/event_broker');
Model = loader('chaplin/models/model');
utils = loader('chaplin/lib/utils');
module.exports = Collection = (function(_super) {
__extends(Collection, _super);
function Collection() {
return Collection.__super__.constructor.apply(this, arguments);
}
_.extend(Collection.prototype, EventBroker);
Collection.prototype.model = Model;
Collection.prototype.serialize = function() {
return this.map(utils.serialize);
};
Collection.prototype.disposed = false;
Collection.prototype.dispose = function() {
var prop, properties, _i, _len;
if (this.disposed) {
return;
}
this.trigger('dispose', this);
this.reset([], {
silent: true
});
this.unsubscribeAllEvents();
this.stopListening();
this.off();
properties = ['model', 'models', '_byId', '_byCid', '_callbacks'];
for (_i = 0, _len = properties.length; _i < _len; _i++) {
prop = properties[_i];
delete this[prop];
}
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Collection;
})(Backbone.Collection);
});;loader.register('chaplin/models/model', function(e, r, module) {
'use strict';
var Backbone, EventBroker, Model, serializeAttributes, serializeModelAttributes, utils, _,
__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; };
_ = loader('underscore');
Backbone = loader('backbone');
utils = loader('chaplin/lib/utils');
EventBroker = loader('chaplin/lib/event_broker');
serializeAttributes = function(model, attributes, modelStack) {
var delegator, key, otherModel, serializedModels, value, _i, _len, _ref;
delegator = utils.beget(attributes);
if (modelStack == null) {
modelStack = {};
}
modelStack[model.cid] = true;
for (key in attributes) {
value = attributes[key];
if (value instanceof Backbone.Model) {
delegator[key] = serializeModelAttributes(value, model, modelStack);
} else if (value instanceof Backbone.Collection) {
serializedModels = [];
_ref = value.models;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
otherModel = _ref[_i];
serializedModels.push(serializeModelAttributes(otherModel, model, modelStack));
}
delegator[key] = serializedModels;
}
}
delete modelStack[model.cid];
return delegator;
};
serializeModelAttributes = function(model, currentModel, modelStack) {
var attributes;
if (model === currentModel || model.cid in modelStack) {
return null;
}
attributes = typeof model.getAttributes === 'function' ? model.getAttributes() : model.attributes;
return serializeAttributes(model, attributes, modelStack);
};
module.exports = Model = (function(_super) {
__extends(Model, _super);
function Model() {
return Model.__super__.constructor.apply(this, arguments);
}
_.extend(Model.prototype, EventBroker);
Model.prototype.getAttributes = function() {
return this.attributes;
};
Model.prototype.serialize = function() {
return serializeAttributes(this, this.getAttributes());
};
Model.prototype.disposed = false;
Model.prototype.dispose = function() {
var prop, properties, _i, _len;
if (this.disposed) {
return;
}
this.trigger('dispose', this);
this.unsubscribeAllEvents();
this.stopListening();
this.off();
properties = ['collection', 'attributes', 'changed', 'defaults', '_escapedAttributes', '_previousAttributes', '_silent', '_pending', '_callbacks'];
for (_i = 0, _len = properties.length; _i < _len; _i++) {
prop = properties[_i];
delete this[prop];
}
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Model;
})(Backbone.Model);
});;loader.register('chaplin/views/layout', function(e, r, module) {
'use strict';
var $, Backbone, EventBroker, Layout, View, mediator, utils, _,
__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; };
_ = loader('underscore');
Backbone = loader('backbone');
mediator = loader('chaplin/mediator');
utils = loader('chaplin/lib/utils');
EventBroker = loader('chaplin/lib/event_broker');
View = loader('chaplin/views/view');
$ = Backbone.$;
module.exports = Layout = (function(_super) {
__extends(Layout, _super);
Layout.prototype.el = 'body';
Layout.prototype.keepElement = true;
Layout.prototype.title = '';
Layout.prototype.globalRegions = null;
Layout.prototype.listen = {
'beforeControllerDispose mediator': 'scroll'
};
function Layout(options) {
if (options == null) {
options = {};
}
this.openLink = __bind(this.openLink, this);
this.globalRegions = [];
this.title = options.title;
if (options.regions) {
this.regions = options.regions;
}
this.settings = _.defaults(options, {
titleTemplate: function(data) {
var st;
st = data.subtitle ? "" + data.subtitle + " \u2013 " : '';
return st + data.title;
},
openExternalToBlank: false,
routeLinks: 'a, .go-to',
skipRouting: '.noscript',
scrollTo: [0, 0]
});
mediator.setHandler('region:show', this.showRegion, this);
mediator.setHandler('region:register', this.registerRegionHandler, this);
mediator.setHandler('region:unregister', this.unregisterRegionHandler, this);
mediator.setHandler('region:find', this.regionByName, this);
mediator.setHandler('adjustTitle', this.adjustTitle, this);
Layout.__super__.constructor.apply(this, arguments);
if (this.settings.routeLinks) {
this.startLinkRouting();
}
}
Layout.prototype.scroll = function() {
var position;
position = this.settings.scrollTo;
if (position) {
return window.scrollTo(position[0], position[1]);
}
};
Layout.prototype.adjustTitle = function(subtitle) {
var title,
_this = this;
if (subtitle == null) {
subtitle = '';
}
title = this.settings.titleTemplate({
title: this.title,
subtitle: subtitle
});
setTimeout(function() {
document.title = title;
return _this.publishEvent('adjustTitle', subtitle, title);
}, 50);
return title;
};
Layout.prototype.startLinkRouting = function() {
var route;
route = this.settings.routeLinks;
if (!route) {
return;
}
if ($) {
return this.$el.on('click', route, this.openLink);
} else {
return this.delegate('click', route, this.openLink);
}
};
Layout.prototype.stopLinkRouting = function() {
var route;
route = this.settings.routeLinks;
if ($) {
if (route) {
return this.$el.off('click', route);
}
} else {
return this.undelegate('click', route, this.openLink);
}
};
Layout.prototype.isExternalLink = function(link) {
var _ref, _ref1;
return link.target === '_blank' || link.rel === 'external' || ((_ref = link.protocol) !== 'http:' && _ref !== 'https:' && _ref !== 'file:') || ((_ref1 = link.hostname) !== location.hostname && _ref1 !== '');
};
Layout.prototype.openLink = function(event) {
var el, external, href, isAnchor, skipRouting, type;
if (utils.modifierKeyPressed(event)) {
return;
}
el = $ ? event.currentTarget : event.delegateTarget;
isAnchor = el.nodeName === 'A';
href = el.getAttribute('href') || el.getAttribute('data-href') || null;
if (!(href != null) || href === '' || href.charAt(0) === '#') {
return;
}
skipRouting = this.settings.skipRouting;
type = typeof skipRouting;
if (type === 'function' && !skipRouting(href, el) || type === 'string' && ($ ? $(el).is(skipRouting) : Backbone.utils.matchesSelector(el, skipRouting))) {
return;
}
external = isAnchor && this.isExternalLink(el);
if (external) {
if (this.settings.openExternalToBlank) {
event.preventDefault();
window.open(href);
}
return;
}
utils.redirectTo({
url: href
});
event.preventDefault();
};
Layout.prototype.registerRegionHandler = function(instance, name, selector) {
if (name != null) {
return this.registerGlobalRegion(instance, name, selector);
} else {
return this.registerGlobalRegions(instance);
}
};
Layout.prototype.registerGlobalRegion = function(instance, name, selector) {
this.unregisterGlobalRegion(instance, name);
return this.globalRegions.unshift({
instance: instance,
name: name,
selector: selector
});
};
Layout.prototype.registerGlobalRegions = function(instance) {
var name, selector, version, _i, _len, _ref;
_ref = utils.getAllPropertyVersions(instance, 'regions');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
version = _ref[_i];
for (name in version) {
selector = version[name];
this.registerGlobalRegion(instance, name, selector);
}
}
};
Layout.prototype.unregisterRegionHandler = function(instance, name) {
if (name != null) {
return this.unregisterGlobalRegion(instance, name);
} else {
return this.unregisterGlobalRegions(instance);
}
};
Layout.prototype.unregisterGlobalRegion = function(instance, name) {
var cid, region;
cid = instance.cid;
return this.globalRegions = (function() {
var _i, _len, _ref, _results;
_ref = this.globalRegions;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
region = _ref[_i];
if (region.instance.cid !== cid || region.name !== name) {
_results.push(region);
}
}
return _results;
}).call(this);
};
Layout.prototype.unregisterGlobalRegions = function(instance) {
var region;
return this.globalRegions = (function() {
var _i, _len, _ref, _results;
_ref = this.globalRegions;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
region = _ref[_i];
if (region.instance.cid !== instance.cid) {
_results.push(region);
}
}
return _results;
}).call(this);
};
Layout.prototype.regionByName = function(name) {
var reg, _i, _len, _ref;
_ref = this.globalRegions;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
reg = _ref[_i];
if (reg.name === name && !reg.instance.stale) {
return reg;
}
}
};
Layout.prototype.showRegion = function(name, instance) {
var region;
region = this.regionByName(name);
if (!region) {
throw new Error("No region registered under " + name);
}
return instance.container = region.selector === '' ? $ ? region.instance.$el : region.instance.el : region.instance.noWrap ? $ ? $(region.instance.container).find(region.selector) : region.instance.container.querySelector(region.selector) : region.instance[$ ? '$' : 'find'](region.selector);
};
Layout.prototype.dispose = function() {
var prop, _i, _len, _ref;
if (this.disposed) {
return;
}
this.stopLinkRouting();
_ref = ['globalRegions', 'title', 'route'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
prop = _ref[_i];
delete this[prop];
}
mediator.removeHandlers(this);
return Layout.__super__.dispose.apply(this, arguments);
};
return Layout;
})(View);
});;loader.register('chaplin/views/view', function(e, r, module) {
'use strict';
var $, Backbone, EventBroker, View, attach, bind, mediator, setHTML, utils, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ = loader('underscore');
Backbone = loader('backbone');
mediator = loader('chaplin/mediator');
EventBroker = loader('chaplin/lib/event_broker');
utils = loader('chaplin/lib/utils');
$ = Backbone.$;
bind = (function() {
if (Function.prototype.bind) {
return function(item, ctx) {
return item.bind(ctx);
};
} else if (_.bind) {
return _.bind;
}
})();
setHTML = (function() {
if ($) {
return function(elem, html) {
return elem.html(html);
};
} else {
return function(elem, html) {
return elem.innerHTML = html;
};
}
})();
attach = (function() {
if ($) {
return function(view) {
var actual;
actual = $(view.container);
if (typeof view.containerMethod === 'function') {
return view.containerMethod(actual, view.el);
} else {
return actual[view.containerMethod](view.el);
}
};
} else {
return function(view) {
var actual;
actual = typeof view.container === 'string' ? document.querySelector(view.container) : view.container;
if (typeof view.containerMethod === 'function') {
return view.containerMethod(actual, view.el);
} else {
return actual[view.containerMethod](view.el);
}
};
}
})();
module.exports = View = (function(_super) {
__extends(View, _super);
_.extend(View.prototype, EventBroker);
View.prototype.autoRender = false;
View.prototype.autoAttach = true;
View.prototype.container = null;
View.prototype.containerMethod = $ ? 'append' : 'appendChild';
View.prototype.regions = null;
View.prototype.region = null;
View.prototype.stale = false;
View.prototype.noWrap = false;
View.prototype.keepElement = false;
View.prototype.subviews = null;
View.prototype.subviewsByName = null;
View.prototype.optionNames = ['autoAttach', 'autoRender', 'container', 'containerMethod', 'region', 'regions', 'noWrap'];
function View(options) {
var optName, optValue, region, render,
_this = this;
if (options) {
for (optName in options) {
optValue = options[optName];
if (__indexOf.call(this.optionNames, optName) >= 0) {
this[optName] = optValue;
}
}
}
render = this.render;
this.render = function() {
if (_this.disposed) {
return false;
}
render.apply(_this, arguments);
if (_this.autoAttach) {
_this.attach.apply(_this, arguments);
}
return _this;
};
this.subviews = [];
this.subviewsByName = {};
if (this.noWrap) {
if (this.region) {
region = mediator.execute('region:find', this.region);
if (region != null) {
this.el = region.instance.container != null ? region.instance.region != null ? $(region.instance.container).find(region.selector) : region.instance.container : region.instance.$(region.selector);
}
}
if (this.container) {
this.el = this.container;
}
}
View.__super__.constructor.apply(this, arguments);
this.delegateListeners();
if (this.model) {
this.listenTo(this.model, 'dispose', this.dispose);
}
if (this.collection) {
this.listenTo(this.collection, 'dispose', function(subject) {
if (!subject || subject === _this.collection) {
return _this.dispose();
}
});
}
if (this.regions != null) {
mediator.execute('region:register', this);
}
if (this.autoRender) {
this.render();
}
}
View.prototype.delegate = function(eventName, second, third) {
var bound, event, events, handler, list, selector;
if (Backbone.utils) {
return Backbone.utils.delegate(this, eventName, second, third);
}
if (typeof eventName !== 'string') {
throw new TypeError('View#delegate: first argument must be a string');
}
if (arguments.length === 2) {
handler = second;
} else if (arguments.length === 3) {
selector = second;
if (typeof selector !== 'string') {
throw new TypeError('View#delegate: ' + 'second argument must be a string');
}
handler = third;
} else {
throw new TypeError('View#delegate: ' + 'only two or three arguments are allowed');
}
if (typeof handler !== 'function') {
throw new TypeError('View#delegate: ' + 'handler argument must be function');
}
list = (function() {
var _i, _len, _ref, _results;
_ref = eventName.split(' ');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_results.push("" + event + ".delegate" + this.cid);
}
return _results;
}).call(this);
events = list.join(' ');
bound = bind(handler, this);
this.$el.on(events, selector || null, bound);
return bound;
};
View.prototype._delegateEvents = function(events) {
var bound, eventName, handler, key, match, selector, value;
if (Backbone.View.prototype.delegateEvents.length === 2) {
return Backbone.View.prototype.delegateEvents.call(this, events, true);
}
for (key in events) {
value = events[key];
handler = typeof value === 'function' ? value : this[value];
if (!handler) {
throw new Error("Method '" + value + "' does not exist");
}
match = key.match(/^(\S+)\s*(.*)$/);
eventName = "" + match[1] + ".delegateEvents" + this.cid;
selector = match[2];
bound = bind(handler, this);
this.$el.on(eventName, selector || null, bound);
}
};
View.prototype.delegateEvents = function(events, keepOld) {
var classEvents, _i, _len, _ref;
if (!keepOld) {
this.undelegateEvents();
}
if (events) {
return this._delegateEvents(events);
}
_ref = utils.getAllPropertyVersions(this, 'events');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
classEvents = _ref[_i];
if (typeof classEvents === 'function') {
classEvents = classEvents.call(this);
}
this._delegateEvents(classEvents);
}
};
View.prototype.undelegate = function(eventName, second, third) {
var event, events, handler, list, selector;
if (Backbone.utils) {
return Backbone.utils.undelegate(this, eventName, second, third);
}
if (eventName) {
if (typeof eventName !== 'string') {
throw new TypeError('View#undelegate: first argument must be a string');
}
if (arguments.length === 2) {
if (typeof second === 'string') {
selector = second;
} else {
handler = second;
}
} else if (arguments.length === 3) {
selector = second;
if (typeof selector !== 'string') {
throw new TypeError('View#undelegate: ' + 'second argument must be a string');
}
handler = third;
}
list = (function() {
var _i, _len, _ref, _results;
_ref = eventName.split(' ');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_results.push("" + event + ".delegate" + this.cid);
}
return _results;
}).call(this);
events = list.join(' ');
return this.$el.off(events, selector || null);
} else {
return this.$el.off(".delegate" + this.cid);
}
};
View.prototype.delegateListeners = function() {
var eventName, key, method, target, version, _i, _len, _ref, _ref1;
if (!this.listen) {
return;
}
_ref = utils.getAllPropertyVersions(this, 'listen');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
version = _ref[_i];
if (typeof version === 'function') {
version = version.call(this);
}
for (key in version) {
method = version[key];
if (typeof method !== 'function') {
method = this[method];
}
if (typeof method !== 'function') {
throw new Error('View#delegateListeners: ' + ("listener for \"" + key + "\" must be function"));
}
_ref1 = key.split(' '), eventName = _ref1[0], target = _ref1[1];
this.delegateListener(eventName, target, method);
}
}
};
View.prototype.delegateListener = function(eventName, target, callback) {
var prop;
if (target === 'model' || target === 'collection') {
prop = this[target];
if (prop) {
this.listenTo(prop, eventName, callback);
}
} else if (target === 'mediator') {
this.subscribeEvent(eventName, callback);
} else if (!target) {
this.on(eventName, callback, this);
}
};
View.prototype.registerRegion = function(name, selector) {
return mediator.execute('region:register', this, name, selector);
};
View.prototype.unregisterRegion = function(name) {
return mediator.execute('region:unregister', this, name);
};
View.prototype.unregisterAllRegions = function() {
return mediator.execute({
name: 'region:unregister',
silent: true
}, this);
};
View.prototype.subview = function(name, view) {
var byName, subviews;
subviews = this.subviews;
byName = this.subviewsByName;
if (name && view) {
this.removeSubview(name);
subviews.push(view);
byName[name] = view;
return view;
} else if (name) {
return byName[name];
}
};
View.prototype.removeSubview = function(nameOrView) {
var byName, index, name, otherName, otherView, subviews, view;
if (!nameOrView) {
return;
}
subviews = this.subviews;
byName = this.subviewsByName;
if (typeof nameOrView === 'string') {
name = nameOrView;
view = byName[name];
} else {
view = nameOrView;
for (otherName in byName) {
otherView = byName[otherName];
if (!(otherView === view)) {
continue;
}
name = otherName;
break;
}
}
if (!(name && view && view.dispose)) {
return;
}
view.dispose();
index = utils.indexOf(subviews, view);
if (index !== -1) {
subviews.splice(index, 1);
}
return delete byName[name];
};
View.prototype.getTemplateData = function() {
var data, source;
data = this.model ? utils.serialize(this.model) : this.collection ? {
items: utils.serialize(this.collection),
length: this.collection.length
} : {};
source = this.model || this.collection;
if (source) {
if (typeof source.isSynced === 'function' && !('synced' in data)) {
data.synced = source.isSynced();
}
}
return data;
};
View.prototype.getTemplateFunction = function() {
throw new Error('View#getTemplateFunction must be overridden');
};
View.prototype.render = function() {
var el, html, templateFunc;
if (this.disposed) {
return false;
}
templateFunc = this.getTemplateFunction();
if (typeof templateFunc === 'function') {
html = templateFunc(this.getTemplateData());
if (this.noWrap) {
el = document.createElement('div');
el.innerHTML = html;
if (el.children.length > 1) {
throw new Error('There must be a single top-level element when ' + 'using `noWrap`.');
}
this.undelegateEvents();
this.setElement(el.firstChild, true);
} else {
setHTML(($ ? this.$el : this.el), html);
}
}
return this;
};
View.prototype.attach = function() {
if (this.region != null) {
mediator.execute('region:show', this.region, this);
}
if (this.container && !document.body.contains(this.el)) {
attach(this);
return this.trigger('addedToDOM');
}
};
View.prototype.disposed = false;
View.prototype.dispose = function() {
var prop, properties, subview, _i, _j, _len, _len1, _ref;
if (this.disposed) {
return;
}
this.unregisterAllRegions();
_ref = this.subviews;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
subview = _ref[_i];
subview.dispose();
}
this.unsubscribeAllEvents();
this.off();
if (this.keepElement) {
this.undelegateEvents();
this.undelegate();
this.stopListening();
} else {
this.remove();
}
properties = ['el', '$el', 'options', 'model', 'collection', 'subviews', 'subviewsByName', '_callbacks'];
for (_j = 0, _len1 = properties.length; _j < _len1; _j++) {
prop = properties[_j];
delete this[prop];
}
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return View;
})(Backbone.View);
});;loader.register('chaplin/views/collection_view', function(e, r, module) {
'use strict';
var $, Backbone, CollectionView, View, addClass, endAnimation, filterChildren, insertView, startAnimation, toggleElement, utils, _,
__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; };
_ = loader('underscore');
Backbone = loader('backbone');
View = loader('chaplin/views/view');
utils = loader('chaplin/lib/utils');
$ = Backbone.$;
filterChildren = function(nodeList, selector) {
var node, _i, _len, _results;
if (!selector) {
return nodeList;
}
_results = [];
for (_i = 0, _len = nodeList.length; _i < _len; _i++) {
node = nodeList[_i];
if (Backbone.utils.matchesSelector(node, selector)) {
_results.push(node);
}
}
return _results;
};
toggleElement = (function() {
if ($) {
return function(elem, visible) {
return elem.toggle(visible);
};
} else {
return function(elem, visible) {
return elem.style.display = (visible ? '' : 'none');
};
}
})();
addClass = (function() {
if ($) {
return function(elem, cls) {
return elem.addClass(cls);
};
} else {
return function(elem, cls) {
return elem.classList.add(cls);
};
}
})();
startAnimation = (function() {
if ($) {
return function(elem, useCssAnimation, cls) {
if (useCssAnimation) {
return addClass(elem, cls);
} else {
return elem.css('opacity', 0);
}
};
} else {
return function(elem, useCssAnimation, cls) {
if (useCssAnimation) {
return addClass(elem, cls);
} else {
return elem.style.opacity = 0;
}
};
}
})();
endAnimation = (function() {
if ($) {
return function(elem, duration) {
return elem.animate({
opacity: 1
}, duration);
};
} else {
return function(elem, duration) {
elem.style.transition = "opacity " + (duration / 1000) + "s";
return elem.opacity = 1;
};
}
})();
insertView = (function() {
if ($) {
return function(list, viewEl, position, length, itemSelector) {
var children, childrenLength, insertInMiddle, isEnd, method;
insertInMiddle = (0 < position && position < length);
isEnd = function(length) {
return length === 0 || position === length;
};
if (insertInMiddle || itemSelector) {
children = list.children(itemSelector);
childrenLength = children.length;
if (children[position] !== viewEl) {
if (isEnd(childrenLength)) {
return list.append(viewEl);
} else {
if (position === 0) {
return children.eq(position).before(viewEl);
} else {
return children.eq(position - 1).after(viewEl);
}
}
}
} else {
method = isEnd(length) ? 'append' : 'prepend';
return list[method](viewEl);
}
};
} else {
return function(list, viewEl, position, length, itemSelector) {
var children, childrenLength, insertInMiddle, isEnd, last;
insertInMiddle = (0 < position && position < length);
isEnd = function(length) {
return length === 0 || position === length;
};
if (insertInMiddle || itemSelector) {
children = filterChildren(list.children, itemSelector);
childrenLength = children.length;
if (children[position] !== viewEl) {
if (isEnd(childrenLength)) {
return list.appendChild(viewEl);
} else if (position === 0) {
return list.insertBefore(viewEl, children[position]);
} else {
last = children[position - 1];
if (list.lastChild === last) {
return list.appendChild(viewEl);
} else {
return list.insertBefore(viewEl, last.nextElementSibling);
}
}
}
} else if (isEnd(length)) {
return list.appendChild(viewEl);
} else {
return list.insertBefore(viewEl, list.firstChild);
}
};
}
})();
module.exports = CollectionView = (function(_super) {
__extends(CollectionView, _super);
CollectionView.prototype.itemView = null;
CollectionView.prototype.autoRender = true;
CollectionView.prototype.renderItems = true;
CollectionView.prototype.animationDuration = 500;
CollectionView.prototype.useCssAnimation = false;
CollectionView.prototype.animationStartClass = 'animated-item-view';
CollectionView.prototype.animationEndClass = 'animated-item-view-end';
CollectionView.prototype.listSelector = null;
CollectionView.prototype.$list = null;
CollectionView.prototype.fallbackSelector = null;
CollectionView.prototype.$fallback = null;
CollectionView.prototype.loadingSelector = null;
CollectionView.prototype.$loading = null;
CollectionView.prototype.itemSelector = null;
CollectionView.prototype.filterer = null;
CollectionView.prototype.filterCallback = function(view, included) {
if ($) {
view.$el.stop(true, true);
}
return toggleElement(($ ? view.$el : view.el), included);
};
CollectionView.prototype.visibleItems = null;
CollectionView.prototype.optionNames = View.prototype.optionNames.concat(['renderItems', 'itemView']);
function CollectionView(options) {
this.renderAllItems = __bind(this.renderAllItems, this);
this.toggleFallback = __bind(this.toggleFallback, this);
this.itemsReset = __bind(this.itemsReset, this);
this.itemRemoved = __bind(this.itemRemoved, this);
this.itemAdded = __bind(this.itemAdded, this);
this.visibleItems = [];
CollectionView.__super__.constructor.apply(this, arguments);
}
CollectionView.prototype.initialize = function(options) {
if (options == null) {
options = {};
}
this.addCollectionListeners();
if (options.filterer != null) {
return this.filter(options.filterer);
}
};
CollectionView.prototype.addCollectionListeners = function() {
this.listenTo(this.collection, 'add', this.itemAdded);
this.listenTo(this.collection, 'remove', this.itemRemoved);
return this.listenTo(this.collection, 'reset sort', this.itemsReset);
};
CollectionView.prototype.getTemplateData = function() {
var templateData;
templateData = {
length: this.collection.length
};
if (typeof this.collection.isSynced === 'function') {
templateData.synced = this.collection.isSynced();
}
return templateData;
};
CollectionView.prototype.getTemplateFunction = function() {};
CollectionView.prototype.render = function() {
var listSelector;
CollectionView.__super__.render.apply(this, arguments);
listSelector = _.result(this, 'listSelector');
if ($) {
this.$list = listSelector ? this.$(listSelector) : this.$el;
} else {
this.list = listSelector ? this.find(this.listSelector) : this.el;
}
this.initFallback();
this.initLoadingIndicator();
if (this.renderItems) {
return this.renderAllItems();
}
};
CollectionView.prototype.itemAdded = function(item, collection, options) {
return this.insertView(item, this.renderItem(item), options.at);
};
CollectionView.prototype.itemRemoved = function(item) {
return this.removeViewForItem(item);
};
CollectionView.prototype.itemsReset = function() {
return this.renderAllItems();
};
CollectionView.prototype.initFallback = function() {
if (!this.fallbackSelector) {
return;
}
if ($) {
this.$fallback = this.$(this.fallbackSelector);
} else {
this.fallback = this.find(this.fallbackSelector);
}
this.on('visibilityChange', this.toggleFallback);
this.listenTo(this.collection, 'syncStateChange', this.toggleFallback);
return this.toggleFallback();
};
CollectionView.prototype.toggleFallback = function() {
var visible;
visible = this.visibleItems.length === 0 && (typeof this.collection.isSynced === 'function' ? this.collection.isSynced() : true);
return toggleElement(($ ? this.$fallback : this.fallback), visible);
};
CollectionView.prototype.initLoadingIndicator = function() {
if (!(this.loadingSelector && typeof this.collection.isSyncing === 'function')) {
return;
}
if ($) {
this.$loading = this.$(this.loadingSelector);
} else {
this.loading = this.find(this.loadingSelector);
}
this.listenTo(this.collection, 'syncStateChange', this.toggleLoadingIndicator);
return this.toggleLoadingIndicator();
};
CollectionView.prototype.toggleLoadingIndicator = function() {
var visible;
visible = this.collection.length === 0 && this.collection.isSyncing();
return toggleElement(($ ? this.$loading : this.loading), visible);
};
CollectionView.prototype.getItemViews = function() {
var itemViews, name, view, _ref;
itemViews = {};
if (this.subviews.length > 0) {
_ref = this.subviewsByName;
for (name in _ref) {
view = _ref[name];
if (name.slice(0, 9) === 'itemView:') {
itemViews[name.slice(9)] = view;
}
}
}
return itemViews;
};
CollectionView.prototype.filter = function(filterer, filterCallback) {
var hasItemViews, included, index, item, view, _i, _len, _ref,
_this = this;
if (typeof filterer === 'function' || filterer === null) {
this.filterer = filterer;
}
if (typeof filterCallback === 'function' || filterCallback === null) {
this.filterCallback = filterCallback;
}
hasItemViews = (function() {
var name;
if (_this.subviews.length > 0) {
for (name in _this.subviewsByName) {
if (name.slice(0, 9) === 'itemView:') {
return true;
}
}
}
return false;
})();
if (hasItemViews) {
_ref = this.collection.models;
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
item = _ref[index];
included = typeof this.filterer === 'function' ? this.filterer(item, index) : true;
view = this.subview("itemView:" + item.cid);
if (!view) {
throw new Error('CollectionView#filter: ' + ("no view found for " + item.cid));
}
this.filterCallback(view, included);
this.updateVisibleItems(view.model, included, false);
}
}
return this.trigger('visibilityChange', this.visibleItems);
};
CollectionView.prototype.renderAllItems = function() {
var cid, index, item, items, remainingViewsByCid, view, _i, _j, _len, _len1, _ref;
items = this.collection.models;
this.visibleItems = [];
remainingViewsByCid = {};
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
view = this.subview("itemView:" + item.cid);
if (view) {
remainingViewsByCid[item.cid] = view;
}
}
_ref = this.getItemViews();
for (cid in _ref) {
if (!__hasProp.call(_ref, cid)) continue;
view = _ref[cid];
if (!(cid in remainingViewsByCid)) {
this.removeSubview("itemView:" + cid);
}
}
for (index = _j = 0, _len1 = items.length; _j < _len1; index = ++_j) {
item = items[index];
view = this.subview("itemView:" + item.cid);
if (view) {
this.insertView(item, view, index, false);
} else {
this.insertView(item, this.renderItem(item), index);
}
}
if (items.length === 0) {
return this.trigger('visibilityChange', this.visibleItems);
}
};
CollectionView.prototype.renderItem = function(item) {
var view;
view = this.subview("itemView:" + item.cid);
if (!view) {
view = this.initItemView(item);
this.subview("itemView:" + item.cid, view);
}
view.render();
return view;
};
CollectionView.prototype.initItemView = function(model) {
if (this.itemView) {
return new this.itemView({
autoRender: false,
model: model
});
} else {
throw new Error('The CollectionView#itemView property ' + 'must be defined or the initItemView() must be overridden.');
}
};
CollectionView.prototype.insertView = function(item, view, position, enableAnimation) {
var elem, included, length, list,
_this = this;
if (enableAnimation == null) {
enableAnimation = true;
}
if (this.animationDuration === 0) {
enableAnimation = false;
}
if (typeof position !== 'number') {
position = this.collection.indexOf(item);
}
included = typeof this.filterer === 'function' ? this.filterer(item, position) : true;
elem = $ ? view.$el : view.el;
if (included && enableAnimation) {
startAnimation(elem, this.useCssAnimation, this.animationStartClass);
}
if (this.filterer) {
this.filterCallback(view, included);
}
length = this.collection.length;
list = $ ? this.$list : this.list;
insertView(list, elem, position, length, this.itemSelector);
view.trigger('addedToParent');
this.updateVisibleItems(item, included);
if (included && enableAnimation) {
if (this.useCssAnimation) {
setTimeout((function() {
return addClass(elem, _this.animationEndClass);
}), 0);
} else {
endAnimation(elem, this.animationDuration);
}
}
return view;
};
CollectionView.prototype.removeViewForItem = function(item) {
this.updateVisibleItems(item, false);
return this.removeSubview("itemView:" + item.cid);
};
CollectionView.prototype.updateVisibleItems = function(item, includedInFilter, triggerEvent) {
var includedInVisibleItems, visibilityChanged, visibleItemsIndex;
if (triggerEvent == null) {
triggerEvent = true;
}
visibilityChanged = false;
visibleItemsIndex = utils.indexOf(this.visibleItems, item);
includedInVisibleItems = visibleItemsIndex !== -1;
if (includedInFilter && !includedInVisibleItems) {
this.visibleItems.push(item);
visibilityChanged = true;
} else if (!includedInFilter && includedInVisibleItems) {
this.visibleItems.splice(visibleItemsIndex, 1);
visibilityChanged = true;
}
if (visibilityChanged && triggerEvent) {
this.trigger('visibilityChange', this.visibleItems);
}
return visibilityChanged;
};
CollectionView.prototype.dispose = function() {
var prop, properties, _i, _len;
if (this.disposed) {
return;
}
properties = ['$list', '$fallback', '$loading', 'visibleItems'];
for (_i = 0, _len = properties.length; _i < _len; _i++) {
prop = properties[_i];
delete this[prop];
}
return CollectionView.__super__.dispose.apply(this, arguments);
};
return CollectionView;
})(View);
});;loader.register('chaplin/lib/route', function(e, r, module) {
'use strict';
var Backbone, Controller, EventBroker, Route, utils, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty;
_ = loader('underscore');
Backbone = loader('backbone');
EventBroker = loader('chaplin/lib/event_broker');
Controller = loader('chaplin/controllers/controller');
utils = loader('chaplin/lib/utils');
module.exports = Route = (function() {
var escapeRegExp, optionalRegExp, paramRegExp, processTrailingSlash;
Route.extend = Backbone.Model.extend;
_.extend(Route.prototype, EventBroker);
escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
optionalRegExp = /\((.*?)\)/g;
paramRegExp = /(?::|\*)(\w+)/g;
processTrailingSlash = function(path, trailing) {
switch (trailing) {
case true:
if (path.slice(-1) !== '/') {
path += '/';
}
break;
case false:
if (path.slice(-1) === '/') {
path = path.slice(0, -1);
}
}
return path;
};
function Route(pattern, controller, action, options) {
var _ref;
this.pattern = pattern;
this.controller = controller;
this.action = action;
this.handler = __bind(this.handler, this);
this.replaceParams = __bind(this.replaceParams, this);
this.parseOptionalPortion = __bind(this.parseOptionalPortion, this);
if (typeof this.pattern !== 'string') {
throw new Error('Route: RegExps are not supported.\
Use strings with :names and `constraints` option of route');
}
this.options = options ? _.extend({}, options) : {};
if (this.options.paramsInQS !== false) {
this.options.paramsInQS = true;
}
if (this.options.name != null) {
this.name = this.options.name;
}
if (this.name && this.name.indexOf('#') !== -1) {
throw new Error('Route: "#" cannot be used in name');
}
if ((_ref = this.name) == null) {
this.name = this.controller + '#' + this.action;
}
this.allParams = [];
this.requiredParams = [];
this.optionalParams = [];
if (this.action in Controller.prototype) {
throw new Error('Route: You should not use existing controller ' + 'properties as action names');
}
this.createRegExp();
if (typeof Object.freeze === "function") {
Object.freeze(this);
}
}
Route.prototype.matches = function(criteria) {
var invalidParamsCount, name, propertiesCount, property, _i, _len, _ref;
if (typeof criteria === 'string') {
return criteria === this.name;
} else {
propertiesCount = 0;
_ref = ['name', 'action', 'controller'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
propertiesCount++;
property = criteria[name];
if (property && property !== this[name]) {
return false;
}
}
invalidParamsCount = propertiesCount === 1 && (name === 'action' || name === 'controller');
return !invalidParamsCount;
}
};
Route.prototype.reverse = function(params, query) {
var name, raw, remainingParams, url, value, _i, _j, _len, _len1, _ref, _ref1;
params = this.normalizeParams(params);
remainingParams = _.extend({}, params);
if (params === false) {
return false;
}
url = this.pattern;
_ref = this.requiredParams;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
value = params[name];
url = url.replace(RegExp("[:*]" + name, "g"), value);
delete remainingParams[name];
}
_ref1 = this.optionalParams;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
name = _ref1[_j];
if (value = params[name]) {
url = url.replace(RegExp("[:*]" + name, "g"), value);
delete remainingParams[name];
}
}
raw = url.replace(optionalRegExp, function(match, portion) {
if (portion.match(/[:*]/g)) {
return "";
} else {
return portion;
}
});
url = processTrailingSlash(raw, this.options.trailing);
if (typeof query !== 'object') {
query = utils.queryParams.parse(query);
}
if (this.options.paramsInQS !== false) {
_.extend(query, remainingParams);
}
if (!_.isEmpty(query)) {
url += '?' + utils.queryParams.stringify(query);
}
return url;
};
Route.prototype.normalizeParams = function(params) {
var paramIndex, paramName, paramsHash, _i, _len, _ref;
if (utils.isArray(params)) {
if (params.length < this.requiredParams.length) {
return false;
}
paramsHash = {};
_ref = this.requiredParams;
for (paramIndex = _i = 0, _len = _ref.length; _i < _len; paramIndex = ++_i) {
paramName = _ref[paramIndex];
paramsHash[paramName] = params[paramIndex];
}
if (!this.testConstraints(paramsHash)) {
return false;
}
params = paramsHash;
} else {
if (params == null) {
params = {};
}
if (!this.testParams(params)) {
return false;
}
}
return params;
};
Route.prototype.testConstraints = function(params) {
var constraint, constraints, name;
constraints = this.options.constraints;
if (constraints) {
for (name in constraints) {
if (!__hasProp.call(constraints, name)) continue;
constraint = constraints[name];
if (!constraint.test(params[name])) {
return false;
}
}
}
return true;
};
Route.prototype.testParams = function(params) {
var paramName, _i, _len, _ref;
_ref = this.requiredParams;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
paramName = _ref[_i];
if (params[paramName] === void 0) {
return false;
}
}
return this.testConstraints(params);
};
Route.prototype.createRegExp = function() {
var pattern,
_this = this;
pattern = this.pattern;
pattern = pattern.replace(escapeRegExp, '\\$&');
this.replaceParams(pattern, function(match, param) {
return _this.allParams.push(param);
});
pattern = pattern.replace(optionalRegExp, this.parseOptionalPortion);
pattern = this.replaceParams(pattern, function(match, param) {
_this.requiredParams.push(param);
return _this.paramCapturePattern(match);
});
return this.regExp = RegExp("^" + pattern + "(?=\\/*(?=\\?|$))");
};
Route.prototype.parseOptionalPortion = function(match, optionalPortion) {
var portion,
_this = this;
portion = this.replaceParams(optionalPortion, function(match, param) {
_this.optionalParams.push(param);
return _this.paramCapturePattern(match);
});
return "(?:" + portion + ")?";
};
Route.prototype.replaceParams = function(s, callback) {
return s.replace(paramRegExp, callback);
};
Route.prototype.paramCapturePattern = function(param) {
if (param.charAt(0) === ':') {
return '([^\/\?]+)';
} else {
return '(.*?)';
}
};
Route.prototype.test = function(path) {
var constraints, matched;
matched = this.regExp.test(path);
if (!matched) {
return false;
}
constraints = this.options.constraints;
if (constraints) {
return this.testConstraints(this.extractParams(path));
}
return true;
};
Route.prototype.handler = function(pathParams, options) {
var actionParams, params, path, query, route, _ref;
options = options ? _.extend({}, options) : {};
if (typeof pathParams === 'object') {
query = utils.queryParams.stringify(options.query);
params = pathParams;
path = this.reverse(params);
} else {
_ref = pathParams.split('?'), path = _ref[0], query = _ref[1];
if (!(query != null)) {
query = '';
} else {
options.query = utils.queryParams.parse(query);
}
params = this.extractParams(path);
path = processTrailingSlash(path, this.options.trailing);
}
actionParams = _.extend({}, params, this.options.params);
route = {
path: path,
action: this.action,
controller: this.controller,
name: this.name,
query: query
};
return this.publishEvent('router:match', route, actionParams, options);
};
Route.prototype.extractParams = function(path) {
var index, match, matches, paramName, params, _i, _len, _ref;
params = {};
matches = this.regExp.exec(path);
_ref = matches.slice(1);
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
match = _ref[index];
paramName = this.allParams.length ? this.allParams[index] : index;
params[paramName] = match;
}
return params;
};
return Route;
})();
});;loader.register('chaplin/lib/router', function(e, r, module) {
'use strict';
var Backbone, EventBroker, History, Route, Router, mediator, utils, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
_ = loader('underscore');
Backbone = loader('backbone');
mediator = loader('chaplin/mediator');
EventBroker = loader('chaplin/lib/event_broker');
History = loader('chaplin/lib/history');
Route = loader('chaplin/lib/route');
utils = loader('chaplin/lib/utils');
module.exports = Router = (function() {
Router.extend = Backbone.Model.extend;
_.extend(Router.prototype, EventBroker);
function Router(options) {
var isWebFile;
this.options = options != null ? options : {};
this.match = __bind(this.match, this);
isWebFile = window.location.protocol !== 'file:';
_.defaults(this.options, {
pushState: isWebFile,
root: '/',
trailing: false
});
this.removeRoot = new RegExp('^' + utils.escapeRegExp(this.options.root) + '(#)?');
this.subscribeEvent('!router:route', this.oldEventError);
this.subscribeEvent('!router:routeByName', this.oldEventError);
this.subscribeEvent('!router:changeURL', this.oldURLEventError);
this.subscribeEvent('dispatcher:dispatch', this.changeURL);
mediator.setHandler('router:route', this.route, this);
mediator.setHandler('router:reverse', this.reverse, this);
this.createHistory();
}
Router.prototype.oldEventError = function() {
throw new Error('!router:route and !router:routeByName events were removed.\
Use `Chaplin.utils.redirectTo`');
};
Router.prototype.oldURLEventError = function() {
throw new Error('!router:changeURL event was removed.');
};
Router.prototype.createHistory = function() {
return Backbone.history = new History();
};
Router.prototype.startHistory = function() {
return Backbone.history.start(this.options);
};
Router.prototype.stopHistory = function() {
if (Backbone.History.started) {
return Backbone.history.stop();
}
};
Router.prototype.findHandler = function(predicate) {
var handler, _i, _len, _ref;
_ref = Backbone.history.handlers;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
handler = _ref[_i];
if (predicate(handler)) {
return handler;
}
}
};
Router.prototype.match = function(pattern, target, options) {
var action, controller, route, _ref;
if (options == null) {
options = {};
}
if (arguments.length === 2 && typeof target === 'object') {
options = target;
controller = options.controller, action = options.action;
if (!(controller && action)) {
throw new Error('Router#match must receive either target or ' + 'options.controller & options.action');
}
} else {
controller = options.controller, action = options.action;
if (controller || action) {
throw new Error('Router#match cannot use both target and ' + 'options.controller / options.action');
}
_ref = target.split('#'), controller = _ref[0], action = _ref[1];
}
_.defaults(options, {
trailing: this.options.trailing
});
route = new Route(pattern, controller, action, options);
Backbone.history.handlers.push({
route: route,
callback: route.handler
});
return route;
};
Router.prototype.route = function(pathDesc, params, options) {
var handler, path, pathParams;
if (typeof pathDesc === 'object') {
path = pathDesc.url;
if (!params && pathDesc.params) {
params = pathDesc.params;
}
}
params = params ? utils.isArray(params) ? params.slice() : _.extend({}, params) : {};
if (path != null) {
path = path.replace(this.removeRoot, '');
handler = this.findHandler(function(handler) {
return handler.route.test(path);
});
options = params;
params = null;
} else {
options = options ? _.extend({}, options) : {};
handler = this.findHandler(function(handler) {
if (handler.route.matches(pathDesc)) {
params = handler.route.normalizeParams(params);
if (params) {
return true;
}
}
return false;
});
}
if (handler) {
_.defaults(options, {
changeURL: true
});
pathParams = path != null ? path : params;
handler.callback(pathParams, options);
return true;
} else {
throw new Error('Router#route: request was not routed');
}
};
Router.prototype.reverse = function(criteria, params, query) {
var handler, handlers, reversed, root, url, _i, _len;
root = this.options.root;
if ((params != null) && typeof params !== 'object') {
throw new TypeError('Router#reverse: params must be an array or an ' + 'object');
}
handlers = Backbone.history.handlers;
for (_i = 0, _len = handlers.length; _i < _len; _i++) {
handler = handlers[_i];
if (!(handler.route.matches(criteria))) {
continue;
}
reversed = handler.route.reverse(params, query);
if (reversed !== false) {
url = root ? root + reversed : reversed;
return url;
}
}
throw new Error("Router#reverse: invalid route criteria specified: " + (JSON.stringify(criteria)));
};
Router.prototype.changeURL = function(controller, params, route, options) {
var navigateOptions, url;
if (!((route.path != null) && options.changeURL)) {
return;
}
url = route.path + (route.query ? "?" + route.query : "");
navigateOptions = {
trigger: options.trigger === true,
replace: options.replace === true
};
return Backbone.history.navigate(url, navigateOptions);
};
Router.prototype.disposed = false;
Router.prototype.dispose = function() {
if (this.disposed) {
return;
}
this.stopHistory();
delete Backbone.history;
this.unsubscribeAllEvents();
mediator.removeHandlers(this);
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Router;
})();
});;loader.register('chaplin/lib/history', function(e, r, module) {
'use strict';
var Backbone, History, isExplorer, rootStripper, routeStripper, trailingSlash, _,
__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; };
_ = loader('underscore');
Backbone = loader('backbone');
routeStripper = /^[#\/]|\s+$/g;
rootStripper = /^\/+|\/+$/g;
isExplorer = /msie [\w.]+/;
trailingSlash = /\/$/;
History = (function(_super) {
__extends(History, _super);
function History() {
return History.__super__.constructor.apply(this, arguments);
}
History.prototype.getFragment = function(fragment, forcePushState) {
var root;
if (!(fragment != null)) {
if (this._hasPushState || !this._wantsHashChange || forcePushState) {
fragment = this.location.pathname + this.location.search;
root = this.root.replace(trailingSlash, '');
if (!fragment.indexOf(root)) {
fragment = fragment.substr(root.length);
}
} else {
fragment = this.getHash();
}
}
return fragment.replace(routeStripper, '');
};
History.prototype.start = function(options) {
var atRoot, fragment, loc, _ref, _ref1;
if (Backbone.History.started) {
throw new Error('Backbone.history has already been started');
}
Backbone.History.started = true;
this.options = _.extend({}, {
root: '/'
}, this.options, options);
this.root = this.options.root;
this._wantsHashChange = this.options.hashChange !== false;
this._wantsPushState = Boolean(this.options.pushState);
this._hasPushState = Boolean(this.options.pushState && this.history && this.history.pushState);
fragment = this.getFragment();
routeStripper = (_ref = this.options.routeStripper) != null ? _ref : routeStripper;
rootStripper = (_ref1 = this.options.rootStripper) != null ? _ref1 : rootStripper;
this.root = ('/' + this.root + '/').replace(rootStripper, '/');
if (this._hasPushState) {
Backbone.$(window).on('popstate', this.checkUrl);
} else if (this._wantsHashChange && 'onhashchange' in window) {
Backbone.$(window).on('hashchange', this.checkUrl);
} else if (this._wantsHashChange) {
this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
}
this.fragment = fragment;
loc = this.location;
atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root;
if (this._wantsHashChange && this._wantsPushState && !this._hasPushState && !atRoot) {
this.fragment = this.getFragment(null, true);
this.location.replace(this.root + '#' + this.fragment);
return true;
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
this.fragment = this.getHash().replace(routeStripper, '');
this.history.replaceState({}, document.title, this.root + this.fragment);
}
if (!this.options.silent) {
return this.loadUrl();
}
};
History.prototype.navigate = function(fragment, options) {
var historyMethod, isSameFragment, url;
if (fragment == null) {
fragment = '';
}
if (!Backbone.History.started) {
return false;
}
if (!options || options === true) {
options = {
trigger: options
};
}
fragment = this.getFragment(fragment);
url = this.root + fragment;
if (this.fragment === fragment) {
return false;
}
this.fragment = fragment;
if (fragment.length === 0 && url !== '/' && (url !== this.root || this.options.trailing !== true)) {
url = url.slice(0, -1);
}
if (this._hasPushState) {
historyMethod = options.replace ? 'replaceState' : 'pushState';
this.history[historyMethod]({}, document.title, url);
} else if (this._wantsHashChange) {
this._updateHash(this.location, fragment, options.replace);
isSameFragment = fragment !== this.getFragment(this.getHash(this.iframe));
if ((this.iframe != null) && isSameFragment) {
if (!options.replace) {
this.iframe.document.open().close();
}
this._updateHash(this.iframe.location, fragment, options.replace);
}
} else {
return this.location.assign(url);
}
if (options.trigger) {
return this.loadUrl(fragment);
}
};
return History;
})(Backbone.History);
module.exports = Backbone.$ ? History : Backbone.History;
});;loader.register('chaplin/lib/event_broker', function(e, r, module) {
'use strict';
var EventBroker, mediator,
__slice = [].slice;
mediator = loader('chaplin/mediator');
EventBroker = {
subscribeEvent: function(type, handler) {
if (typeof type !== 'string') {
throw new TypeError('EventBroker#subscribeEvent: ' + 'type argument must be a string');
}
if (typeof handler !== 'function') {
throw new TypeError('EventBroker#subscribeEvent: ' + 'handler argument must be a function');
}
mediator.unsubscribe(type, handler, this);
return mediator.subscribe(type, handler, this);
},
subscribeEventOnce: function(type, handler) {
if (typeof type !== 'string') {
throw new TypeError('EventBroker#subscribeEventOnce: ' + 'type argument must be a string');
}
if (typeof handler !== 'function') {
throw new TypeError('EventBroker#subscribeEventOnce: ' + 'handler argument must be a function');
}
mediator.unsubscribe(type, handler, this);
return mediator.subscribeOnce(type, handler, this);
},
unsubscribeEvent: function(type, handler) {
if (typeof type !== 'string') {
throw new TypeError('EventBroker#unsubscribeEvent: ' + 'type argument must be a string');
}
if (typeof handler !== 'function') {
throw new TypeError('EventBroker#unsubscribeEvent: ' + 'handler argument must be a function');
}
return mediator.unsubscribe(type, handler);
},
unsubscribeAllEvents: function() {
return mediator.unsubscribe(null, null, this);
},
publishEvent: function() {
var args, type;
type = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (typeof type !== 'string') {
throw new TypeError('EventBroker#publishEvent: ' + 'type argument must be a string');
}
return mediator.publish.apply(mediator, [type].concat(__slice.call(args)));
}
};
if (typeof Object.freeze === "function") {
Object.freeze(EventBroker);
}
module.exports = EventBroker;
});;loader.register('chaplin/lib/support', function(e, r, module) {
'use strict';
var support;
support = {
propertyDescriptors: (function() {
var o;
if (!(typeof Object.defineProperty === 'function' && typeof Object.defineProperties === 'function')) {
return false;
}
try {
o = {};
Object.defineProperty(o, 'foo', {
value: 'bar'
});
return o.foo === 'bar';
} catch (error) {
return false;
}
})()
};
module.exports = support;
});;loader.register('chaplin/lib/composition', function(e, r, module) {
'use strict';
var Backbone, Composition, EventBroker, has, _,
__hasProp = {}.hasOwnProperty;
_ = loader('underscore');
Backbone = loader('backbone');
EventBroker = loader('chaplin/lib/event_broker');
has = Object.prototype.hasOwnProperty;
module.exports = Composition = (function() {
Composition.extend = Backbone.Model.extend;
_.extend(Composition.prototype, Backbone.Events);
_.extend(Composition.prototype, EventBroker);
Composition.prototype.item = null;
Composition.prototype.options = null;
Composition.prototype._stale = false;
function Composition(options) {
if (options != null) {
this.options = _.extend({}, options);
}
this.item = this;
this.initialize(this.options);
}
Composition.prototype.initialize = function() {};
Composition.prototype.compose = function() {};
Composition.prototype.check = function(options) {
return _.isEqual(this.options, options);
};
Composition.prototype.stale = function(value) {
var item, name;
if (value == null) {
return this._stale;
}
this._stale = value;
for (name in this) {
item = this[name];
if (item && item !== this && typeof item === 'object' && has.call(item, 'stale')) {
item.stale = value;
}
}
};
Composition.prototype.disposed = false;
Composition.prototype.dispose = function() {
var obj, prop, properties, _i, _len;
if (this.disposed) {
return;
}
for (prop in this) {
if (!__hasProp.call(this, prop)) continue;
obj = this[prop];
if (obj && typeof obj.dispose === 'function') {
if (obj !== this) {
obj.dispose();
delete this[prop];
}
}
}
this.unsubscribeAllEvents();
this.stopListening();
properties = ['redirected'];
for (_i = 0, _len = properties.length; _i < _len; _i++) {
prop = properties[_i];
delete this[prop];
}
this.disposed = true;
return typeof Object.freeze === "function" ? Object.freeze(this) : void 0;
};
return Composition;
})();
});;loader.register('chaplin/lib/sync_machine', function(e, r, module) {
'use strict';
var STATE_CHANGE, SYNCED, SYNCING, SyncMachine, UNSYNCED, event, _fn, _i, _len, _ref;
UNSYNCED = 'unsynced';
SYNCING = 'syncing';
SYNCED = 'synced';
STATE_CHANGE = 'syncStateChange';
SyncMachine = {
_syncState: UNSYNCED,
_previousSyncState: null,
syncState: function() {
return this._syncState;
},
isUnsynced: function() {
return this._syncState === UNSYNCED;
},
isSynced: function() {
return this._syncState === SYNCED;
},
isSyncing: function() {
return this._syncState === SYNCING;
},
unsync: function() {
var _ref;
if ((_ref = this._syncState) === SYNCING || _ref === SYNCED) {
this._previousSync = this._syncState;
this._syncState = UNSYNCED;
this.trigger(this._syncState, this, this._syncState);
this.trigger(STATE_CHANGE, this, this._syncState);
}
},
beginSync: function() {
var _ref;
if ((_ref = this._syncState) === UNSYNCED || _ref === SYNCED) {
this._previousSync = this._syncState;
this._syncState = SYNCING;
this.trigger(this._syncState, this, this._syncState);
this.trigger(STATE_CHANGE, this, this._syncState);
}
},
finishSync: function() {
if (this._syncState === SYNCING) {
this._previousSync = this._syncState;
this._syncState = SYNCED;
this.trigger(this._syncState, this, this._syncState);
this.trigger(STATE_CHANGE, this, this._syncState);
}
},
abortSync: function() {
if (this._syncState === SYNCING) {
this._syncState = this._previousSync;
this._previousSync = this._syncState;
this.trigger(this._syncState, this, this._syncState);
this.trigger(STATE_CHANGE, this, this._syncState);
}
}
};
_ref = [UNSYNCED, SYNCING, SYNCED, STATE_CHANGE];
_fn = function(event) {
return SyncMachine[event] = function(callback, context) {
if (context == null) {
context = this;
}
this.on(event, callback, context);
if (this._syncState === event) {
return callback.call(context);
}
};
};
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_fn(event);
}
if (typeof Object.freeze === "function") {
Object.freeze(SyncMachine);
}
module.exports = SyncMachine;
});;loader.register('chaplin/lib/utils', function(e, r, module) {
'use strict';
var support, utils, _,
__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; },
__hasProp = {}.hasOwnProperty;
_ = loader('underscore');
support = loader('chaplin/lib/support');
utils = {
beget: (function() {
var ctor;
if (typeof Object.create === 'function') {
return Object.create;
} else {
ctor = function() {};
return function(obj) {
ctor.prototype = obj;
return new ctor;
};
}
})(),
indexOf: (function() {
if (Array.prototype.indexOf) {
return function(list, index) {
return list.indexOf(index);
};
} else if (_.indexOf) {
return _.indexOf;
}
})(),
isArray: Array.isArray || _.isArray,
serialize: function(data) {
if (typeof data.serialize === 'function') {
return data.serialize();
} else if (typeof data.toJSON === 'function') {
return data.toJSON();
} else {
throw new TypeError('utils.serialize: Unknown data was passed');
}
},
readonly: (function() {
var readonlyDescriptor;
if (support.propertyDescriptors) {
readonlyDescriptor = {
writable: false,
enumerable: true,
configurable: false
};
return function() {
var obj, prop, properties, _i, _len;
obj = arguments[0], properties = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
for (_i = 0, _len = properties.length; _i < _len; _i++) {
prop = properties[_i];
readonlyDescriptor.value = obj[prop];
Object.defineProperty(obj, prop, readonlyDescriptor);
}
return true;
};
} else {
return function() {
return false;
};
}
})(),
getPrototypeChain: function(object) {
var chain, _ref, _ref1, _ref2, _ref3;
chain = [object.constructor.prototype];
while (object = (_ref = (_ref1 = object.constructor) != null ? (_ref2 = _ref1.superclass) != null ? _ref2.prototype : void 0 : void 0) != null ? _ref : (_ref3 = object.constructor) != null ? _ref3.__super__ : void 0) {
chain.push(object);
}
return chain.reverse();
},
getAllPropertyVersions: function(object, property) {
var proto, result, value, _i, _len, _ref;
result = [];
_ref = utils.getPrototypeChain(object);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
proto = _ref[_i];
value = proto[property];
if (value && __indexOf.call(result, value) < 0) {
result.push(value);
}
}
return result;
},
upcase: function(str) {
return str.charAt(0).toUpperCase() + str.substring(1);
},
escapeRegExp: function(str) {
return String(str || '').replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
},
modifierKeyPressed: function(event) {
return event.shiftKey || event.altKey || event.ctrlKey || event.metaKey;
},
reverse: function(criteria, params, query) {
return loader('chaplin/mediator').execute('router:reverse', criteria, params, query);
},
redirectTo: function(pathDesc, params, options) {
return loader('chaplin/mediator').execute('router:route', pathDesc, params, options);
},
querystring: {
stringify: function(queryParams) {
var arrParam, encodedKey, key, query, stringifyKeyValuePair, value, _i, _len;
query = '';
stringifyKeyValuePair = function(encodedKey, value) {
if (value != null) {
return '&' + encodedKey + '=' + encodeURIComponent(value);
} else {
return '';
}
};
for (key in queryParams) {
if (!__hasProp.call(queryParams, key)) continue;
value = queryParams[key];
encodedKey = encodeURIComponent(key);
if (utils.isArray(value)) {
for (_i = 0, _len = value.length; _i < _len; _i++) {
arrParam = value[_i];
query += stringifyKeyValuePair(encodedKey, arrParam);
}
} else {
query += stringifyKeyValuePair(encodedKey, value);
}
}
return query && query.substring(1);
},
parse: function(queryString) {
var current, field, pair, pairs, params, value, _i, _len, _ref;
params = {};
if (!queryString) {
return params;
}
queryString = queryString.slice(queryString.indexOf('?') + 1);
pairs = queryString.split('&');
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
pair = pairs[_i];
if (!pair.length) {
continue;
}
_ref = pair.split('='), field = _ref[0], value = _ref[1];
if (!field.length) {
continue;
}
field = decodeURIComponent(field);
value = decodeURIComponent(value);
current = params[field];
if (current) {
if (current.push) {
current.push(value);
} else {
params[field] = [current, value];
}
} else {
params[field] = value;
}
}
return params;
}
}
};
utils.queryParams = utils.querystring;
if (typeof Object.seal === "function") {
Object.seal(utils);
}
module.exports = utils;
});;loader.register('chaplin', function(e, r, module) {
module.exports = {
Application: loader('chaplin/application'),
mediator: loader('chaplin/mediator'),
Dispatcher: loader('chaplin/dispatcher'),
Controller: loader('chaplin/controllers/controller'),
Composer: loader('chaplin/composer'),
Composition: loader('chaplin/lib/composition'),
Collection: loader('chaplin/models/collection'),
Model: loader('chaplin/models/model'),
Layout: loader('chaplin/views/layout'),
View: loader('chaplin/views/view'),
CollectionView: loader('chaplin/views/collection_view'),
Route: loader('chaplin/lib/route'),
Router: loader('chaplin/lib/router'),
EventBroker: loader('chaplin/lib/event_broker'),
support: loader('chaplin/lib/support'),
SyncMachine: loader('chaplin/lib/sync_machine'),
utils: loader('chaplin/lib/utils')
};
});
var regDeps = function(Backbone, _) {
loader.register('backbone', function(exports, require, module) {
module.exports = Backbone;
});
loader.register('underscore', function(exports, require, module) {
module.exports = _;
});
};
if (typeof define === 'function' && define.amd) {
define(['backbone', 'underscore'], function(Backbone, _) {
regDeps(Backbone, _);
return loader('chaplin');
});
} else if (typeof module === 'object' && module && module.exports) {
regDeps(require('backbone'), require('underscore'));
module.exports = loader('chaplin');
} else if (typeof require === 'function') {
regDeps(window.Backbone, window._ || window.Backbone.utils);
window.Chaplin = loader('chaplin');
} else {
throw new Error('Chaplin requires Common.js or AMD modules');
}
})();
\ No newline at end of file
/*!
* Exoskeleton.js 0.6.3
* (c) 2013 Paul Miller <http://paulmillr.com>
* Based on Backbone.js
* (c) 2010-2013 Jeremy Ashkenas, DocumentCloud
* Exoskeleton may be freely distributed under the MIT license.
* For all details and documentation: <http://exosjs.com>
*/
(function(root, factory) {
// Set up Backbone appropriately for the environment.
if (typeof define === 'function' && define.amd) {
define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
root.Backbone = root.Exoskeleton = factory(root, exports, _, $);
});
} else if (typeof exports !== 'undefined') {
var _, $;
try { _ = require('underscore'); } catch(e) { }
try { $ = require('jquery'); } catch(e) { }
factory(root, exports, _, $);
} else {
root.Backbone = root.Exoskeleton = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
}
})(this, function(root, Backbone, _, $) {
'use strict';
// Initial Setup
// -------------
// Save the previous value of the `Backbone` variable, so that it can be
// restored later on, if `noConflict` is used.
var previousBackbone = root.Backbone;
var previousExoskeleton = root.Exoskeleton;
// Underscore replacement.
var utils = Backbone.utils = _ = (_ || {});
// Hold onto a local reference to `$`. Can be changed at any point.
Backbone.$ = $;
// Create local references to array methods we'll want to use later.
var array = [];
var push = array.push;
var slice = array.slice;
var toString = ({}).toString;
// Current version of the library. Keep in sync with `package.json`.
// Backbone.VERSION = '1.0.0';
// Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
// to its previous owner. Returns a reference to this Backbone object.
Backbone.noConflict = function() {
root.Backbone = previousBackbone;
root.Exoskeleton = previousExoskeleton;
return this;
};
// Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option
// will fake `"PATCH"`, `"PUT"` and `"DELETE"` requests via the `_method` parameter and
// set a `X-Http-Method-Override` header.
Backbone.emulateHTTP = false;
// Turn on `emulateJSON` to support legacy servers that can't deal with direct
// `application/json` requests ... will encode the body as
// `application/x-www-form-urlencoded` instead and will send the model in a
// form param named `model`.
Backbone.emulateJSON = false;
// Helpers
// -------
// Helper function to correctly set up the prototype chain, for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and
// class properties to be extended.
Backbone.extend = function(protoProps, staticProps) {
var parent = this;
var child;
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent's constructor.
if (protoProps && hasOwnProperty.call(protoProps, 'constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
}
// Add static properties to the constructor function, if supplied.
_.extend(child, parent, staticProps);
// Set the prototype chain to inherit from `parent`, without calling
// `parent`'s constructor function.
var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
// Add prototype properties (instance properties) to the subclass,
// if supplied.
if (protoProps) _.extend(child.prototype, protoProps);
// Set a convenience property in case the parent's prototype is needed
// later.
child.__super__ = parent.prototype;
return child;
};
// Throw an error when a URL is needed, and none is supplied.
var urlError = function() {
throw new Error('A "url" property or function must be specified');
};
// Wrap an optional error callback with a fallback error event.
var wrapError = function(model, options) {
var error = options.error;
options.error = function(resp) {
if (error) error(model, resp, options);
model.trigger('error', model, resp, options);
};
};
// Checker for utility methods. Useful for custom builds.
var utilExists = function(method) {
return typeof _[method] === 'function';
};
utils.result = function result(object, property) {
var value = object ? object[property] : undefined;
return typeof value === 'function' ? object[property]() : value;
};
utils.defaults = function defaults(obj) {
slice.call(arguments, 1).forEach(function(item) {
for (var key in item) if (obj[key] === undefined)
obj[key] = item[key];
});
return obj;
};
utils.extend = function extend(obj) {
slice.call(arguments, 1).forEach(function(item) {
for (var key in item) obj[key] = item[key];
});
return obj;
};
var htmlEscapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
};
utils.escape = function escape(string) {
return string == null ? '' : String(string).replace(/[&<>"']/g, function(match) {
return htmlEscapes[match];
});
};
utils.sortBy = function(obj, value, context) {
var iterator = typeof value === 'function' ? value : function(obj){ return obj[value]; };
return obj
.map(function(value, index, list) {
return {
value: value,
index: index,
criteria: iterator.call(context, value, index, list)
};
})
.sort(function(left, right) {
var a = left.criteria;
var b = right.criteria;
if (a !== b) {
if (a > b || a === void 0) return 1;
if (a < b || b === void 0) return -1;
}
return left.index - right.index;
})
.map(function(item) {
return item.value;
});
};
/** Used to generate unique IDs */
var idCounter = 0;
utils.uniqueId = function uniqueId(prefix) {
var id = ++idCounter + '';
return prefix ? prefix + id : id;
};
var eq = function(a, b, aStack, bStack) {
// Identical objects are equal. `0 === -0`, but they aren't identical.
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
if (a === b) return a !== 0 || 1 / a == 1 / b;
// A strict comparison is necessary because `null == undefined`.
if (a == null || b == null) return a === b;
// Unwrap any wrapped objects.
//if (a instanceof _) a = a._wrapped;
//if (b instanceof _) b = b._wrapped;
// Compare `[[Class]]` names.
var className = toString.call(a);
if (className != toString.call(b)) return false;
switch (className) {
// Strings, numbers, dates, and booleans are compared by value.
case '[object String]':
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
// equivalent to `new String("5")`.
return a == String(b);
case '[object Number]':
// `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
// other numeric values.
return a !== +a ? b !== +b : (a === 0 ? 1 / a === 1 / b : a === +b);
case '[object Date]':
case '[object Boolean]':
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
// millisecond representations. Note that invalid dates with millisecond representations
// of `NaN` are not equivalent.
return +a == +b;
// RegExps are compared by their source patterns and flags.
case '[object RegExp]':
return a.source == b.source &&
a.global == b.global &&
a.multiline == b.multiline &&
a.ignoreCase == b.ignoreCase;
}
if (typeof a != 'object' || typeof b != 'object') return false;
// Assume equality for cyclic structures. The algorithm for detecting cyclic
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
var length = aStack.length;
while (length--) {
// Linear search. Performance is inversely proportional to the number of
// unique nested structures.
if (aStack[length] == a) return bStack[length] == b;
}
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(typeof aCtor === 'function' && (aCtor instanceof aCtor) &&
typeof bCtor === 'function' && (bCtor instanceof bCtor))) {
return false;
}
// Add the first object to the stack of traversed objects.
aStack.push(a);
bStack.push(b);
var size = 0, result = true;
// Recursively compare objects and arrays.
if (className === '[object Array]') {
// Compare array lengths to determine if a deep comparison is necessary.
size = a.length;
result = size === b.length;
if (result) {
// Deep compare the contents, ignoring non-numeric properties.
while (size--) {
if (!(result = eq(a[size], b[size], aStack, bStack))) break;
}
}
} else {
// Deep compare objects.
for (var key in a) {
if (hasOwnProperty.call(a, key)) {
// Count the expected number of properties.
size++;
// Deep compare each member.
if (!(result = hasOwnProperty.call(b, key) && eq(a[key], b[key], aStack, bStack))) break;
}
}
// Ensure that both objects contain the same number of properties.
if (result) {
for (key in b) {
if (hasOwnProperty.call(b, key) && !(size--)) break;
}
result = !size;
}
}
// Remove the first object from the stack of traversed objects.
aStack.pop();
bStack.pop();
return result;
};
// Perform a deep comparison to check if two objects are equal.
utils.isEqual = function(a, b) {
return eq(a, b, [], []);
};
// Usage:
// utils.matchesSelector(div, '.something');
utils.matchesSelector = (function() {
if (typeof document === 'undefined') return;
// Suffix.
var sfx = 'MatchesSelector';
var tag = document.createElement('div');
var name;
// Detect the right suffix.
['matches', 'webkit' + sfx, 'moz' + sfx, 'ms' + sfx].some(function(item) {
var valid = (item in tag);
name = item;
return valid;
});
if (!name) throw new Error('Element#matches is not supported');
return function(element, selector) {
return element[name](selector);
};
})();
utils.delegate = function(view, eventName, selector, callback) {
if (typeof selector === 'function') {
callback = selector;
selector = null;
}
if (typeof callback !== 'function') {
throw new TypeError('View#delegate expects callback function');
}
var root = view.el;
var bound = callback.bind(view);
var handler = selector ? function(event) {
for (var el = event.target; el && el !== root; el = el.parentNode) {
if (utils.matchesSelector(el, selector)) {
// event.currentTarget or event.target are read-only.
event.delegateTarget = el;
return bound(event);
}
}
} : bound;
root.addEventListener(eventName, handler, false);
view._handlers.push({
eventName: eventName, selector: selector,
callback: callback, handler: handler
});
return handler;
};
utils.undelegate = function(view, eventName, selector, callback) {
if (typeof selector === 'function') {
callback = selector;
selector = null;
}
var handlers = view._handlers;
var removeListener = function(item) {
view.el.removeEventListener(item.eventName, item.handler, false);
};
// Remove all handlers.
if (!eventName && !selector && !callback) {
handlers.forEach(removeListener);
view._handlers = [];
} else {
// Remove some handlers.
handlers
.filter(function(item) {
return item.eventName === eventName &&
(callback ? item.callback === callback : true) &&
(selector ? item.selector === selector : true);
})
.forEach(function(item) {
removeListener(item);
handlers.splice(handlers.indexOf(item), 1);
});
}
};
// Make AJAX request to the server.
// Usage:
// var callback = function(error, data) {console.log('Done.', error, data);};
// ajax({url: 'url', type: 'PATCH', data: 'data'}, callback);
utils.ajax = (function() {
var xmlRe = /^(?:application|text)\/xml/;
var jsonRe = /^application\/json/;
var getData = function(accepts, xhr) {
if (accepts == null) accepts = xhr.getResponseHeader('content-type');
if (xmlRe.test(accepts)) {
return xhr.responseXML;
} else if (jsonRe.test(accepts)) {
return JSON.parse(xhr.responseText);
} else {
return xhr.responseText;
}
};
var isValid = function(xhr) {
return (xhr.status >= 200 && xhr.status < 300) ||
(xhr.status === 304) ||
(xhr.status === 0 && window.location.protocol === 'file:')
};
var end = function(xhr, options, deferred) {
return function() {
if (xhr.readyState !== 4) return;
var status = xhr.status;
var data = getData(options.headers && options.headers.Accept, xhr);
// Check for validity.
if (isValid(xhr)) {
if (options.success) options.success(data);
if (deferred) deferred.resolve(data);
} else {
var error = new Error('Server responded with a status of ' + status);
if (options.error) options.error(xhr, status, error);
if (deferred) deferred.reject(xhr);
}
}
};
return function(options) {
if (options == null) throw new Error('You must provide options');
if (options.type == null) options.type = 'GET';
var xhr = new XMLHttpRequest();
var deferred = Backbone.Deferred && Backbone.Deferred();
if (options.contentType) {
if (options.headers == null) options.headers = {};
options.headers['Content-Type'] = options.contentType;
}
// Stringify GET query params.
if (options.type === 'GET' && typeof options.data === 'object') {
var query = '';
var stringifyKeyValuePair = function(key, value) {
return value == null ? '' :
'&' + encodeURIComponent(key) +
'=' + encodeURIComponent(value);
};
for (var key in options.data) {
query += stringifyKeyValuePair(key, options.data[key]);
}
if (query) {
var sep = (options.url.indexOf('?') === -1) ? '?' : '&';
options.url += sep + query.substring(1);
}
}
if (options.credentials) options.withCredentials = true;
xhr.addEventListener('readystatechange', end(xhr, options, deferred));
xhr.open(options.type, options.url, true);
if (options.headers) for (var key in options.headers) {
xhr.setRequestHeader(key, options.headers[key]);
}
if (options.beforeSend) options.beforeSend(xhr);
xhr.send(options.data);
return deferred ? deferred.promise : undefined;
};
})();
// Backbone.Events
// ---------------
// A module that can be mixed in to *any object* in order to provide it with
// custom events. You may bind with `on` or remove with `off` callback
// functions to an event; `trigger`-ing an event fires all callbacks in
// succession.
//
// var object = {};
// _.extend(object, Backbone.Events);
// object.on('expand', function(){ alert('expanded'); });
// object.trigger('expand');
//
var Events = Backbone.Events = {
// Bind an event to a `callback` function. Passing `"all"` will bind
// the callback to all events fired.
on: function(name, callback, context) {
if (!eventsApi(this, 'on', name, [callback, context]) || !callback)
return this;
this._events || (this._events = {});
var events = this._events[name] || (this._events[name] = []);
events.push({callback: callback, context: context, ctx: context || this});
return this;
},
// Bind an event to only be triggered a single time. After the first time
// the callback is invoked, it will be removed.
once: function(name, callback, context) {
if (!eventsApi(this, 'once', name, [callback, context]) || !callback)
return this;
var self = this;
var ran;
var once = function() {
if (ran) return;
ran = true;
self.off(name, once);
callback.apply(this, arguments);
};
once._callback = callback;
return this.on(name, once, context);
},
// Remove one or many callbacks. If `context` is null, removes all
// callbacks with that function. If `callback` is null, removes all
// callbacks for the event. If `name` is null, removes all bound
// callbacks for all events.
off: function(name, callback, context) {
var retain, ev, events, names, i, l, j, k;
if (!this._events || !eventsApi(this, 'off', name, [callback, context]))
return this;
if (!name && !callback && !context) {
this._events = undefined;
return this;
}
names = name ? [name] : Object.keys(this._events);
for (i = 0, l = names.length; i < l; i++) {
name = names[i];
if (events = this._events[name]) {
this._events[name] = retain = [];
if (callback || context) {
for (j = 0, k = events.length; j < k; j++) {
ev = events[j];
if ((callback && callback !== ev.callback &&
callback !== ev.callback._callback) ||
(context && context !== ev.context)) {
retain.push(ev);
}
}
}
if (!retain.length) delete this._events[name];
}
}
return this;
},
// Trigger one or many events, firing all bound callbacks. Callbacks are
// passed the same arguments as `trigger` is, apart from the event name
// (unless you're listening on `"all"`, which will cause your callback to
// receive the true name of the event as the first argument).
trigger: function(name) {
if (!this._events) return this;
var args = slice.call(arguments, 1);
if (!eventsApi(this, 'trigger', name, args)) return this;
var events = this._events[name];
var allEvents = this._events.all;
if (events) triggerEvents(events, args);
if (allEvents) triggerEvents(allEvents, arguments);
return this;
},
// Tell this object to stop listening to either specific events ... or
// to every object it's currently listening to.
stopListening: function(obj, name, callback) {
var listeningTo = this._listeningTo;
if (!listeningTo) return this;
var remove = !name && !callback;
if (!callback && typeof name === 'object') callback = this;
if (obj) (listeningTo = {})[obj._listenId] = obj;
for (var id in listeningTo) {
obj = listeningTo[id];
obj.off(name, callback, this);
if (remove || !Object.keys(obj._events).length) {
delete this._listeningTo[id];
}
}
return this;
}
};
// Regular expression used to split event strings.
var eventSplitter = /\s+/;
// Implement fancy features of the Events API such as multiple event
// names `"change blur"` and jQuery-style event maps `{change: action}`
// in terms of the existing API.
var eventsApi = function(obj, action, name, rest) {
if (!name) return true;
var arr;
// Handle event maps.
if (typeof name === 'object') {
for (var key in name) {
arr = [key, name[key]];
push.apply(arr, rest);
obj[action].apply(obj, arr);
}
return false;
}
// Handle space separated event names.
if (eventSplitter.test(name)) {
var names = name.split(eventSplitter);
for (var i = 0, l = names.length; i < l; i++) {
arr = [names[i]];
push.apply(arr, rest);
obj[action].apply(obj, arr);
}
return false;
}
return true;
};
// A difficult-to-believe, but optimized internal dispatch function for
// triggering events. Tries to keep the usual cases speedy (most internal
// Backbone events have 3 arguments).
var triggerEvents = function(events, args) {
var ev, i = -1, l = events.length, a1 = args[0], a2 = args[1], a3 = args[2];
switch (args.length) {
case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); return;
case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return;
case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return;
case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return;
default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args);
}
};
var listenMethods = {listenTo: 'on', listenToOnce: 'once'};
// Inversion-of-control versions of `on` and `once`. Tell *this* object to
// listen to an event in another object ... keeping track of what it's
// listening to.
Object.keys(listenMethods).forEach(function(method) {
var implementation = listenMethods[method];
Events[method] = function(obj, name, callback) {
var listeningTo = this._listeningTo || (this._listeningTo = {});
var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
listeningTo[id] = obj;
if (!callback && typeof name === 'object') callback = this;
obj[implementation](name, callback, this);
return this;
};
});
// Aliases for backwards compatibility.
Events.bind = Events.on;
Events.unbind = Events.off;
// Backbone.Model
// --------------
// Backbone **Models** are the basic data object in the framework --
// frequently representing a row in a table in a database on your server.
// A discrete chunk of data and a bunch of useful, related methods for
// performing computations and transformations on that data.
// Create a new model with the specified attributes. A client id (`cid`)
// is automatically generated and assigned for you.
var Model = Backbone.Model = function(attributes, options) {
var attrs = attributes || {};
options || (options = {});
this.cid = _.uniqueId('c');
this.attributes = Object.create(null);
if (options.collection) this.collection = options.collection;
if (options.parse) attrs = this.parse(attrs, options) || {};
attrs = _.defaults({}, attrs, _.result(this, 'defaults'));
this.set(attrs, options);
this.changed = Object.create(null);
this.initialize.apply(this, arguments);
};
// Attach all inheritable methods to the Model prototype.
_.extend(Model.prototype, Events, {
// A hash of attributes whose current and previous value differ.
changed: null,
// The value returned during the last failed validation.
validationError: null,
// The default name for the JSON `id` attribute is `"id"`. MongoDB and
// CouchDB users may want to set this to `"_id"`.
idAttribute: 'id',
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function(){},
// Return a copy of the model's `attributes` object.
toJSON: function(options) {
return _.extend(Object.create(null), this.attributes);
},
// Proxy `Backbone.sync` by default -- but override this if you need
// custom syncing semantics for *this* particular model.
sync: function() {
return Backbone.sync.apply(this, arguments);
},
// Get the value of an attribute.
get: function(attr) {
return this.attributes[attr];
},
// Get the HTML-escaped value of an attribute.
escape: function(attr) {
return _.escape(this.get(attr));
},
// Returns `true` if the attribute contains a value that is not null
// or undefined.
has: function(attr) {
return this.get(attr) != null;
},
// Set a hash of model attributes on the object, firing `"change"`. This is
// the core primitive operation of a model, updating the data and notifying
// anyone who needs to know about the change in state. The heart of the beast.
set: function(key, val, options) {
var attr, attrs, unset, changes, silent, changing, prev, current;
if (key == null) return this;
// Handle both `"key", value` and `{key: value}` -style arguments.
if (typeof key === 'object') {
attrs = key;
options = val;
} else {
(attrs = {})[key] = val;
}
options || (options = {});
// Run validation.
if (!this._validate(attrs, options)) return false;
// Extract attributes and options.
unset = options.unset;
silent = options.silent;
changes = [];
changing = this._changing;
this._changing = true;
if (!changing) {
this._previousAttributes = _.extend(Object.create(null), this.attributes);
this.changed = {};
}
current = this.attributes, prev = this._previousAttributes;
// Check for changes of `id`.
if (this.idAttribute in attrs) this.id = attrs[this.idAttribute];
// For each `set` attribute, update or delete the current value.
for (attr in attrs) {
val = attrs[attr];
if (!_.isEqual(current[attr], val)) changes.push(attr);
if (!_.isEqual(prev[attr], val)) {
this.changed[attr] = val;
} else {
delete this.changed[attr];
}
unset ? delete current[attr] : current[attr] = val;
}
// Trigger all relevant attribute changes.
if (!silent) {
if (changes.length) this._pending = true;
for (var i = 0, l = changes.length; i < l; i++) {
this.trigger('change:' + changes[i], this, current[changes[i]], options);
}
}
// You might be wondering why there's a `while` loop here. Changes can
// be recursively nested within `"change"` events.
if (changing) return this;
if (!silent) {
while (this._pending) {
this._pending = false;
this.trigger('change', this, options);
}
}
this._pending = false;
this._changing = false;
return this;
},
// Remove an attribute from the model, firing `"change"`. `unset` is a noop
// if the attribute doesn't exist.
unset: function(attr, options) {
return this.set(attr, void 0, _.extend({}, options, {unset: true}));
},
// Clear all attributes on the model, firing `"change"`.
clear: function(options) {
var attrs = {};
for (var key in this.attributes) attrs[key] = void 0;
return this.set(attrs, _.extend({}, options, {unset: true}));
},
// Determine if the model has changed since the last `"change"` event.
// If you specify an attribute name, determine if that attribute has changed.
hasChanged: function(attr) {
if (attr == null) return !!Object.keys(this.changed).length;
return hasOwnProperty.call(this.changed, attr);
},
// Return an object containing all the attributes that have changed, or
// false if there are no changed attributes. Useful for determining what
// parts of a view need to be updated and/or what attributes need to be
// persisted to the server. Unset attributes will be set to undefined.
// You can also pass an attributes object to diff against the model,
// determining if there *would be* a change.
changedAttributes: function(diff) {
if (!diff) return this.hasChanged() ? _.extend(Object.create(null), this.changed) : false;
var val, changed = false;
var old = this._changing ? this._previousAttributes : this.attributes;
for (var attr in diff) {
if (_.isEqual(old[attr], (val = diff[attr]))) continue;
(changed || (changed = {}))[attr] = val;
}
return changed;
},
// Get the previous value of an attribute, recorded at the time the last
// `"change"` event was fired.
previous: function(attr) {
if (attr == null || !this._previousAttributes) return null;
return this._previousAttributes[attr];
},
// Get all of the attributes of the model at the time of the previous
// `"change"` event.
previousAttributes: function() {
return _.extend(Object.create(null), this._previousAttributes);
},
// Fetch the model from the server. If the server's representation of the
// model differs from its current attributes, they will be overridden,
// triggering a `"change"` event.
fetch: function(options) {
options = options ? _.extend({}, options) : {};
if (options.parse === void 0) options.parse = true;
var model = this;
var success = options.success;
options.success = function(resp) {
if (!model.set(model.parse(resp, options), options)) return false;
if (success) success(model, resp, options);
model.trigger('sync', model, resp, options);
};
wrapError(this, options);
return this.sync('read', this, options);
},
// Set a hash of model attributes, and sync the model to the server.
// If the server returns an attributes hash that differs, the model's
// state will be `set` again.
save: function(key, val, options) {
var attrs, method, xhr, attributes = this.attributes;
// Handle both `"key", value` and `{key: value}` -style arguments.
if (key == null || typeof key === 'object') {
attrs = key;
options = val;
} else {
(attrs = {})[key] = val;
}
options = _.extend({validate: true}, options);
// If we're not waiting and attributes exist, save acts as
// `set(attr).save(null, opts)` with validation. Otherwise, check if
// the model will be valid when the attributes, if any, are set.
if (attrs && !options.wait) {
if (!this.set(attrs, options)) return false;
} else {
if (!this._validate(attrs, options)) return false;
}
// Set temporary attributes if `{wait: true}`.
if (attrs && options.wait) {
this.attributes = _.extend(Object.create(null), attributes, attrs);
}
// After a successful server-side save, the client is (optionally)
// updated with the server-side state.
if (options.parse === void 0) options.parse = true;
var model = this;
var success = options.success;
options.success = function(resp) {
// Ensure attributes are restored during synchronous saves.
model.attributes = attributes;
var serverAttrs = model.parse(resp, options);
if (options.wait) serverAttrs = _.extend(attrs || {}, serverAttrs);
if (serverAttrs && typeof serverAttrs === 'object' && !model.set(serverAttrs, options)) {
return false;
}
if (success) success(model, resp, options);
model.trigger('sync', model, resp, options);
};
wrapError(this, options);
method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
if (method === 'patch') options.attrs = attrs;
xhr = this.sync(method, this, options);
// Restore attributes.
if (attrs && options.wait) this.attributes = attributes;
return xhr;
},
// Destroy this model on the server if it was already persisted.
// Optimistically removes the model from its collection, if it has one.
// If `wait: true` is passed, waits for the server to respond before removal.
destroy: function(options) {
options = options ? _.extend({}, options) : {};
var model = this;
var success = options.success;
var destroy = function() {
model.trigger('destroy', model, model.collection, options);
};
options.success = function(resp) {
if (options.wait || model.isNew()) destroy();
if (success) success(model, resp, options);
if (!model.isNew()) model.trigger('sync', model, resp, options);
};
if (this.isNew()) {
options.success();
return false;
}
wrapError(this, options);
var xhr = this.sync('delete', this, options);
if (!options.wait) destroy();
return xhr;
},
// Default URL for the model's representation on the server -- if you're
// using Backbone's restful methods, override this to change the endpoint
// that will be called.
url: function() {
var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url') || urlError();
if (this.isNew()) return base;
return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id);
},
// **parse** converts a response into the hash of attributes to be `set` on
// the model. The default implementation is just to pass the response along.
parse: function(resp, options) {
return resp;
},
// Create a new model with identical attributes to this one.
clone: function() {
return new this.constructor(this.attributes);
},
// A model is new if it has never been saved to the server, and lacks an id.
isNew: function() {
return this.id == null;
},
// Check if the model is currently in a valid state.
isValid: function(options) {
return this._validate({}, _.extend(options || {}, { validate: true }));
},
// Run validation against the next complete set of model attributes,
// returning `true` if all is well. Otherwise, fire an `"invalid"` event.
_validate: function(attrs, options) {
if (!options.validate || !this.validate) return true;
attrs = _.extend(Object.create(null), this.attributes, attrs);
var error = this.validationError = this.validate(attrs, options) || null;
if (!error) return true;
this.trigger('invalid', this, error, _.extend(options, {validationError: error}));
return false;
}
});
if (_.keys) {
// Underscore methods that we want to implement on the Model.
var modelMethods = ['keys', 'values', 'pairs', 'invert', 'pick', 'omit'];
// Mix in each Underscore method as a proxy to `Model#attributes`.
modelMethods.filter(utilExists).forEach(function(method) {
Model.prototype[method] = function() {
var args = slice.call(arguments);
args.unshift(this.attributes);
return _[method].apply(_, args);
};
});
}
// Backbone.Collection
// -------------------
// If models tend to represent a single row of data, a Backbone Collection is
// more analagous to a table full of data ... or a small slice or page of that
// table, or a collection of rows that belong together for a particular reason
// -- all of the messages in this particular folder, all of the documents
// belonging to this particular author, and so on. Collections maintain
// indexes of their models, both in order, and for lookup by `id`.
// Create a new **Collection**, perhaps to contain a specific type of `model`.
// If a `comparator` is specified, the Collection will maintain
// its models in sort order, as they're added and removed.
var Collection = Backbone.Collection = function(models, options) {
options || (options = {});
if (options.model) this.model = options.model;
if (options.comparator !== void 0) this.comparator = options.comparator;
this._reset();
this.initialize.apply(this, arguments);
if (models) this.reset(models, _.extend({silent: true}, options));
};
// Default options for `Collection#set`.
var setOptions = {add: true, remove: true, merge: true};
var addOptions = {add: true, remove: false};
// Define the Collection's inheritable methods.
_.extend(Collection.prototype, Events, {
// The default model for a collection is just a **Backbone.Model**.
// This should be overridden in most cases.
model: typeof Model === 'undefined' ? null : Model,
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function(){},
// The JSON representation of a Collection is an array of the
// models' attributes.
toJSON: function(options) {
return this.map(function(model){ return model.toJSON(options); });
},
// Proxy `Backbone.sync` by default.
sync: function() {
return Backbone.sync.apply(this, arguments);
},
// Add a model, or list of models to the set.
add: function(models, options) {
return this.set(models, _.extend({merge: false}, options, addOptions));
},
// Remove a model, or a list of models from the set.
remove: function(models, options) {
var singular = !Array.isArray(models);
models = singular ? [models] : models.slice();
options || (options = {});
var i, l, index, model;
for (i = 0, l = models.length; i < l; i++) {
model = models[i] = this.get(models[i]);
if (!model) continue;
delete this._byId[model.id];
delete this._byId[model.cid];
index = this.indexOf(model);
this.models.splice(index, 1);
this.length--;
if (!options.silent) {
options.index = index;
model.trigger('remove', model, this, options);
}
this._removeReference(model);
}
return singular ? models[0] : models;
},
// Update a collection by `set`-ing a new list of models, adding new ones,
// removing models that are no longer present, and merging models that
// already exist in the collection, as necessary. Similar to **Model#set**,
// the core operation for updating the data contained by the collection.
set: function(models, options) {
options = _.defaults({}, options, setOptions);
if (options.parse) models = this.parse(models, options);
var singular = !Array.isArray(models);
models = singular ? (models ? [models] : []) : models.slice();
var i, l, id, model, attrs, existing, sort;
var at = options.at;
var targetModel = this.model;
var sortable = this.comparator && (at == null) && options.sort !== false;
var sortAttr = typeof this.comparator === 'string' ? this.comparator : null;
var toAdd = [], toRemove = [], modelMap = {};
var add = options.add, merge = options.merge, remove = options.remove;
var order = !sortable && add && remove ? [] : false;
// Turn bare objects into model references, and prevent invalid models
// from being added.
for (i = 0, l = models.length; i < l; i++) {
attrs = models[i];
if (attrs instanceof Model) {
id = model = attrs;
} else {
id = attrs[targetModel.prototype.idAttribute];
}
// If a duplicate is found, prevent it from being added and
// optionally merge it into the existing model.
if (existing = this.get(id)) {
if (remove) modelMap[existing.cid] = true;
if (merge) {
attrs = attrs === model ? model.attributes : attrs;
if (options.parse) attrs = existing.parse(attrs, options);
existing.set(attrs, options);
if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true;
}
models[i] = existing;
// If this is a new, valid model, push it to the `toAdd` list.
} else if (add) {
model = models[i] = this._prepareModel(attrs, options);
if (!model) continue;
toAdd.push(model);
// Listen to added models' events, and index models for lookup by
// `id` and by `cid`.
model.on('all', this._onModelEvent, this);
this._byId[model.cid] = model;
if (model.id != null) this._byId[model.id] = model;
}
if (order) order.push(existing || model);
}
// Remove nonexistent models if appropriate.
if (remove) {
for (i = 0, l = this.length; i < l; ++i) {
if (!modelMap[(model = this.models[i]).cid]) toRemove.push(model);
}
if (toRemove.length) this.remove(toRemove, options);
}
// See if sorting is needed, update `length` and splice in new models.
if (toAdd.length || (order && order.length)) {
if (sortable) sort = true;
this.length += toAdd.length;
if (at != null) {
for (i = 0, l = toAdd.length; i < l; i++) {
this.models.splice(at + i, 0, toAdd[i]);
}
} else {
if (order) this.models.length = 0;
var orderedModels = order || toAdd;
for (i = 0, l = orderedModels.length; i < l; i++) {
this.models.push(orderedModels[i]);
}
}
}
// Silently sort the collection if appropriate.
if (sort) this.sort({silent: true});
// Unless silenced, it's time to fire all appropriate add/sort events.
if (!options.silent) {
for (i = 0, l = toAdd.length; i < l; i++) {
(model = toAdd[i]).trigger('add', model, this, options);
}
if (sort || (order && order.length)) this.trigger('sort', this, options);
}
// Return the added (or merged) model (or models).
return singular ? models[0] : models;
},
// When you have more items than you want to add or remove individually,
// you can reset the entire set with a new list of models, without firing
// any granular `add` or `remove` events. Fires `reset` when finished.
// Useful for bulk operations and optimizations.
reset: function(models, options) {
options || (options = {});
for (var i = 0, l = this.models.length; i < l; i++) {
this._removeReference(this.models[i]);
}
options.previousModels = this.models;
this._reset();
models = this.add(models, _.extend({silent: true}, options));
if (!options.silent) this.trigger('reset', this, options);
return models;
},
// Add a model to the end of the collection.
push: function(model, options) {
return this.add(model, _.extend({at: this.length}, options));
},
// Remove a model from the end of the collection.
pop: function(options) {
var model = this.at(this.length - 1);
this.remove(model, options);
return model;
},
// Add a model to the beginning of the collection.
unshift: function(model, options) {
return this.add(model, _.extend({at: 0}, options));
},
// Remove a model from the beginning of the collection.
shift: function(options) {
var model = this.at(0);
this.remove(model, options);
return model;
},
// Slice out a sub-array of models from the collection.
slice: function() {
return slice.apply(this.models, arguments);
},
// Get a model from the set by id.
get: function(obj) {
if (obj == null) return void 0;
return this._byId[obj.id] || this._byId[obj.cid] || this._byId[obj];
},
// Get the model at the given index.
at: function(index) {
return this.models[index];
},
// Return models with matching attributes. Useful for simple cases of
// `filter`.
where: function(attrs, first) {
if (!attrs || !Object.keys(attrs).length) return first ? void 0 : [];
return this[first ? 'find' : 'filter'](function(model) {
for (var key in attrs) {
if (attrs[key] !== model.get(key)) return false;
}
return true;
});
},
// Return the first model with matching attributes. Useful for simple cases
// of `find`.
findWhere: function(attrs) {
return this.where(attrs, true);
},
// Force the collection to re-sort itself. You don't need to call this under
// normal circumstances, as the set will maintain sort order as each item
// is added.
sort: function(options) {
if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
options || (options = {});
// Run sort based on type of `comparator`.
if (typeof this.comparator === 'string' || this.comparator.length === 1) {
this.models = this.sortBy(this.comparator, this);
} else {
this.models.sort(this.comparator.bind(this));
}
if (!options.silent) this.trigger('sort', this, options);
return this;
},
// Pluck an attribute from each model in the collection.
pluck: function(attr) {
return this.models.map(function(model) {
return model.get(attr);
});
},
// Fetch the default set of models for this collection, resetting the
// collection when they arrive. If `reset: true` is passed, the response
// data will be passed through the `reset` method instead of `set`.
fetch: function(options) {
options = options ? _.extend({}, options) : {};
if (options.parse === void 0) options.parse = true;
var success = options.success;
var collection = this;
options.success = function(resp) {
var method = options.reset ? 'reset' : 'set';
collection[method](resp, options);
if (success) success(collection, resp, options);
collection.trigger('sync', collection, resp, options);
};
wrapError(this, options);
return this.sync('read', this, options);
},
// Create a new instance of a model in this collection. Add the model to the
// collection immediately, unless `wait: true` is passed, in which case we
// wait for the server to agree.
create: function(model, options) {
options = options ? _.extend({}, options) : {};
if (!(model = this._prepareModel(model, options))) return false;
if (!options.wait) this.add(model, options);
var collection = this;
var success = options.success;
options.success = function(model, resp, options) {
if (options.wait) collection.add(model, options);
if (success) success(model, resp, options);
};
model.save(null, options);
return model;
},
// **parse** converts a response into a list of models to be added to the
// collection. The default implementation is just to pass it through.
parse: function(resp, options) {
return resp;
},
// Create a new collection with an identical list of models as this one.
clone: function() {
return new this.constructor(this.models);
},
// Private method to reset all internal state. Called when the collection
// is first initialized or reset.
_reset: function() {
this.length = 0;
this.models = [];
this._byId = Object.create(null);
},
// Prepare a hash of attributes (or other model) to be added to this
// collection.
_prepareModel: function(attrs, options) {
if (attrs instanceof Collection.prototype.model) {
if (!attrs.collection) attrs.collection = this;
return attrs;
}
options = options ? _.extend({}, options) : {};
options.collection = this;
var model = new this.model(attrs, options);
if (!model.validationError) return model;
this.trigger('invalid', this, model.validationError, options);
return false;
},
// Internal method to sever a model's ties to a collection.
_removeReference: function(model) {
if (this === model.collection) delete model.collection;
model.off('all', this._onModelEvent, this);
},
// Internal method called every time a model in the set fires an event.
// Sets need to update their indexes when models change ids. All other
// events simply proxy through. "add" and "remove" events that originate
// in other collections are ignored.
_onModelEvent: function(event, model, collection, options) {
if ((event === 'add' || event === 'remove') && collection !== this) return;
if (event === 'destroy') this.remove(model, options);
if (model && event === 'change:' + model.idAttribute) {
delete this._byId[model.previous(model.idAttribute)];
if (model.id != null) this._byId[model.id] = model;
}
this.trigger.apply(this, arguments);
}
});
if (utilExists('each')) {
// Underscore methods that we want to implement on the Collection.
// 90% of the core usefulness of Backbone Collections is actually implemented
// right here:
var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
'tail', 'drop', 'last', 'without', 'difference', 'indexOf', 'shuffle',
'lastIndexOf', 'isEmpty', 'chain'];
// Mix in each Underscore method as a proxy to `Collection#models`.
methods.filter(utilExists).forEach(function(method) {
Collection.prototype[method] = function() {
var args = slice.call(arguments);
args.unshift(this.models);
return _[method].apply(_, args);
};
});
// Underscore methods that take a property name as an argument.
var attributeMethods = ['groupBy', 'countBy', 'sortBy'];
// Use attributes instead of properties.
attributeMethods.filter(utilExists).forEach(function(method) {
Collection.prototype[method] = function(value, context) {
var iterator = typeof value === 'function' ? value : function(model) {
return model.get(value);
};
return _[method](this.models, iterator, context);
};
});
} else {
['forEach', 'map', 'filter', 'some', 'every', 'reduce', 'reduceRight',
'indexOf', 'lastIndexOf'].forEach(function(method) {
Collection.prototype[method] = function(arg, context) {
return this.models[method](arg, context);
};
});
// Exoskeleton-specific:
Collection.prototype.find = function(iterator, context) {
var result;
this.some(function(value, index, list) {
if (iterator.call(context, value, index, list)) {
result = value;
return true;
}
});
return result;
};
// Underscore methods that take a property name as an argument.
['sortBy'].forEach(function(method) {
Collection.prototype[method] = function(value, context) {
var iterator = typeof value === 'function' ? value : function(model) {
return model.get(value);
};
return _[method](this.models, iterator, context);
};
});
}
// Backbone.View
// -------------
// Backbone Views are almost more convention than they are actual code. A View
// is simply a JavaScript object that represents a logical chunk of UI in the
// DOM. This might be a single item, an entire list, a sidebar or panel, or
// even the surrounding frame which wraps your whole app. Defining a chunk of
// UI as a **View** allows you to define your DOM events declaratively, without
// having to worry about render order ... and makes it easy for the view to
// react to specific changes in the state of your models.
// Options with special meaning *(e.g. model, collection, id, className)* are
// attached directly to the view. See `viewOptions` for an exhaustive
// list.
// Cached regex to split keys for `delegate`.
var delegateEventSplitter = /^(\S+)\s*(.*)$/;
// List of view options to be merged as properties.
var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
// Creating a Backbone.View creates its initial element outside of the DOM,
// if an existing element is not provided...
var View = Backbone.View = function(options) {
this.cid = _.uniqueId('view');
if (options) Object.keys(options).forEach(function(key) {
if (viewOptions.indexOf(key) !== -1) this[key] = options[key];
}, this);
this._handlers = [];
this._ensureElement();
this.initialize.apply(this, arguments);
this.delegateEvents();
};
// Set up all inheritable **Backbone.View** properties and methods.
_.extend(View.prototype, Events, {
// In case you want to include jQuery with your app
// for *some* views and use native methods for other views.
useNative: false,
// The default `tagName` of a View's element is `"div"`.
tagName: 'div',
// jQuery delegate for element lookup, scoped to DOM elements within the
// current view. This should be preferred to global lookups where possible.
$: function(selector) {
return Backbone.$ && !this.useNative ? this.$el.find(selector) : this.findAll(selector);
},
// Exoskeleton-related DOM methods.
find: function(selector) {
return this.el.querySelector(selector);
},
findAll: function(selector) {
return slice.call(this.el.querySelectorAll(selector));
},
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function(){},
// **render** is the core function that your view should override, in order
// to populate its element (`this.el`), with the appropriate HTML. The
// convention is for **render** to always return `this`.
render: function() {
return this;
},
// Remove this view by taking the element out of the DOM, and removing any
// applicable Backbone.Events listeners.
remove: function() {
var parent;
if (Backbone.$ && !this.useNative) {
this.$el.remove();
} else if (parent = this.el.parentNode) {
parent.removeChild(this.el);
}
this.stopListening();
return this;
},
// Change the view's element (`this.el` property), including event
// re-delegation.
setElement: function(element, delegate) {
if (Backbone.$ && !this.useNative) {
if (this.$el) this.undelegateEvents();
this.$el = element instanceof Backbone.$ ? element : Backbone.$(element);
this.el = this.$el[0];
} else {
if (this.el) this.undelegateEvents();
this.el = (typeof element === 'string') ?
document.querySelector(element) : element;
}
if (delegate !== false) this.delegateEvents();
return this;
},
// Set callbacks, where `this.events` is a hash of
//
// *{"event selector": "callback"}*
//
// {
// 'mousedown .title': 'edit',
// 'click .button': 'save',
// 'click .open': function(e) { ... }
// }
//
// pairs. Callbacks will be bound to the view, with `this` set properly.
// Uses event delegation for efficiency.
// Omitting the selector binds the event to `this.el`.
// This only works for delegate-able events: not `focus`, `blur`, and
// not `change`, `submit`, and `reset` in Internet Explorer.
delegateEvents: function(events, keepOld) {
if (!(events || (events = _.result(this, 'events')))) return this;
if (!keepOld) this.undelegateEvents();
for (var key in events) {
var method = events[key];
if (typeof method !== 'function') method = this[events[key]];
// if (!method) continue;
var match = key.match(delegateEventSplitter);
var eventName = match[1], selector = match[2];
if (Backbone.$ && !this.useNative) {
eventName += '.delegateEvents' + this.cid;
method = method.bind(this);
this.$el.on(eventName, (selector ? selector : null), method);
} else {
utils.delegate(this, eventName, selector, method);
}
}
return this;
},
// Clears all callbacks previously bound to the view with `delegateEvents`.
// You usually don't need to use this, but may wish to if you have multiple
// Backbone views attached to the same DOM element.
undelegateEvents: function() {
if (Backbone.$ && !this.useNative) {
this.$el.off('.delegateEvents' + this.cid);
} else {
utils.undelegate(this);
}
return this;
},
// Ensure that the View has a DOM element to render into.
// If `this.el` is a string, pass it through `$()`, take the first
// matching element, and re-assign it to `el`. Otherwise, create
// an element from the `id`, `className` and `tagName` properties.
_ensureElement: function() {
if (!this.el) {
var attrs = _.extend({}, _.result(this, 'attributes'));
if (this.id) attrs.id = _.result(this, 'id');
if (this.className) attrs.className = _.result(this, 'className');
if (attrs['class']) attrs.className = attrs['class'];
var el = _.extend(document.createElement(_.result(this, 'tagName')), attrs);
this.setElement(el, false);
} else {
this.setElement(_.result(this, 'el'), false);
}
}
});
// Backbone.sync
// -------------
// Override this function to change the manner in which Backbone persists
// models to the server. You will be passed the type of request, and the
// model in question. By default, makes a RESTful Ajax request
// to the model's `url()`. Some possible customizations could be:
//
// * Use `setTimeout` to batch rapid-fire updates into a single request.
// * Send up the models as XML instead of JSON.
// * Persist models via WebSockets instead of Ajax.
//
// Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests
// as `POST`, with a `_method` parameter containing the true HTTP method,
// as well as all requests with the body as `application/x-www-form-urlencoded`
// instead of `application/json` with the model in a param named `model`.
// Useful when interfacing with server-side languages like **PHP** that make
// it difficult to read the body of `PUT` requests.
Backbone.sync = function(method, model, options) {
var type = methodMap[method];
// Default options, unless specified.
_.defaults(options || (options = {}), {
emulateHTTP: Backbone.emulateHTTP,
emulateJSON: Backbone.emulateJSON
});
// Default JSON-request options.
var params = {type: type, dataType: 'json'};
// Ensure that we have a URL.
if (!options.url) {
params.url = _.result(model, 'url') || urlError();
}
// Ensure that we have the appropriate request data.
if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
params.contentType = 'application/json';
params.data = JSON.stringify(options.attrs || model.toJSON(options));
}
// For older servers, emulate JSON by encoding the request into an HTML-form.
if (options.emulateJSON) {
params.contentType = 'application/x-www-form-urlencoded';
params.data = params.data ? {model: params.data} : {};
}
// For older servers, emulate HTTP by mimicking the HTTP method with `_method`
// And an `X-HTTP-Method-Override` header.
if (options.emulateHTTP && (type === 'PUT' || type === 'DELETE' || type === 'PATCH')) {
params.type = 'POST';
if (options.emulateJSON) params.data._method = type;
var beforeSend = options.beforeSend;
options.beforeSend = function(xhr) {
xhr.setRequestHeader('X-HTTP-Method-Override', type);
if (beforeSend) return beforeSend.apply(this, arguments);
};
}
// Don't process data on a non-GET request.
if (params.type !== 'GET' && !options.emulateJSON) {
params.processData = false;
}
// Make the request, allowing the user to override any Ajax options.
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
model.trigger('request', model, xhr, options);
return xhr;
};
// Map from CRUD to HTTP for our default `Backbone.sync` implementation.
var methodMap = {
'create': 'POST',
'update': 'PUT',
'patch': 'PATCH',
'delete': 'DELETE',
'read': 'GET'
};
// Set the default implementation of `Backbone.ajax` to proxy through to `$`.
// Override this if you'd like to use a different library.
Backbone.ajax = Backbone.$ ? function() {
return Backbone.$.ajax.apply(Backbone.$, arguments);
} : utils.ajax;
if (Backbone.$) Backbone.Deferred = function() {
return new Backbone.$.Deferred();
};
// Backbone.Router
// ---------------
// Routers map faux-URLs to actions, and fire events when routes are
// matched. Creating a new one sets its `routes` hash, if not set statically.
var Router = Backbone.Router = function(options) {
options || (options = {});
if (options.routes) this.routes = options.routes;
this._bindRoutes();
this.initialize.apply(this, arguments);
};
// Cached regular expressions for matching named param parts and splatted
// parts of route strings.
var optionalParam = /\((.*?)\)/g;
var namedParam = /(\(\?)?:\w+/g;
var splatParam = /\*\w+/g;
var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
var isRegExp = function(value) {
return value ? (typeof value === 'object' && toString.call(value) === '[object RegExp]') : false;
};
// Set up all inheritable **Backbone.Router** properties and methods.
_.extend(Router.prototype, Events, {
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function(){},
// Manually bind a single named route to a callback. For example:
//
// this.route('search/:query/p:num', 'search', function(query, num) {
// ...
// });
//
route: function(route, name, callback) {
if (!isRegExp(route)) route = this._routeToRegExp(route);
if (typeof name === 'function') {
callback = name;
name = '';
}
if (!callback) callback = this[name];
var router = this;
Backbone.history.route(route, function(fragment) {
var args = router._extractParameters(route, fragment);
callback && callback.apply(router, args);
router.trigger.apply(router, ['route:' + name].concat(args));
router.trigger('route', name, args);
Backbone.history.trigger('route', router, name, args);
});
return this;
},
// Simple proxy to `Backbone.history` to save a fragment into the history.
navigate: function(fragment, options) {
Backbone.history.navigate(fragment, options);
return this;
},
// Bind all defined routes to `Backbone.history`. We have to reverse the
// order of the routes here to support behavior where the most general
// routes can be defined at the bottom of the route map.
_bindRoutes: function() {
if (!this.routes) return;
this.routes = _.result(this, 'routes');
var route, routes = Object.keys(this.routes);
while ((route = routes.pop()) != null) {
this.route(route, this.routes[route]);
}
},
// Convert a route string into a regular expression, suitable for matching
// against the current location hash.
_routeToRegExp: function(route) {
route = route.replace(escapeRegExp, '\\$&')
.replace(optionalParam, '(?:$1)?')
.replace(namedParam, function(match, optional) {
return optional ? match : '([^\/]+)';
})
.replace(splatParam, '(.*?)');
return new RegExp('^' + route + '$');
},
// Given a route, and a URL fragment that it matches, return the array of
// extracted decoded parameters. Empty or unmatched parameters will be
// treated as `null` to normalize cross-browser behavior.
_extractParameters: function(route, fragment) {
var params = route.exec(fragment).slice(1);
return params.map(function(param) {
return param ? decodeURIComponent(param) : null;
});
}
});
// Backbone.History
// ----------------
// Handles cross-browser history management, based on either
// [pushState](http://diveintohtml5.info/history.html) and real URLs, or
// [onhashchange](https://developer.mozilla.org/en-US/docs/DOM/window.onhashchange)
// and URL fragments.
var History = Backbone.History = function() {
this.handlers = [];
this.checkUrl = this.checkUrl.bind(this);
// Ensure that `History` can be used outside of the browser.
if (typeof window !== 'undefined') {
this.location = window.location;
this.history = window.history;
}
};
// Cached regex for stripping a leading hash/slash and trailing space.
var routeStripper = /^[#\/]|\s+$/g;
// Cached regex for stripping leading and trailing slashes.
var rootStripper = /^\/+|\/+$/g;
// Cached regex for removing a trailing slash.
var trailingSlash = /\/$/;
// Cached regex for stripping urls of hash and query.
var pathStripper = /[#].*$/;
// Has the history handling already been started?
History.started = false;
// Set up all inheritable **Backbone.History** properties and methods.
_.extend(History.prototype, Events, {
// Gets the true hash value. Cannot use location.hash directly due to bug
// in Firefox where location.hash will always be decoded.
getHash: function(window) {
var match = (window || this).location.href.match(/#(.*)$/);
return match ? match[1] : '';
},
// Get the cross-browser normalized URL fragment, either from the URL,
// the hash, or the override.
getFragment: function(fragment) {
if (fragment == null) {
if (this._wantsPushState || !this._wantsHashChange) {
// CHANGED: Make fragment include query string.
fragment = this.location.pathname + this.location.search;
var root = this.root.replace(trailingSlash, '');
if (!fragment.indexOf(root)) fragment = fragment.slice(root.length);
} else {
fragment = this.getHash();
}
}
return fragment.replace(routeStripper, '');
},
// Start the hash change handling, returning `true` if the current URL matches
// an existing route, and `false` otherwise.
start: function(options) {
if (History.started) throw new Error("Backbone.history has already been started");
History.started = true;
// Figure out the initial configuration.
// Is pushState desired or should we use hashchange only?
this.options = _.extend({root: '/'}, this.options, options);
this.root = this.options.root;
this._wantsHashChange = this.options.hashChange !== false;
this._wantsPushState = !!this.options.pushState;
var fragment = this.getFragment();
// Normalize root to always include a leading and trailing slash.
this.root = ('/' + this.root + '/').replace(rootStripper, '/');
// Depending on whether we're using pushState or hashes, determine how we
// check the URL state.
if (this._wantsPushState) {
window.addEventListener('popstate', this.checkUrl, false);
} else if (this._wantsHashChange) {
window.addEventListener('hashchange', this.checkUrl, false);
}
// Determine if we need to change the base url, for a pushState link
// opened by a non-pushState browser.
this.fragment = fragment;
var loc = this.location;
var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root;
// Transition from hashChange to pushState or vice versa if both are
// requested.
if (this._wantsHashChange && this._wantsPushState) {
// If we've started out with a hash-based route, but we're currently
// in a browser where it could be `pushState`-based instead...
if (atRoot && loc.hash) {
this.fragment = this.getHash().replace(routeStripper, '');
// CHANGED: It's no longer needed to add loc.search at the end,
// as query params have been already included into @fragment
this.history.replaceState({}, document.title, this.root + this.fragment);
}
}
if (!this.options.silent) return this.loadUrl();
},
// Disable Backbone.history, perhaps temporarily. Not useful in a real app,
// but possibly useful for unit testing Routers.
stop: function() {
window.removeEventListener('popstate', this.checkUrl);
window.removeEventListener('hashchange', this.checkUrl);
History.started = false;
},
// Add a route to be tested when the fragment changes. Routes added later
// may override previous routes.
route: function(route, callback) {
this.handlers.unshift({route: route, callback: callback});
},
// Checks the current URL to see if it has changed, and if it has,
// calls `loadUrl`.
checkUrl: function() {
var current = this.getFragment();
if (current === this.fragment) return false;
this.loadUrl();
},
// Attempt to load the current URL fragment. If a route succeeds with a
// match, returns `true`. If no defined routes matches the fragment,
// returns `false`.
loadUrl: function(fragment) {
fragment = this.fragment = this.getFragment(fragment);
return this.handlers.some(function(handler) {
if (handler.route.test(fragment)) {
handler.callback(fragment);
return true;
}
});
},
// Save a fragment into the hash history, or replace the URL state if the
// 'replace' option is passed. You are responsible for properly URL-encoding
// the fragment in advance.
//
// The options object can contain `trigger: true` if you wish to have the
// route callback be fired (not usually desirable), or `replace: true`, if
// you wish to modify the current URL without adding an entry to the history.
navigate: function(fragment, options) {
if (!History.started) return false;
if (!options || options === true) options = {trigger: !!options};
var url = this.root + (fragment = this.getFragment(fragment || ''));
// Strip the fragment of the query and hash for matching.
fragment = fragment.replace(pathStripper, '');
if (this.fragment === fragment) return;
this.fragment = fragment;
// Don't include a trailing slash on the root.
if (fragment === '' && url !== '/') url = url.slice(0, -1);
// If we're using pushState we use it to set the fragment as a real URL.
if (this._wantsPushState) {
this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url);
// If hash changes haven't been explicitly disabled, update the hash
// fragment to store history.
} else if (this._wantsHashChange) {
this._updateHash(this.location, fragment, options.replace);
// If you've told us that you explicitly don't want fallback hashchange-
// based history, then `navigate` becomes a page refresh.
} else {
return this.location.assign(url);
}
if (options.trigger) return this.loadUrl(fragment);
},
// Update the hash location, either replacing the current entry, or adding
// a new one to the browser history.
_updateHash: function(location, fragment, replace) {
if (replace) {
var href = location.href.replace(/(javascript:|#).*$/, '');
location.replace(href + '#' + fragment);
} else {
// Some browsers require that `hash` contains a leading #.
location.hash = '#' + fragment;
}
}
});
// !!!
// Init.
['Model', 'Collection', 'Router', 'View', 'History'].forEach(function(name) {
var item = Backbone[name];
if (item) item.extend = Backbone.extend;
});
// Allow the `Backbone` object to serve as a global event bus, for folks who
// want global "pubsub" in a convenient place.
_.extend(Backbone, Events);
// Create the default Backbone.history.
Backbone.history = new History();
return Backbone;
});
...@@ -12,104 +12,81 @@ button { ...@@ -12,104 +12,81 @@ button {
font-size: 100%; font-size: 100%;
vertical-align: baseline; vertical-align: baseline;
font-family: inherit; font-family: inherit;
font-weight: inherit;
color: inherit; color: inherit;
-webkit-appearance: none; -webkit-appearance: none;
-ms-appearance: none; -ms-appearance: none;
-o-appearance: none;
appearance: none; appearance: none;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
font-smoothing: antialiased;
} }
body { body {
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif; font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
line-height: 1.4em; line-height: 1.4em;
background: #eaeaea url('bg.png'); background: #f5f5f5;
color: #4d4d4d; color: #4d4d4d;
width: 550px; min-width: 230px;
max-width: 550px;
margin: 0 auto; margin: 0 auto;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased; -moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased; -ms-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
font-smoothing: antialiased; font-smoothing: antialiased;
font-weight: 300;
} }
button, button,
input[type="checkbox"] { input[type="checkbox"] {
outline: none; outline: none;
}
.hidden {
display: none;
} }
#todoapp { #todoapp {
background: #fff; background: #fff;
background: rgba(255, 255, 255, 0.9);
margin: 130px 0 40px 0; margin: 130px 0 40px 0;
border: 1px solid #ccc;
position: relative; position: relative;
border-top-left-radius: 2px; box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
border-top-right-radius: 2px; 0 25px 50px 0 rgba(0, 0, 0, 0.1);
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.2),
0 25px 50px 0 rgba(0, 0, 0, 0.15);
}
#todoapp:before {
content: '';
border-left: 1px solid #f5d6d6;
border-right: 1px solid #f5d6d6;
width: 2px;
position: absolute;
top: 0;
left: 40px;
height: 100%;
} }
#todoapp input::-webkit-input-placeholder { #todoapp input::-webkit-input-placeholder {
font-style: italic; font-style: italic;
font-weight: 300;
color: #e6e6e6;
} }
#todoapp input::-moz-placeholder { #todoapp input::-moz-placeholder {
font-style: italic; font-style: italic;
color: #a9a9a9; font-weight: 300;
color: #e6e6e6;
}
#todoapp input::input-placeholder {
font-style: italic;
font-weight: 300;
color: #e6e6e6;
} }
#todoapp h1 { #todoapp h1 {
position: absolute; position: absolute;
top: -120px; top: -155px;
width: 100%; width: 100%;
font-size: 70px; font-size: 100px;
font-weight: bold; font-weight: 100;
text-align: center; text-align: center;
color: #b3b3b3; color: rgba(175, 47, 47, 0.15);
color: rgba(255, 255, 255, 0.3);
text-shadow: -1px -1px rgba(0, 0, 0, 0.2);
-webkit-text-rendering: optimizeLegibility; -webkit-text-rendering: optimizeLegibility;
-moz-text-rendering: optimizeLegibility; -moz-text-rendering: optimizeLegibility;
-ms-text-rendering: optimizeLegibility; -ms-text-rendering: optimizeLegibility;
-o-text-rendering: optimizeLegibility;
text-rendering: optimizeLegibility; text-rendering: optimizeLegibility;
} }
#header {
padding-top: 15px;
border-radius: inherit;
}
#header:before {
content: '';
position: absolute;
top: 0;
right: 0;
left: 0;
height: 15px;
z-index: 2;
border-bottom: 1px solid #6c615c;
background: #8d7d77;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(132, 110, 100, 0.8)),to(rgba(101, 84, 76, 0.8)));
background: -webkit-linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8));
background: linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670');
border-top-left-radius: 1px;
border-top-right-radius: 1px;
}
#new-todo, #new-todo,
.edit { .edit {
position: relative; position: relative;
...@@ -117,6 +94,7 @@ input[type="checkbox"] { ...@@ -117,6 +94,7 @@ input[type="checkbox"] {
width: 100%; width: 100%;
font-size: 24px; font-size: 24px;
font-family: inherit; font-family: inherit;
font-weight: inherit;
line-height: 1.4em; line-height: 1.4em;
border: 0; border: 0;
outline: none; outline: none;
...@@ -124,29 +102,25 @@ input[type="checkbox"] { ...@@ -124,29 +102,25 @@ input[type="checkbox"] {
padding: 6px; padding: 6px;
border: 1px solid #999; border: 1px solid #999;
box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2); box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
-moz-box-sizing: border-box;
-ms-box-sizing: border-box; -ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased; -moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased; -ms-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
font-smoothing: antialiased; font-smoothing: antialiased;
} }
#new-todo { #new-todo {
padding: 16px 16px 16px 60px; padding: 16px 16px 16px 60px;
border: none; border: none;
background: rgba(0, 0, 0, 0.02); background: rgba(0, 0, 0, 0.003);
z-index: 2; box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
box-shadow: none;
} }
#main { #main {
position: relative; position: relative;
z-index: 2; z-index: 2;
border-top: 1px dotted #adadad; border-top: 1px solid #e6e6e6;
} }
label[for='toggle-all'] { label[for='toggle-all'] {
...@@ -155,19 +129,19 @@ label[for='toggle-all'] { ...@@ -155,19 +129,19 @@ label[for='toggle-all'] {
#toggle-all { #toggle-all {
position: absolute; position: absolute;
top: -42px; top: -55px;
left: -4px; left: -12px;
width: 40px; width: 60px;
height: 34px;
text-align: center; text-align: center;
/* Mobile Safari */ border: none; /* Mobile Safari */
border: none;
} }
#toggle-all:before { #toggle-all:before {
content: '»'; content: '';
font-size: 28px; font-size: 22px;
color: #d9d9d9; color: #e6e6e6;
padding: 0 25px 7px; padding: 10px 27px 10px 27px;
} }
#toggle-all:checked:before { #toggle-all:checked:before {
...@@ -183,7 +157,7 @@ label[for='toggle-all'] { ...@@ -183,7 +157,7 @@ label[for='toggle-all'] {
#todo-list li { #todo-list li {
position: relative; position: relative;
font-size: 24px; font-size: 24px;
border-bottom: 1px dotted #ccc; border-bottom: 1px solid #ededed;
} }
#todo-list li:last-child { #todo-list li:last-child {
...@@ -215,28 +189,18 @@ label[for='toggle-all'] { ...@@ -215,28 +189,18 @@ label[for='toggle-all'] {
top: 0; top: 0;
bottom: 0; bottom: 0;
margin: auto 0; margin: auto 0;
/* Mobile Safari */ border: none; /* Mobile Safari */
border: none;
-webkit-appearance: none; -webkit-appearance: none;
-ms-appearance: none; -ms-appearance: none;
-o-appearance: none;
appearance: none; appearance: none;
} }
#todo-list li .toggle:after { #todo-list li .toggle:after {
content: '✔'; content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="#ededed" stroke-width="3"/></svg>');
/* 40 + a couple of pixels visual adjustment */
line-height: 43px;
font-size: 20px;
color: #d9d9d9;
text-shadow: 0 -1px 0 #bfbfbf;
} }
#todo-list li .toggle:checked:after { #todo-list li .toggle:checked:after {
color: #85ada7; content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="#bddad5" stroke-width="3"/><path fill="#5dc2af" d="M72 25L42 71 27 56l-4 4 20 20 34-52z"/></svg>');
text-shadow: 0 1px 0 #669991;
bottom: 1px;
position: relative;
} }
#todo-list li label { #todo-list li label {
...@@ -246,12 +210,11 @@ label[for='toggle-all'] { ...@@ -246,12 +210,11 @@ label[for='toggle-all'] {
margin-left: 45px; margin-left: 45px;
display: block; display: block;
line-height: 1.2; line-height: 1.2;
-webkit-transition: color 0.4s;
transition: color 0.4s; transition: color 0.4s;
} }
#todo-list li.completed label { #todo-list li.completed label {
color: #a9a9a9; color: #d9d9d9;
text-decoration: line-through; text-decoration: line-through;
} }
...@@ -264,21 +227,18 @@ label[for='toggle-all'] { ...@@ -264,21 +227,18 @@ label[for='toggle-all'] {
width: 40px; width: 40px;
height: 40px; height: 40px;
margin: auto 0; margin: auto 0;
font-size: 22px; font-size: 30px;
color: #a88a8a; color: #cc9a9a;
-webkit-transition: all 0.2s; margin-bottom: 11px;
transition: all 0.2s; transition: color 0.2s ease-out;
} }
#todo-list li .destroy:hover { #todo-list li .destroy:hover {
text-shadow: 0 0 1px #000, color: #af5b5e;
0 0 10px rgba(199, 107, 107, 0.8);
-webkit-transform: scale(1.3);
transform: scale(1.3);
} }
#todo-list li .destroy:after { #todo-list li .destroy:after {
content: ''; content: '×';
} }
#todo-list li:hover .destroy { #todo-list li:hover .destroy {
...@@ -295,29 +255,25 @@ label[for='toggle-all'] { ...@@ -295,29 +255,25 @@ label[for='toggle-all'] {
#footer { #footer {
color: #777; color: #777;
padding: 0 15px; padding: 10px 15px;
position: absolute;
right: 0;
bottom: -31px;
left: 0;
height: 20px; height: 20px;
z-index: 1;
text-align: center; text-align: center;
border-top: 1px solid #e6e6e6;
} }
#footer:before { #footer:before {
content: ''; content: '';
position: absolute; position: absolute;
right: 0; right: 0;
bottom: 31px; bottom: 0;
left: 0; left: 0;
height: 50px; height: 50px;
z-index: -1; overflow: hidden;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
0 6px 0 -3px rgba(255, 255, 255, 0.8), 0 8px 0 -3px #f6f6f6,
0 7px 1px -3px rgba(0, 0, 0, 0.3), 0 9px 1px -3px rgba(0, 0, 0, 0.2),
0 43px 0 -6px rgba(255, 255, 255, 0.8), 0 16px 0 -6px #f6f6f6,
0 44px 2px -6px rgba(0, 0, 0, 0.2); 0 17px 2px -6px rgba(0, 0, 0, 0.2);
} }
#todo-count { #todo-count {
...@@ -325,6 +281,10 @@ label[for='toggle-all'] { ...@@ -325,6 +281,10 @@ label[for='toggle-all'] {
text-align: left; text-align: left;
} }
#todo-count strong {
font-weight: 300;
}
#filters { #filters {
margin: 0; margin: 0;
padding: 0; padding: 0;
...@@ -339,49 +299,72 @@ label[for='toggle-all'] { ...@@ -339,49 +299,72 @@ label[for='toggle-all'] {
} }
#filters li a { #filters li a {
color: #83756f; color: inherit;
margin: 2px; margin: 3px;
padding: 3px 7px;
text-decoration: none; text-decoration: none;
border: 1px solid transparent;
border-radius: 3px;
}
#filters li a.selected,
#filters li a:hover {
border-color: rgba(175, 47, 47, 0.1);
} }
#filters li a.selected { #filters li a.selected {
font-weight: bold; border-color: rgba(175, 47, 47, 0.2);
} }
#clear-completed { #clear-completed,
html #clear-completed:active {
float: right; float: right;
position: relative; position: relative;
line-height: 20px; line-height: 20px;
text-decoration: none; text-decoration: none;
background: rgba(0, 0, 0, 0.1); cursor: pointer;
font-size: 11px; visibility: hidden;
padding: 0 10px; position: relative;
border-radius: 3px; }
box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.2);
#clear-completed::after {
visibility: visible;
content: 'Clear completed';
position: absolute;
right: 0;
white-space: nowrap;
} }
#clear-completed:hover { #clear-completed:hover::after {
background: rgba(0, 0, 0, 0.15); text-decoration: underline;
box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.3);
} }
#info { #info {
margin: 65px auto 0; margin: 65px auto 0;
color: #a6a6a6; color: #bfbfbf;
font-size: 12px; font-size: 10px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
text-align: center; text-align: center;
} }
#info p {
line-height: 1;
}
#info a { #info a {
color: inherit; color: inherit;
text-decoration: none;
font-weight: 400;
}
#info a:hover {
text-decoration: underline;
} }
/* /*
Hack to remove background from Mobile Safari. Hack to remove background from Mobile Safari.
Can't use it globally since it destroys checkboxes in Firefox and Opera Can't use it globally since it destroys checkboxes in Firefox
*/ */
@media screen and (-webkit-min-device-pixel-ratio:0) { @media screen and (-webkit-min-device-pixel-ratio:0) {
#toggle-all, #toggle-all,
#todo-list li .toggle { #todo-list li .toggle {
...@@ -393,10 +376,6 @@ label[for='toggle-all'] { ...@@ -393,10 +376,6 @@ label[for='toggle-all'] {
} }
#toggle-all { #toggle-all {
top: -56px;
left: -15px;
width: 65px;
height: 41px;
-webkit-transform: rotate(90deg); -webkit-transform: rotate(90deg);
transform: rotate(90deg); transform: rotate(90deg);
-webkit-appearance: none; -webkit-appearance: none;
...@@ -404,151 +383,12 @@ label[for='toggle-all'] { ...@@ -404,151 +383,12 @@ label[for='toggle-all'] {
} }
} }
.hidden { @media (max-width: 430px) {
display: none; #footer {
} height: 50px;
hr {
margin: 20px 0;
border: 0;
border-top: 1px dashed #C5C5C5;
border-bottom: 1px dashed #F7F7F7;
}
.learn a {
font-weight: normal;
text-decoration: none;
color: #b83f45;
}
.learn a:hover {
text-decoration: underline;
color: #787e7e;
}
.learn h3,
.learn h4,
.learn h5 {
margin: 10px 0;
font-weight: 500;
line-height: 1.2;
color: #000;
}
.learn h3 {
font-size: 24px;
}
.learn h4 {
font-size: 18px;
}
.learn h5 {
margin-bottom: 0;
font-size: 14px;
}
.learn ul {
padding: 0;
margin: 0 0 30px 25px;
}
.learn li {
line-height: 20px;
}
.learn p {
font-size: 15px;
font-weight: 300;
line-height: 1.3;
margin-top: 0;
margin-bottom: 0;
}
.quote {
border: none;
margin: 20px 0 60px 0;
}
.quote p {
font-style: italic;
}
.quote p:before {
content: '“';
font-size: 50px;
opacity: .15;
position: absolute;
top: -20px;
left: 3px;
}
.quote p:after {
content: '”';
font-size: 50px;
opacity: .15;
position: absolute;
bottom: -42px;
right: 3px;
}
.quote footer {
position: absolute;
bottom: -40px;
right: 0;
}
.quote footer img {
border-radius: 3px;
}
.quote footer a {
margin-left: 5px;
vertical-align: middle;
}
.speech-bubble {
position: relative;
padding: 10px;
background: rgba(0, 0, 0, .04);
border-radius: 5px;
}
.speech-bubble:after {
content: '';
position: absolute;
top: 100%;
right: 30px;
border: 13px solid transparent;
border-top-color: rgba(0, 0, 0, .04);
}
.learn-bar > .learn {
position: absolute;
width: 272px;
top: 8px;
left: -300px;
padding: 10px;
border-radius: 5px;
background-color: rgba(255, 255, 255, .6);
-webkit-transition-property: left;
transition-property: left;
-webkit-transition-duration: 500ms;
transition-duration: 500ms;
}
@media (min-width: 899px) {
.learn-bar {
width: auto;
margin: 0 0 0 300px;
}
.learn-bar > .learn {
left: 8px;
} }
.learn-bar #todoapp { #filters {
width: 550px; bottom: 10px;
margin: 130px auto 40px auto;
} }
} }
hr {
margin: 20px 0;
border: 0;
border-top: 1px dashed #c5c5c5;
border-bottom: 1px dashed #f7f7f7;
}
.learn a {
font-weight: normal;
text-decoration: none;
color: #b83f45;
}
.learn a:hover {
text-decoration: underline;
color: #787e7e;
}
.learn h3,
.learn h4,
.learn h5 {
margin: 10px 0;
font-weight: 500;
line-height: 1.2;
color: #000;
}
.learn h3 {
font-size: 24px;
}
.learn h4 {
font-size: 18px;
}
.learn h5 {
margin-bottom: 0;
font-size: 14px;
}
.learn ul {
padding: 0;
margin: 0 0 30px 25px;
}
.learn li {
line-height: 20px;
}
.learn p {
font-size: 15px;
font-weight: 300;
line-height: 1.3;
margin-top: 0;
margin-bottom: 0;
}
#issue-count {
display: none;
}
.quote {
border: none;
margin: 20px 0 60px 0;
}
.quote p {
font-style: italic;
}
.quote p:before {
content: '“';
font-size: 50px;
opacity: .15;
position: absolute;
top: -20px;
left: 3px;
}
.quote p:after {
content: '”';
font-size: 50px;
opacity: .15;
position: absolute;
bottom: -42px;
right: 3px;
}
.quote footer {
position: absolute;
bottom: -40px;
right: 0;
}
.quote footer img {
border-radius: 3px;
}
.quote footer a {
margin-left: 5px;
vertical-align: middle;
}
.speech-bubble {
position: relative;
padding: 10px;
background: rgba(0, 0, 0, .04);
border-radius: 5px;
}
.speech-bubble:after {
content: '';
position: absolute;
top: 100%;
right: 30px;
border: 13px solid transparent;
border-top-color: rgba(0, 0, 0, .04);
}
.learn-bar > .learn {
position: absolute;
width: 272px;
top: 8px;
left: -300px;
padding: 10px;
border-radius: 5px;
background-color: rgba(255, 255, 255, .6);
transition-property: left;
transition-duration: 500ms;
}
@media (min-width: 899px) {
.learn-bar {
width: auto;
padding-left: 300px;
}
.learn-bar > .learn {
left: 8px;
}
}
/* global _ */
(function () { (function () {
'use strict'; 'use strict';
/* jshint ignore:start */
// Underscore's Template Module // Underscore's Template Module
// Courtesy of underscorejs.org // Courtesy of underscorejs.org
var _ = (function (_) { var _ = (function (_) {
...@@ -114,6 +116,7 @@ ...@@ -114,6 +116,7 @@
if (location.hostname === 'todomvc.com') { if (location.hostname === 'todomvc.com') {
window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'));
} }
/* jshint ignore:end */
function redirect() { function redirect() {
if (location.hostname === 'tastejs.github.io') { if (location.hostname === 'tastejs.github.io') {
...@@ -175,13 +178,17 @@ ...@@ -175,13 +178,17 @@
if (learnJSON.backend) { if (learnJSON.backend) {
this.frameworkJSON = learnJSON.backend; this.frameworkJSON = learnJSON.backend;
this.frameworkJSON.issueLabel = framework;
this.append({ this.append({
backend: true backend: true
}); });
} else if (learnJSON[framework]) { } else if (learnJSON[framework]) {
this.frameworkJSON = learnJSON[framework]; this.frameworkJSON = learnJSON[framework];
this.frameworkJSON.issueLabel = framework;
this.append(); this.append();
} }
this.fetchIssueCount();
} }
Learn.prototype.append = function (opts) { Learn.prototype.append = function (opts) {
...@@ -212,6 +219,26 @@ ...@@ -212,6 +219,26 @@
document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); document.body.insertAdjacentHTML('afterBegin', aside.outerHTML);
}; };
Learn.prototype.fetchIssueCount = function () {
var issueLink = document.getElementById('issue-count-link');
if (issueLink) {
var url = issueLink.href.replace('https://github.com', 'https://api.github.com/repos');
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function (e) {
var parsedResponse = JSON.parse(e.target.responseText);
if (parsedResponse instanceof Array) {
var count = parsedResponse.length
if (count !== 0) {
issueLink.innerHTML = 'This app has ' + count + ' open issues';
document.getElementById('issue-count').style.display = 'inline';
}
}
};
xhr.send();
}
};
redirect(); redirect();
getFile('learn.json', Learn); getFile('learn.json', Learn);
})(); })();
{ {
"author": "Paul Miller (http://paulmillr.com/)", "private": true,
"name": "brunch-with-chaplin-todomvc",
"description": "Brunch with Chaplin TODOMVC app",
"version": "0.0.1",
"engines": {
"node": "0.8 || 0.9"
},
"scripts": {
"start": "brunch watch --server",
"test": "brunch test"
},
"dependencies": { "dependencies": {
"javascript-brunch": ">= 1.0 < 1.8", "chaplin": "^1.0.0",
"coffee-script-brunch": ">= 1.0 < 1.8", "exoskeleton": "^0.6.3",
"backbone.localstorage": "^1.1.16",
"backbone.nativeview": "^0.3.2",
"css-brunch": ">= 1.0 < 1.8", "todomvc-app-css": "^1.0.0",
"stylus-brunch": ">= 1.0 < 1.8", "todomvc-common": "^1.0.1",
"javascript-brunch": ">= 1.0 < 1.8",
"coffee-script-brunch": ">= 1.0 < 1.8",
"handlebars-brunch": ">= 1.0 < 1.8", "handlebars-brunch": ">= 1.0 < 1.8",
"uglify-js-brunch": ">= 1.0 < 1.8"
"uglify-js-brunch": ">= 1.0 < 1.8",
"clean-css-brunch": ">= 1.0 < 1.8"
},
"devDependencies": {
"chai": "~1.2.0",
"sinon": "~1.4.2",
"sinon-chai": "~2.1.2"
} }
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,8 +3,14 @@ ...@@ -3,8 +3,14 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Chaplin &amp; Brunch • TodoMVC</title> <title>Chaplin &amp; Brunch • TodoMVC</title>
<link rel="stylesheet" href="../bower_components/todomvc-common/base.css"> <link rel="stylesheet" href="../node_modules/todomvc-common/base.css">
<script src="../bower_components/todomvc-common/base.js"></script> <link rel="stylesheet" href="../node_modules/todomvc-app-css/index.css">
<script src="../node_modules/todomvc-common/base.js"></script>
<script src="../node_modules/exoskeleton/exoskeleton.js"></script>
<script src="../node_modules/backbone.nativeview/backbone.nativeview.js"></script>
<script src="../node_modules/backbone.localstorage/backbone.localStorage.js"></script>
<script src="vendor.js"></script>
<script src="../node_modules/chaplin/chaplin.js"></script>
<script src="app.js"></script> <script src="app.js"></script>
<script>require('initialize');</script> <script>require('initialize');</script>
</head> </head>
......
(function(/*! Brunch !*/) {
'use strict';
var globals = typeof window !== 'undefined' ? window : global;
if (typeof globals.require === 'function') return;
var modules = {};
var cache = {};
var has = function(object, name) {
return ({}).hasOwnProperty.call(object, name);
};
var expand = function(root, name) {
var results = [], parts, part;
if (/^\.\.?(\/|$)/.test(name)) {
parts = [root, name].join('/').split('/');
} else {
parts = name.split('/');
}
for (var i = 0, length = parts.length; i < length; i++) {
part = parts[i];
if (part === '..') {
results.pop();
} else if (part !== '.' && part !== '') {
results.push(part);
}
}
return results.join('/');
};
var dirname = function(path) {
return path.split('/').slice(0, -1).join('/');
};
var localRequire = function(path) {
return function(name) {
var dir = dirname(path);
var absolute = expand(dir, name);
return globals.require(absolute, path);
};
};
var initModule = function(name, definition) {
var module = {id: name, exports: {}};
cache[name] = module;
definition(module.exports, localRequire(name), module);
return module.exports;
};
var require = function(name, loaderPath) {
var path = expand(name, '.');
if (loaderPath == null) loaderPath = '/';
if (has(cache, path)) return cache[path].exports;
if (has(modules, path)) return initModule(path, modules[path]);
var dirIndex = expand(path, './index');
if (has(cache, dirIndex)) return cache[dirIndex].exports;
if (has(modules, dirIndex)) return initModule(dirIndex, modules[dirIndex]);
throw new Error('Cannot find module "' + name + '" from '+ '"' + loaderPath + '"');
};
var define = function(bundle, fn) {
if (typeof bundle === 'object') {
for (var key in bundle) {
if (has(bundle, key)) {
modules[key] = bundle[key];
}
}
} else {
modules[bundle] = fn;
}
};
var list = function() {
var result = [];
for (var item in modules) {
if (has(modules, item)) {
result.push(item);
}
}
return result;
};
globals.require = require;
globals.require.define = define;
globals.require.register = define;
globals.require.list = list;
globals.require.brunch = true;
})();
Backbone.View = Backbone.NativeView;
/*!
handlebars v1.3.0
Copyright (C) 2011 by Yehuda Katz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@license
*/
/* exported Handlebars */
var Handlebars = (function() {
// handlebars/safe-string.js
var __module3__ = (function() {
"use strict";
var __exports__;
// Build out our basic SafeString type
function SafeString(string) {
this.string = string;
}
SafeString.prototype.toString = function() {
return "" + this.string;
};
__exports__ = SafeString;
return __exports__;
})();
// handlebars/utils.js
var __module2__ = (function(__dependency1__) {
"use strict";
var __exports__ = {};
/*jshint -W004 */
var SafeString = __dependency1__;
var escape = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#x27;",
"`": "&#x60;"
};
var badChars = /[&<>"'`]/g;
var possible = /[&<>"'`]/;
function escapeChar(chr) {
return escape[chr] || "&amp;";
}
function extend(obj, value) {
for(var key in value) {
if(Object.prototype.hasOwnProperty.call(value, key)) {
obj[key] = value[key];
}
}
}
__exports__.extend = extend;var toString = Object.prototype.toString;
__exports__.toString = toString;
// Sourced from lodash
// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
var isFunction = function(value) {
return typeof value === 'function';
};
// fallback for older versions of Chrome and Safari
if (isFunction(/x/)) {
isFunction = function(value) {
return typeof value === 'function' && toString.call(value) === '[object Function]';
};
}
var isFunction;
__exports__.isFunction = isFunction;
var isArray = Array.isArray || function(value) {
return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
};
__exports__.isArray = isArray;
function escapeExpression(string) {
// don't escape SafeStrings, since they're already safe
if (string instanceof SafeString) {
return string.toString();
} else if (!string && string !== 0) {
return "";
}
// Force a string conversion as this will be done by the append regardless and
// the regex test will do this transparently behind the scenes, causing issues if
// an object's to string has escaped characters in it.
string = "" + string;
if(!possible.test(string)) { return string; }
return string.replace(badChars, escapeChar);
}
__exports__.escapeExpression = escapeExpression;function isEmpty(value) {
if (!value && value !== 0) {
return true;
} else if (isArray(value) && value.length === 0) {
return true;
} else {
return false;
}
}
__exports__.isEmpty = isEmpty;
return __exports__;
})(__module3__);
// handlebars/exception.js
var __module4__ = (function() {
"use strict";
var __exports__;
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
function Exception(message, node) {
var line;
if (node && node.firstLine) {
line = node.firstLine;
message += ' - ' + line + ':' + node.firstColumn;
}
var tmp = Error.prototype.constructor.call(this, message);
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
for (var idx = 0; idx < errorProps.length; idx++) {
this[errorProps[idx]] = tmp[errorProps[idx]];
}
if (line) {
this.lineNumber = line;
this.column = node.firstColumn;
}
}
Exception.prototype = new Error();
__exports__ = Exception;
return __exports__;
})();
// handlebars/base.js
var __module1__ = (function(__dependency1__, __dependency2__) {
"use strict";
var __exports__ = {};
var Utils = __dependency1__;
var Exception = __dependency2__;
var VERSION = "1.3.0";
__exports__.VERSION = VERSION;var COMPILER_REVISION = 4;
__exports__.COMPILER_REVISION = COMPILER_REVISION;
var REVISION_CHANGES = {
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
2: '== 1.0.0-rc.3',
3: '== 1.0.0-rc.4',
4: '>= 1.0.0'
};
__exports__.REVISION_CHANGES = REVISION_CHANGES;
var isArray = Utils.isArray,
isFunction = Utils.isFunction,
toString = Utils.toString,
objectType = '[object Object]';
function HandlebarsEnvironment(helpers, partials) {
this.helpers = helpers || {};
this.partials = partials || {};
registerDefaultHelpers(this);
}
__exports__.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = {
constructor: HandlebarsEnvironment,
logger: logger,
log: log,
registerHelper: function(name, fn, inverse) {
if (toString.call(name) === objectType) {
if (inverse || fn) { throw new Exception('Arg not supported with multiple helpers'); }
Utils.extend(this.helpers, name);
} else {
if (inverse) { fn.not = inverse; }
this.helpers[name] = fn;
}
},
registerPartial: function(name, str) {
if (toString.call(name) === objectType) {
Utils.extend(this.partials, name);
} else {
this.partials[name] = str;
}
}
};
function registerDefaultHelpers(instance) {
instance.registerHelper('helperMissing', function(arg) {
if(arguments.length === 2) {
return undefined;
} else {
throw new Exception("Missing helper: '" + arg + "'");
}
});
instance.registerHelper('blockHelperMissing', function(context, options) {
var inverse = options.inverse || function() {}, fn = options.fn;
if (isFunction(context)) { context = context.call(this); }
if(context === true) {
return fn(this);
} else if(context === false || context == null) {
return inverse(this);
} else if (isArray(context)) {
if(context.length > 0) {
return instance.helpers.each(context, options);
} else {
return inverse(this);
}
} else {
return fn(context);
}
});
instance.registerHelper('each', function(context, options) {
var fn = options.fn, inverse = options.inverse;
var i = 0, ret = "", data;
if (isFunction(context)) { context = context.call(this); }
if (options.data) {
data = createFrame(options.data);
}
if(context && typeof context === 'object') {
if (isArray(context)) {
for(var j = context.length; i<j; i++) {
if (data) {
data.index = i;
data.first = (i === 0);
data.last = (i === (context.length-1));
}
ret = ret + fn(context[i], { data: data });
}
} else {
for(var key in context) {
if(context.hasOwnProperty(key)) {
if(data) {
data.key = key;
data.index = i;
data.first = (i === 0);
}
ret = ret + fn(context[key], {data: data});
i++;
}
}
}
}
if(i === 0){
ret = inverse(this);
}
return ret;
});
instance.registerHelper('if', function(conditional, options) {
if (isFunction(conditional)) { conditional = conditional.call(this); }
// Default behavior is to render the positive path if the value is truthy and not empty.
// The `includeZero` option may be set to treat the condtional as purely not empty based on the
// behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
if ((!options.hash.includeZero && !conditional) || Utils.isEmpty(conditional)) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
instance.registerHelper('unless', function(conditional, options) {
return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});
});
instance.registerHelper('with', function(context, options) {
if (isFunction(context)) { context = context.call(this); }
if (!Utils.isEmpty(context)) return options.fn(context);
});
instance.registerHelper('log', function(context, options) {
var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
instance.log(level, context);
});
}
var logger = {
methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },
// State enum
DEBUG: 0,
INFO: 1,
WARN: 2,
ERROR: 3,
level: 3,
// can be overridden in the host environment
log: function(level, obj) {
if (logger.level <= level) {
var method = logger.methodMap[level];
if (typeof console !== 'undefined' && console[method]) {
console[method].call(console, obj);
}
}
}
};
__exports__.logger = logger;
function log(level, obj) { logger.log(level, obj); }
__exports__.log = log;var createFrame = function(object) {
var obj = {};
Utils.extend(obj, object);
return obj;
};
__exports__.createFrame = createFrame;
return __exports__;
})(__module2__, __module4__);
// handlebars/runtime.js
var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
"use strict";
var __exports__ = {};
var Utils = __dependency1__;
var Exception = __dependency2__;
var COMPILER_REVISION = __dependency3__.COMPILER_REVISION;
var REVISION_CHANGES = __dependency3__.REVISION_CHANGES;
function checkRevision(compilerInfo) {
var compilerRevision = compilerInfo && compilerInfo[0] || 1,
currentRevision = COMPILER_REVISION;
if (compilerRevision !== currentRevision) {
if (compilerRevision < currentRevision) {
var runtimeVersions = REVISION_CHANGES[currentRevision],
compilerVersions = REVISION_CHANGES[compilerRevision];
throw new Exception("Template was precompiled with an older version of Handlebars than the current runtime. "+
"Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").");
} else {
// Use the embedded version info since the runtime doesn't know about this revision yet
throw new Exception("Template was precompiled with a newer version of Handlebars than the current runtime. "+
"Please update your runtime to a newer version ("+compilerInfo[1]+").");
}
}
}
__exports__.checkRevision = checkRevision;// TODO: Remove this line and break up compilePartial
function template(templateSpec, env) {
if (!env) {
throw new Exception("No environment passed to template");
}
// Note: Using env.VM references rather than local var references throughout this section to allow
// for external users to override these as psuedo-supported APIs.
var invokePartialWrapper = function(partial, name, context, helpers, partials, data) {
var result = env.VM.invokePartial.apply(this, arguments);
if (result != null) { return result; }
if (env.compile) {
var options = { helpers: helpers, partials: partials, data: data };
partials[name] = env.compile(partial, { data: data !== undefined }, env);
return partials[name](context, options);
} else {
throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
}
};
// Just add water
var container = {
escapeExpression: Utils.escapeExpression,
invokePartial: invokePartialWrapper,
programs: [],
program: function(i, fn, data) {
var programWrapper = this.programs[i];
if(data) {
programWrapper = program(i, fn, data);
} else if (!programWrapper) {
programWrapper = this.programs[i] = program(i, fn);
}
return programWrapper;
},
merge: function(param, common) {
var ret = param || common;
if (param && common && (param !== common)) {
ret = {};
Utils.extend(ret, common);
Utils.extend(ret, param);
}
return ret;
},
programWithDepth: env.VM.programWithDepth,
noop: env.VM.noop,
compilerInfo: null
};
return function(context, options) {
options = options || {};
var namespace = options.partial ? options : env,
helpers,
partials;
if (!options.partial) {
helpers = options.helpers;
partials = options.partials;
}
var result = templateSpec.call(
container,
namespace, context,
helpers,
partials,
options.data);
if (!options.partial) {
env.VM.checkRevision(container.compilerInfo);
}
return result;
};
}
__exports__.template = template;function programWithDepth(i, fn, data /*, $depth */) {
var args = Array.prototype.slice.call(arguments, 3);
var prog = function(context, options) {
options = options || {};
return fn.apply(this, [context, options.data || data].concat(args));
};
prog.program = i;
prog.depth = args.length;
return prog;
}
__exports__.programWithDepth = programWithDepth;function program(i, fn, data) {
var prog = function(context, options) {
options = options || {};
return fn(context, options.data || data);
};
prog.program = i;
prog.depth = 0;
return prog;
}
__exports__.program = program;function invokePartial(partial, name, context, helpers, partials, data) {
var options = { partial: true, helpers: helpers, partials: partials, data: data };
if(partial === undefined) {
throw new Exception("The partial " + name + " could not be found");
} else if(partial instanceof Function) {
return partial(context, options);
}
}
__exports__.invokePartial = invokePartial;function noop() { return ""; }
__exports__.noop = noop;
return __exports__;
})(__module2__, __module4__, __module1__);
// handlebars.runtime.js
var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) {
"use strict";
var __exports__;
/*globals Handlebars: true */
var base = __dependency1__;
// Each of these augment the Handlebars object. No need to setup here.
// (This is done to easily share code between commonjs and browse envs)
var SafeString = __dependency2__;
var Exception = __dependency3__;
var Utils = __dependency4__;
var runtime = __dependency5__;
// For compatibility and usage outside of module systems, make the Handlebars object a namespace
var create = function() {
var hb = new base.HandlebarsEnvironment();
Utils.extend(hb, base);
hb.SafeString = SafeString;
hb.Exception = Exception;
hb.Utils = Utils;
hb.VM = runtime;
hb.template = function(spec) {
return runtime.template(spec, hb);
};
return hb;
};
var Handlebars = create();
Handlebars.create = create;
__exports__ = Handlebars;
return __exports__;
})(__module1__, __module3__, __module4__, __module2__, __module5__);
return __module0__;
})();
//# sourceMappingURL=vendor.js.map
\ No newline at end of file
{"version":3,"sources":["vendor/vendor.js","node_modules/handlebars-brunch/node_modules/handlebars/dist/handlebars.runtime.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;ACDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"public/vendor.js","sourcesContent":["Backbone.View = Backbone.NativeView;\n","/*!\n\n handlebars v1.3.0\n\nCopyright (C) 2011 by Yehuda Katz\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n@license\n*/\n/* exported Handlebars */\nvar Handlebars = (function() {\n// handlebars/safe-string.js\nvar __module3__ = (function() {\n \"use strict\";\n var __exports__;\n // Build out our basic SafeString type\n function SafeString(string) {\n this.string = string;\n }\n\n SafeString.prototype.toString = function() {\n return \"\" + this.string;\n };\n\n __exports__ = SafeString;\n return __exports__;\n})();\n\n// handlebars/utils.js\nvar __module2__ = (function(__dependency1__) {\n \"use strict\";\n var __exports__ = {};\n /*jshint -W004 */\n var SafeString = __dependency1__;\n\n var escape = {\n \"&\": \"&amp;\",\n \"<\": \"&lt;\",\n \">\": \"&gt;\",\n '\"': \"&quot;\",\n \"'\": \"&#x27;\",\n \"`\": \"&#x60;\"\n };\n\n var badChars = /[&<>\"'`]/g;\n var possible = /[&<>\"'`]/;\n\n function escapeChar(chr) {\n return escape[chr] || \"&amp;\";\n }\n\n function extend(obj, value) {\n for(var key in value) {\n if(Object.prototype.hasOwnProperty.call(value, key)) {\n obj[key] = value[key];\n }\n }\n }\n\n __exports__.extend = extend;var toString = Object.prototype.toString;\n __exports__.toString = toString;\n // Sourced from lodash\n // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt\n var isFunction = function(value) {\n return typeof value === 'function';\n };\n // fallback for older versions of Chrome and Safari\n if (isFunction(/x/)) {\n isFunction = function(value) {\n return typeof value === 'function' && toString.call(value) === '[object Function]';\n };\n }\n var isFunction;\n __exports__.isFunction = isFunction;\n var isArray = Array.isArray || function(value) {\n return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;\n };\n __exports__.isArray = isArray;\n\n function escapeExpression(string) {\n // don't escape SafeStrings, since they're already safe\n if (string instanceof SafeString) {\n return string.toString();\n } else if (!string && string !== 0) {\n return \"\";\n }\n\n // Force a string conversion as this will be done by the append regardless and\n // the regex test will do this transparently behind the scenes, causing issues if\n // an object's to string has escaped characters in it.\n string = \"\" + string;\n\n if(!possible.test(string)) { return string; }\n return string.replace(badChars, escapeChar);\n }\n\n __exports__.escapeExpression = escapeExpression;function isEmpty(value) {\n if (!value && value !== 0) {\n return true;\n } else if (isArray(value) && value.length === 0) {\n return true;\n } else {\n return false;\n }\n }\n\n __exports__.isEmpty = isEmpty;\n return __exports__;\n})(__module3__);\n\n// handlebars/exception.js\nvar __module4__ = (function() {\n \"use strict\";\n var __exports__;\n\n var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];\n\n function Exception(message, node) {\n var line;\n if (node && node.firstLine) {\n line = node.firstLine;\n\n message += ' - ' + line + ':' + node.firstColumn;\n }\n\n var tmp = Error.prototype.constructor.call(this, message);\n\n // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.\n for (var idx = 0; idx < errorProps.length; idx++) {\n this[errorProps[idx]] = tmp[errorProps[idx]];\n }\n\n if (line) {\n this.lineNumber = line;\n this.column = node.firstColumn;\n }\n }\n\n Exception.prototype = new Error();\n\n __exports__ = Exception;\n return __exports__;\n})();\n\n// handlebars/base.js\nvar __module1__ = (function(__dependency1__, __dependency2__) {\n \"use strict\";\n var __exports__ = {};\n var Utils = __dependency1__;\n var Exception = __dependency2__;\n\n var VERSION = \"1.3.0\";\n __exports__.VERSION = VERSION;var COMPILER_REVISION = 4;\n __exports__.COMPILER_REVISION = COMPILER_REVISION;\n var REVISION_CHANGES = {\n 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it\n 2: '== 1.0.0-rc.3',\n 3: '== 1.0.0-rc.4',\n 4: '>= 1.0.0'\n };\n __exports__.REVISION_CHANGES = REVISION_CHANGES;\n var isArray = Utils.isArray,\n isFunction = Utils.isFunction,\n toString = Utils.toString,\n objectType = '[object Object]';\n\n function HandlebarsEnvironment(helpers, partials) {\n this.helpers = helpers || {};\n this.partials = partials || {};\n\n registerDefaultHelpers(this);\n }\n\n __exports__.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = {\n constructor: HandlebarsEnvironment,\n\n logger: logger,\n log: log,\n\n registerHelper: function(name, fn, inverse) {\n if (toString.call(name) === objectType) {\n if (inverse || fn) { throw new Exception('Arg not supported with multiple helpers'); }\n Utils.extend(this.helpers, name);\n } else {\n if (inverse) { fn.not = inverse; }\n this.helpers[name] = fn;\n }\n },\n\n registerPartial: function(name, str) {\n if (toString.call(name) === objectType) {\n Utils.extend(this.partials, name);\n } else {\n this.partials[name] = str;\n }\n }\n };\n\n function registerDefaultHelpers(instance) {\n instance.registerHelper('helperMissing', function(arg) {\n if(arguments.length === 2) {\n return undefined;\n } else {\n throw new Exception(\"Missing helper: '\" + arg + \"'\");\n }\n });\n\n instance.registerHelper('blockHelperMissing', function(context, options) {\n var inverse = options.inverse || function() {}, fn = options.fn;\n\n if (isFunction(context)) { context = context.call(this); }\n\n if(context === true) {\n return fn(this);\n } else if(context === false || context == null) {\n return inverse(this);\n } else if (isArray(context)) {\n if(context.length > 0) {\n return instance.helpers.each(context, options);\n } else {\n return inverse(this);\n }\n } else {\n return fn(context);\n }\n });\n\n instance.registerHelper('each', function(context, options) {\n var fn = options.fn, inverse = options.inverse;\n var i = 0, ret = \"\", data;\n\n if (isFunction(context)) { context = context.call(this); }\n\n if (options.data) {\n data = createFrame(options.data);\n }\n\n if(context && typeof context === 'object') {\n if (isArray(context)) {\n for(var j = context.length; i<j; i++) {\n if (data) {\n data.index = i;\n data.first = (i === 0);\n data.last = (i === (context.length-1));\n }\n ret = ret + fn(context[i], { data: data });\n }\n } else {\n for(var key in context) {\n if(context.hasOwnProperty(key)) {\n if(data) { \n data.key = key; \n data.index = i;\n data.first = (i === 0);\n }\n ret = ret + fn(context[key], {data: data});\n i++;\n }\n }\n }\n }\n\n if(i === 0){\n ret = inverse(this);\n }\n\n return ret;\n });\n\n instance.registerHelper('if', function(conditional, options) {\n if (isFunction(conditional)) { conditional = conditional.call(this); }\n\n // Default behavior is to render the positive path if the value is truthy and not empty.\n // The `includeZero` option may be set to treat the condtional as purely not empty based on the\n // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.\n if ((!options.hash.includeZero && !conditional) || Utils.isEmpty(conditional)) {\n return options.inverse(this);\n } else {\n return options.fn(this);\n }\n });\n\n instance.registerHelper('unless', function(conditional, options) {\n return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});\n });\n\n instance.registerHelper('with', function(context, options) {\n if (isFunction(context)) { context = context.call(this); }\n\n if (!Utils.isEmpty(context)) return options.fn(context);\n });\n\n instance.registerHelper('log', function(context, options) {\n var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;\n instance.log(level, context);\n });\n }\n\n var logger = {\n methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },\n\n // State enum\n DEBUG: 0,\n INFO: 1,\n WARN: 2,\n ERROR: 3,\n level: 3,\n\n // can be overridden in the host environment\n log: function(level, obj) {\n if (logger.level <= level) {\n var method = logger.methodMap[level];\n if (typeof console !== 'undefined' && console[method]) {\n console[method].call(console, obj);\n }\n }\n }\n };\n __exports__.logger = logger;\n function log(level, obj) { logger.log(level, obj); }\n\n __exports__.log = log;var createFrame = function(object) {\n var obj = {};\n Utils.extend(obj, object);\n return obj;\n };\n __exports__.createFrame = createFrame;\n return __exports__;\n})(__module2__, __module4__);\n\n// handlebars/runtime.js\nvar __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {\n \"use strict\";\n var __exports__ = {};\n var Utils = __dependency1__;\n var Exception = __dependency2__;\n var COMPILER_REVISION = __dependency3__.COMPILER_REVISION;\n var REVISION_CHANGES = __dependency3__.REVISION_CHANGES;\n\n function checkRevision(compilerInfo) {\n var compilerRevision = compilerInfo && compilerInfo[0] || 1,\n currentRevision = COMPILER_REVISION;\n\n if (compilerRevision !== currentRevision) {\n if (compilerRevision < currentRevision) {\n var runtimeVersions = REVISION_CHANGES[currentRevision],\n compilerVersions = REVISION_CHANGES[compilerRevision];\n throw new Exception(\"Template was precompiled with an older version of Handlebars than the current runtime. \"+\n \"Please update your precompiler to a newer version (\"+runtimeVersions+\") or downgrade your runtime to an older version (\"+compilerVersions+\").\");\n } else {\n // Use the embedded version info since the runtime doesn't know about this revision yet\n throw new Exception(\"Template was precompiled with a newer version of Handlebars than the current runtime. \"+\n \"Please update your runtime to a newer version (\"+compilerInfo[1]+\").\");\n }\n }\n }\n\n __exports__.checkRevision = checkRevision;// TODO: Remove this line and break up compilePartial\n\n function template(templateSpec, env) {\n if (!env) {\n throw new Exception(\"No environment passed to template\");\n }\n\n // Note: Using env.VM references rather than local var references throughout this section to allow\n // for external users to override these as psuedo-supported APIs.\n var invokePartialWrapper = function(partial, name, context, helpers, partials, data) {\n var result = env.VM.invokePartial.apply(this, arguments);\n if (result != null) { return result; }\n\n if (env.compile) {\n var options = { helpers: helpers, partials: partials, data: data };\n partials[name] = env.compile(partial, { data: data !== undefined }, env);\n return partials[name](context, options);\n } else {\n throw new Exception(\"The partial \" + name + \" could not be compiled when running in runtime-only mode\");\n }\n };\n\n // Just add water\n var container = {\n escapeExpression: Utils.escapeExpression,\n invokePartial: invokePartialWrapper,\n programs: [],\n program: function(i, fn, data) {\n var programWrapper = this.programs[i];\n if(data) {\n programWrapper = program(i, fn, data);\n } else if (!programWrapper) {\n programWrapper = this.programs[i] = program(i, fn);\n }\n return programWrapper;\n },\n merge: function(param, common) {\n var ret = param || common;\n\n if (param && common && (param !== common)) {\n ret = {};\n Utils.extend(ret, common);\n Utils.extend(ret, param);\n }\n return ret;\n },\n programWithDepth: env.VM.programWithDepth,\n noop: env.VM.noop,\n compilerInfo: null\n };\n\n return function(context, options) {\n options = options || {};\n var namespace = options.partial ? options : env,\n helpers,\n partials;\n\n if (!options.partial) {\n helpers = options.helpers;\n partials = options.partials;\n }\n var result = templateSpec.call(\n container,\n namespace, context,\n helpers,\n partials,\n options.data);\n\n if (!options.partial) {\n env.VM.checkRevision(container.compilerInfo);\n }\n\n return result;\n };\n }\n\n __exports__.template = template;function programWithDepth(i, fn, data /*, $depth */) {\n var args = Array.prototype.slice.call(arguments, 3);\n\n var prog = function(context, options) {\n options = options || {};\n\n return fn.apply(this, [context, options.data || data].concat(args));\n };\n prog.program = i;\n prog.depth = args.length;\n return prog;\n }\n\n __exports__.programWithDepth = programWithDepth;function program(i, fn, data) {\n var prog = function(context, options) {\n options = options || {};\n\n return fn(context, options.data || data);\n };\n prog.program = i;\n prog.depth = 0;\n return prog;\n }\n\n __exports__.program = program;function invokePartial(partial, name, context, helpers, partials, data) {\n var options = { partial: true, helpers: helpers, partials: partials, data: data };\n\n if(partial === undefined) {\n throw new Exception(\"The partial \" + name + \" could not be found\");\n } else if(partial instanceof Function) {\n return partial(context, options);\n }\n }\n\n __exports__.invokePartial = invokePartial;function noop() { return \"\"; }\n\n __exports__.noop = noop;\n return __exports__;\n})(__module2__, __module4__, __module1__);\n\n// handlebars.runtime.js\nvar __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) {\n \"use strict\";\n var __exports__;\n /*globals Handlebars: true */\n var base = __dependency1__;\n\n // Each of these augment the Handlebars object. No need to setup here.\n // (This is done to easily share code between commonjs and browse envs)\n var SafeString = __dependency2__;\n var Exception = __dependency3__;\n var Utils = __dependency4__;\n var runtime = __dependency5__;\n\n // For compatibility and usage outside of module systems, make the Handlebars object a namespace\n var create = function() {\n var hb = new base.HandlebarsEnvironment();\n\n Utils.extend(hb, base);\n hb.SafeString = SafeString;\n hb.Exception = Exception;\n hb.Utils = Utils;\n\n hb.VM = runtime;\n hb.template = function(spec) {\n return runtime.template(spec, hb);\n };\n\n return hb;\n };\n\n var Handlebars = create();\n Handlebars.create = create;\n\n __exports__ = Handlebars;\n return __exports__;\n})(__module1__, __module3__, __module4__, __module2__, __module5__);\n\n return __module0__;\n})();\n"]}
\ No newline at end of file
Backbone.View = Backbone.NativeView;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment