Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
c637306d
Commit
c637306d
authored
May 11, 2015
by
Arthur Verschaeve
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1291 from tastejs/sjs/fix-marionette
Fix Marionette Issues
parents
1c2abb79
6e298ea5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
48 deletions
+34
-48
examples/backbone_marionette/css/app.css
examples/backbone_marionette/css/app.css
+0
-6
examples/backbone_marionette/js/TodoMVC.Layout.js
examples/backbone_marionette/js/TodoMVC.Layout.js
+3
-3
examples/backbone_marionette/js/TodoMVC.TodoList.Views.js
examples/backbone_marionette/js/TodoMVC.TodoList.Views.js
+12
-25
examples/backbone_marionette/js/TodoMVC.TodoList.js
examples/backbone_marionette/js/TodoMVC.TodoList.js
+9
-4
examples/backbone_marionette/js/TodoMVC.js
examples/backbone_marionette/js/TodoMVC.js
+10
-10
No files found.
examples/backbone_marionette/css/app.css
View file @
c637306d
...
@@ -2,9 +2,3 @@
...
@@ -2,9 +2,3 @@
#todoapp
.filter-completed
#todo-list
.active
{
#todoapp
.filter-completed
#todo-list
.active
{
display
:
none
;
display
:
none
;
}
}
#main
,
#footer
{
display
:
none
;
}
examples/backbone_marionette/js/TodoMVC.Layout.js
View file @
c637306d
...
@@ -39,8 +39,8 @@ TodoMVC.module('Layout', function (Layout, App, Backbone) {
...
@@ -39,8 +39,8 @@ TodoMVC.module('Layout', function (Layout, App, Backbone) {
},
},
onInputKeypress
:
function
(
e
)
{
onInputKeypress
:
function
(
e
)
{
var
ENTER_KEY
=
13
,
var
ENTER_KEY
=
13
;
todoText
=
this
.
ui
.
input
.
val
().
trim
();
var
todoText
=
this
.
ui
.
input
.
val
().
trim
();
if
(
e
.
which
===
ENTER_KEY
&&
todoText
)
{
if
(
e
.
which
===
ENTER_KEY
&&
todoText
)
{
this
.
collection
.
create
({
this
.
collection
.
create
({
...
@@ -72,7 +72,7 @@ TodoMVC.module('Layout', function (Layout, App, Backbone) {
...
@@ -72,7 +72,7 @@ TodoMVC.module('Layout', function (Layout, App, Backbone) {
},
},
collectionEvents
:
{
collectionEvents
:
{
'
all
'
:
'
render
'
all
:
'
render
'
},
},
templateHelpers
:
{
templateHelpers
:
{
...
...
examples/backbone_marionette/js/TodoMVC.TodoList.Views.js
View file @
c637306d
...
@@ -10,6 +10,9 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
...
@@ -10,6 +10,9 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
Views
.
ItemView
=
Marionette
.
ItemView
.
extend
({
Views
.
ItemView
=
Marionette
.
ItemView
.
extend
({
tagName
:
'
li
'
,
tagName
:
'
li
'
,
template
:
'
#template-todoItemView
'
,
template
:
'
#template-todoItemView
'
,
className
:
function
()
{
return
this
.
model
.
get
(
'
completed
'
)
?
'
completed
'
:
'
active
'
;
},
ui
:
{
ui
:
{
edit
:
'
.edit
'
,
edit
:
'
.edit
'
,
...
@@ -27,17 +30,7 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
...
@@ -27,17 +30,7 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
},
},
modelEvents
:
{
modelEvents
:
{
'
change
'
:
'
render
'
change
:
'
render
'
},
onRender
:
function
()
{
this
.
$el
.
removeClass
(
'
active completed
'
);
if
(
this
.
model
.
get
(
'
completed
'
))
{
this
.
$el
.
addClass
(
'
completed
'
);
}
else
{
this
.
$el
.
addClass
(
'
active
'
);
}
},
},
deleteModel
:
function
()
{
deleteModel
:
function
()
{
...
@@ -65,7 +58,8 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
...
@@ -65,7 +58,8 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
},
},
onEditKeypress
:
function
(
e
)
{
onEditKeypress
:
function
(
e
)
{
var
ENTER_KEY
=
13
,
ESC_KEY
=
27
;
var
ENTER_KEY
=
13
;
var
ESC_KEY
=
27
;
if
(
e
.
which
===
ENTER_KEY
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
this
.
onEditFocusout
();
this
.
onEditFocusout
();
...
@@ -98,32 +92,25 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
...
@@ -98,32 +92,25 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
},
},
collectionEvents
:
{
collectionEvents
:
{
'
all
'
:
'
update
'
'
change:completed
'
:
'
render
'
,
all
:
'
setCheckAllState
'
},
},
initialize
:
function
()
{
initialize
:
function
()
{
this
.
listenTo
(
App
.
request
(
'
filterState
'
),
'
change:filter
'
,
this
.
render
,
this
);
this
.
listenTo
(
App
.
request
(
'
filterState
'
),
'
change:filter
'
,
this
.
render
,
this
);
},
},
addChild
:
function
(
child
)
{
filter
:
function
(
child
)
{
var
filteredOn
=
App
.
request
(
'
filterState
'
).
get
(
'
filter
'
);
var
filteredOn
=
App
.
request
(
'
filterState
'
).
get
(
'
filter
'
);
return
child
.
matchesFilter
(
filteredOn
);
if
(
child
.
matchesFilter
(
filteredOn
))
{
Backbone
.
Marionette
.
CompositeView
.
prototype
.
addChild
.
apply
(
this
,
arguments
);
}
},
},
onRender
:
function
()
{
setCheckAllState
:
function
()
{
this
.
update
();
},
update
:
function
()
{
function
reduceCompleted
(
left
,
right
)
{
function
reduceCompleted
(
left
,
right
)
{
return
left
&&
right
.
get
(
'
completed
'
);
return
left
&&
right
.
get
(
'
completed
'
);
}
}
var
allCompleted
=
this
.
collection
.
reduce
(
reduceCompleted
,
true
);
var
allCompleted
=
this
.
collection
.
reduce
(
reduceCompleted
,
true
);
this
.
ui
.
toggle
.
prop
(
'
checked
'
,
allCompleted
);
this
.
ui
.
toggle
.
prop
(
'
checked
'
,
allCompleted
);
this
.
$el
.
parent
().
toggle
(
!!
this
.
collection
.
length
);
this
.
$el
.
parent
().
toggle
(
!!
this
.
collection
.
length
);
},
},
...
@@ -132,7 +119,7 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
...
@@ -132,7 +119,7 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette) {
var
isChecked
=
e
.
currentTarget
.
checked
;
var
isChecked
=
e
.
currentTarget
.
checked
;
this
.
collection
.
each
(
function
(
todo
)
{
this
.
collection
.
each
(
function
(
todo
)
{
todo
.
save
({
'
completed
'
:
isChecked
});
todo
.
save
({
completed
:
isChecked
});
});
});
}
}
});
});
...
...
examples/backbone_marionette/js/TodoMVC.TodoList.js
View file @
c637306d
...
@@ -17,19 +17,24 @@ TodoMVC.module('TodoList', function (TodoList, App, Backbone, Marionette) {
...
@@ -17,19 +17,24 @@ TodoMVC.module('TodoList', function (TodoList, App, Backbone, Marionette) {
//
//
// Control the workflow and logic that exists at the application
// Control the workflow and logic that exists at the application
// level, above the implementation detail of views and models
// level, above the implementation detail of views and models
TodoList
.
Controller
=
Marionette
.
Controller
.
extend
({
TodoList
.
Controller
=
Marionette
.
Controller
.
extend
({
initialize
:
function
()
{
initialize
:
function
()
{
this
.
todoList
=
new
App
.
Todos
.
TodoList
();
this
.
todoList
=
new
App
.
Todos
.
TodoList
();
},
},
// Start the app by showing the appropriate views
// Start the app by showing the appropriate views
// and fetching the list of todo items, if there are any
// and fetching the list of todo items, if there are any
start
:
function
()
{
start
:
function
()
{
this
.
showHeader
(
this
.
todoList
);
this
.
showHeader
(
this
.
todoList
);
this
.
showFooter
(
this
.
todoList
);
this
.
showFooter
(
this
.
todoList
);
this
.
showTodoList
(
this
.
todoList
);
this
.
showTodoList
(
this
.
todoList
);
this
.
todoList
.
on
(
'
all
'
,
this
.
updateHiddenElements
,
this
);
this
.
todoList
.
fetch
();
this
.
todoList
.
fetch
();
},
},
updateHiddenElements
:
function
()
{
$
(
'
#main, #footer
'
).
toggle
(
!!
this
.
todoList
.
length
);
},
showHeader
:
function
(
todoList
)
{
showHeader
:
function
(
todoList
)
{
var
header
=
new
App
.
Layout
.
Header
({
var
header
=
new
App
.
Layout
.
Header
({
collection
:
todoList
collection
:
todoList
...
...
examples/backbone_marionette/js/TodoMVC.js
View file @
c637306d
...
@@ -4,23 +4,23 @@
...
@@ -4,23 +4,23 @@
// TodoMVC is global for developing in the console
// TodoMVC is global for developing in the console
// and functional testing.
// and functional testing.
var
App
=
Backbone
.
Marionette
.
Application
.
extend
({
var
App
=
Backbone
.
Marionette
.
Application
.
extend
({
setRootLayout
:
function
()
{
setRootLayout
:
function
()
{
this
.
root
=
new
TodoMVC
.
Layout
.
Root
();
this
.
root
=
new
TodoMVC
.
Layout
.
Root
();
}
}
});
});
window
.
TodoMVC
=
new
App
();
window
.
TodoMVC
=
new
App
();
(
function
()
{
(
function
()
{
var
filterState
=
new
Backbone
.
Model
({
var
filterState
=
new
Backbone
.
Model
({
filter
:
'
all
'
filter
:
'
all
'
});
});
TodoMVC
.
reqres
.
setHandler
(
'
filterState
'
,
function
()
{
TodoMVC
.
reqres
.
setHandler
(
'
filterState
'
,
function
()
{
return
filterState
;
return
filterState
;
});
});
})();
})();
TodoMVC
.
on
(
'
before:start
'
,
function
()
{
TodoMVC
.
on
(
'
before:start
'
,
function
()
{
TodoMVC
.
setRootLayout
();
TodoMVC
.
setRootLayout
();
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment