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/
!bower_components/todomvc-common/
node_modules/chaplin/*
!node_modules/chaplin/chaplin.js
# NPM packages folder.
node_modules/
node_modules/exoskeleton/*
!node_modules/exoskeleton/exoskeleton.js
# Brunch folder for temporary files.
tmp/
node_modules/backbone.localstorage/*
!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 @@
<head>
<meta charset="utf-8">
<title>Chaplin &amp; Brunch • TodoMVC</title>
<link rel="stylesheet" href="../bower_components/todomvc-common/base.css">
<link rel="stylesheet" href="../bower_components/todomvc-common/base.js">
<link rel="stylesheet" href="../node_modules/todomvc-common/base.css">
<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>require('initialize');</script>
</head>
......
......@@ -14,7 +14,4 @@
<a href="#/completed">Completed</a>
</li>
</ul>
<button id="clear-completed">
Clear completed
<span id="completed-count"></span>
</button>
<button id="clear-completed">Clear completed <span id="completed-count"></span></button>
......@@ -14,6 +14,14 @@ module.exports = class TodoView extends View
template: require './templates/todo'
tagName: 'li'
render: ->
super
@toggleClass()
toggleClass: ->
isCompleted = @model.get('completed')
@el.classList.toggle 'completed', isCompleted
clear: ->
@model.destroy()
......@@ -22,7 +30,9 @@ module.exports = class TodoView extends View
edit: ->
@el.classList.add 'editing'
@find('.edit').focus()
input = @find('.edit')
input.focus()
input.value = input.value;
save: (event) ->
ENTER_KEY = 13
......
......@@ -18,7 +18,7 @@ module.exports = class TodosView extends CollectionView
@renderCheckbox()
renderCheckbox: ->
@find('#toggle-all').setAttribute 'checked', @collection.allAreCompleted()
@find('#toggle-all').checked = @collection.allAreCompleted()
utils.toggle @el, @collection.length isnt 0
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 =
# See http://brunch.readthedocs.org/en/latest/config.html for documentation.
files:
javascripts:
joinTo: 'app.js'
joinTo:
'app.js': /^app/
'vendor.js': /^vendor/
stylesheets:
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;
}));
This diff is collapsed.
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 () {
'use strict';
/* jshint ignore:start */
// Underscore's Template Module
// Courtesy of underscorejs.org
var _ = (function (_) {
......@@ -114,6 +116,7 @@
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'));
}
/* jshint ignore:end */
function redirect() {
if (location.hostname === 'tastejs.github.io') {
......@@ -175,13 +178,17 @@
if (learnJSON.backend) {
this.frameworkJSON = learnJSON.backend;
this.frameworkJSON.issueLabel = framework;
this.append({
backend: true
});
} else if (learnJSON[framework]) {
this.frameworkJSON = learnJSON[framework];
this.frameworkJSON.issueLabel = framework;
this.append();
}
this.fetchIssueCount();
}
Learn.prototype.append = function (opts) {
......@@ -212,6 +219,26 @@
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();
getFile('learn.json', Learn);
})();
{
"author": "Paul Miller (http://paulmillr.com/)",
"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"
},
"private": true,
"dependencies": {
"javascript-brunch": ">= 1.0 < 1.8",
"coffee-script-brunch": ">= 1.0 < 1.8",
"chaplin": "^1.0.0",
"exoskeleton": "^0.6.3",
"backbone.localstorage": "^1.1.16",
"backbone.nativeview": "^0.3.2",
"css-brunch": ">= 1.0 < 1.8",
"stylus-brunch": ">= 1.0 < 1.8",
"todomvc-app-css": "^1.0.0",
"todomvc-common": "^1.0.1",
"javascript-brunch": ">= 1.0 < 1.8",
"coffee-script-brunch": ">= 1.0 < 1.8",
"handlebars-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"
"uglify-js-brunch": ">= 1.0 < 1.8"
}
}
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,8 +3,14 @@
<head>
<meta charset="utf-8">
<title>Chaplin &amp; Brunch • TodoMVC</title>
<link rel="stylesheet" href="../bower_components/todomvc-common/base.css">
<script src="../bower_components/todomvc-common/base.js"></script>
<link rel="stylesheet" href="../node_modules/todomvc-common/base.css">
<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>require('initialize');</script>
</head>
......
This diff is collapsed.
This diff is collapsed.
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