fix sd-value and filters.pluralize

This commit is contained in:
Evan You 2013-08-13 00:06:30 -04:00
parent cdfe391689
commit 4772f12e6d
4 changed files with 15 additions and 15 deletions

View File

@ -36,7 +36,7 @@
class="toggle"
type="checkbox"
sd-checked="todo.completed"
sd-on="change:updateCount"
sd-on="change:toggleTodo"
>
<label sd-text="todo.title" sd-on="dblclick:editTodo"></label>
<button class="destroy" sd-on="click:removeTodo"></button>

View File

@ -16,13 +16,13 @@ Seed.controller('todos', function (scope) {
}}
// dynamic context computed property using info from target scope
scope.filterTodo = {get: function (e) {
return filters[scope.filter](e.scope.completed)
scope.filterTodo = {get: function (ctx) {
return filters[scope.filter](ctx.scope.completed)
}}
// dynamic context computed property using info from target element
scope.checkFilter = {get: function (e) {
return scope.filter === e.el.textContent.toLowerCase()
scope.checkFilter = {get: function (ctx) {
return scope.filter === ctx.el.textContent.toLowerCase()
}}
// two-way computed property with both getter and setter
@ -31,10 +31,10 @@ Seed.controller('todos', function (scope) {
return scope.remaining === 0
},
set: function (value) {
scope.remaining = value ? 0 : scope.total
scope.todos.forEach(function (todo) {
todo.completed = value
})
scope.remaining = value ? 0 : scope.total
}
}
@ -55,7 +55,7 @@ Seed.controller('todos', function (scope) {
todoStorage.save(scope.todos)
}
scope.updateCount = function (e) {
scope.toggleTodo = function (e) {
scope.remaining += e.scope.completed ? -1 : 1
todoStorage.save(scope.todos)
}
@ -76,9 +76,7 @@ Seed.controller('todos', function (scope) {
scope.cancelEdit = function (e) {
e.scope.editing = false
setTimeout(function () {
e.scope.title = beforeEditCache
}, 0)
e.scope.title = beforeEditCache
}
scope.removeCompleted = function () {
@ -98,7 +96,7 @@ Seed.controller('todos', function (scope) {
function updateFilter () {
scope.filter = location.hash ? location.hash.slice(2) : 'all'
}
updateFilter()
window.addEventListener('hashchange', updateFilter)

View File

@ -30,7 +30,7 @@ module.exports = {
focus: function (value) {
var el = this.el
setTimeout(function () {
el[value ? 'focus' : 'blur']()
el[value ? 'focus' : 'focus']()
}, 0)
},
@ -53,14 +53,14 @@ module.exports = {
this.change = function () {
self.seed.scope[self.key] = el.value
}
el.addEventListener('change', this.change)
el.addEventListener('keyup', this.change)
},
update: function (value) {
this.el.value = value ? value : ''
},
unbind: function () {
if (this.oneway) return
this.el.removeEventListener('change', this.change)
this.el.removeEventListener('keyup', this.change)
}
},

View File

@ -30,7 +30,9 @@ module.exports = {
},
pluralize: function (value, args) {
return value === 1 ? args[0] : (args[1] || args[0] + 's')
return args.length > 1
? (args[value - 1] || args[args.length - 1])
: (args[value - 1] || args[0] + 's')
},
currency: function (value, args) {