Commit 5a1a3f33 authored by Paul Miller's avatar Paul Miller

Switch Chaplin app to Exoskeleton.

parent 73e8fadd
...@@ -2,6 +2,7 @@ Application = require 'application' ...@@ -2,6 +2,7 @@ Application = require 'application'
routes = require 'routes' routes = require 'routes'
# Initialize the application on DOM ready event. # Initialize the application on DOM ready event.
$ -> document.addEventListener 'DOMContentLoaded', ->
new Application new Application
controllerSuffix: '-controller', pushState: false, routes: routes controllerSuffix: '-controller', pushState: false, routes: routes
, false
# Application-specific utilities
# ------------------------------
# Delegate to Chaplin’s utils module.
utils = Chaplin.utils.beget Chaplin.utils
Backbone.utils.extend utils,
toggle: (elem, visible) ->
elem.style.display = (if visible then '' else 'none')
# Prevent creating new properties and stuff.
Object.seal? utils
module.exports = utils
View = require './base/view' View = require './base/view'
utils = require 'lib/utils'
module.exports = class FooterView extends View module.exports = class FooterView extends View
autoRender: true autoRender: true
...@@ -16,23 +17,24 @@ module.exports = class FooterView extends View ...@@ -16,23 +17,24 @@ module.exports = class FooterView extends View
updateFilterer: (filterer) -> updateFilterer: (filterer) ->
filterer = '' if filterer is 'all' filterer = '' if filterer is 'all'
@$('#filters a') selector = "[href='#/#{filterer}']"
.removeClass('selected') cls = 'selected'
.filter("[href='#/#{filterer}']") @findAll('#filters a').forEach (link) =>
.addClass('selected') link.classList.remove cls
link.classList.add cls if Backbone.utils.matchesSelector link, selector
renderCounter: -> renderCounter: ->
total = @collection.length total = @collection.length
active = @collection.getActive().length active = @collection.getActive().length
completed = @collection.getCompleted().length completed = @collection.getCompleted().length
@$('#todo-count > strong').html active @find('#todo-count > strong').textContent = active
countDescription = (if active is 1 then 'item' else 'items') countDescription = (if active is 1 then 'item' else 'items')
@$('.todo-count-title').text countDescription @find('.todo-count-title').textContent = countDescription
@$('#completed-count').html "(#{completed})" @find('#completed-count').textContent = "(#{completed})"
@$('#clear-completed').toggle(completed > 0) utils.toggle @find('#clear-completed'), completed > 0
@$el.toggle(total > 0) utils.toggle @el, total > 0
clearCompleted: -> clearCompleted: ->
@publishEvent 'todos:clear' @publishEvent 'todos:clear'
...@@ -9,7 +9,7 @@ module.exports = class HeaderView extends View ...@@ -9,7 +9,7 @@ module.exports = class HeaderView extends View
createOnEnter: (event) -> createOnEnter: (event) ->
ENTER_KEY = 13 ENTER_KEY = 13
title = $(event.currentTarget).val().trim() title = event.delegateTarget.value.trim()
return if event.keyCode isnt ENTER_KEY or not title return if event.keyCode isnt ENTER_KEY or not title
@collection.create {title} @collection.create {title}
@$('#new-todo').val '' @find('#new-todo').value = ''
...@@ -4,8 +4,8 @@ module.exports = class TodoView extends View ...@@ -4,8 +4,8 @@ module.exports = class TodoView extends View
events: events:
'click .toggle': 'toggle' 'click .toggle': 'toggle'
'dblclick label': 'edit' 'dblclick label': 'edit'
'keypress .edit': 'save' 'keyup .edit': 'save'
'blur .edit': 'save' 'focusout .edit': 'save'
'click .destroy': 'clear' 'click .destroy': 'clear'
listen: listen:
...@@ -21,13 +21,13 @@ module.exports = class TodoView extends View ...@@ -21,13 +21,13 @@ module.exports = class TodoView extends View
@model.toggle().save() @model.toggle().save()
edit: -> edit: ->
@$el.addClass 'editing' @el.classList.add 'editing'
@$('.edit').focus() @find('.edit').focus()
save: (event) -> save: (event) ->
ENTER_KEY = 13 ENTER_KEY = 13
title = $(event.currentTarget).val().trim() title = event.delegateTarget.value.trim()
return @model.destroy() unless title return @model.destroy() unless title
return if event.type is 'keypress' and event.keyCode isnt ENTER_KEY return if event.type is 'keyup' and event.keyCode isnt ENTER_KEY
@model.save {title} @model.save {title}
@$el.removeClass 'editing' @el.classList.remove 'editing'
CollectionView = require './base/collection-view' CollectionView = require './base/collection-view'
TodoView = require './todo-view'
utils = require 'lib/utils'
module.exports = class TodosView extends CollectionView module.exports = class TodosView extends CollectionView
container: '#main' container: '#main'
events: events:
'click #toggle-all': 'toggleCompleted' 'click #toggle-all': 'toggleCompleted'
itemView: require './todo-view' itemView: TodoView
listSelector: '#todo-list' listSelector: '#todo-list'
listen: listen:
'all collection': 'renderCheckbox' 'all collection': 'renderCheckbox'
...@@ -16,11 +18,11 @@ module.exports = class TodosView extends CollectionView ...@@ -16,11 +18,11 @@ module.exports = class TodosView extends CollectionView
@renderCheckbox() @renderCheckbox()
renderCheckbox: -> renderCheckbox: ->
@$('#toggle-all').prop 'checked', @collection.allAreCompleted() @find('#toggle-all').setAttribute 'checked', @collection.allAreCompleted()
@$el.toggle(@collection.length isnt 0) utils.toggle @el, @collection.length isnt 0
toggleCompleted: (event) -> toggleCompleted: (event) ->
isChecked = event.currentTarget.checked isChecked = event.delegateTarget.checked
@collection.each (todo) -> todo.save completed: isChecked @collection.each (todo) -> todo.save completed: isChecked
clear: -> clear: ->
......
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.
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
> Chaplin is an architecture for JavaScript applications using the Backbone.js library. Chaplin addresses Backbone’s limitations by providing a lightweight and flexible structure that features well-proven design patterns and best practices. > Chaplin is an architecture for JavaScript applications using the Backbone.js library. Chaplin addresses Backbone’s limitations by providing a lightweight and flexible structure that features well-proven design patterns and best practices.
In this case, Backbone is replaced with [Exoskeleton](http://exosjs.com),
faster and leaner Backbone without dependencies on jQuery and underscore.
> _[Chaplin - chaplinjs.org](http://chaplinjs.org)_ > _[Chaplin - chaplinjs.org](http://chaplinjs.org)_
......
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