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
Sven Franck
todomvc
Commits
a543e298
Commit
a543e298
authored
Mar 09, 2013
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flight - code style
parent
994d727a
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
264 additions
and
266 deletions
+264
-266
dependency-examples/flight/app/js/app.js
dependency-examples/flight/app/js/app.js
+3
-3
dependency-examples/flight/app/js/data/stats.js
dependency-examples/flight/app/js/data/stats.js
+3
-4
dependency-examples/flight/app/js/data/todos.js
dependency-examples/flight/app/js/data/todos.js
+101
-103
dependency-examples/flight/app/js/store.js
dependency-examples/flight/app/js/store.js
+0
-1
dependency-examples/flight/app/js/ui/main_selector.js
dependency-examples/flight/app/js/ui/main_selector.js
+2
-4
dependency-examples/flight/app/js/ui/new_item.js
dependency-examples/flight/app/js/ui/new_item.js
+2
-4
dependency-examples/flight/app/js/ui/stats.js
dependency-examples/flight/app/js/ui/stats.js
+3
-4
dependency-examples/flight/app/js/ui/todo_list.js
dependency-examples/flight/app/js/ui/todo_list.js
+12
-15
dependency-examples/flight/app/js/ui/toggle_all.js
dependency-examples/flight/app/js/ui/toggle_all.js
+3
-4
dependency-examples/flight/app/js/ui/with_filters.js
dependency-examples/flight/app/js/ui/with_filters.js
+7
-10
dependency-examples/flight/app/js/utils.js
dependency-examples/flight/app/js/utils.js
+37
-24
dependency-examples/flight/index.html
dependency-examples/flight/index.html
+20
-19
template/index.html
template/index.html
+71
-71
No files found.
dependency-examples/flight/app/js/app.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
./data/todos
'
,
'
./data/todos
'
,
'
./data/stats
'
,
'
./data/stats
'
,
...
@@ -25,11 +25,11 @@ define(
...
@@ -25,11 +25,11 @@ define(
StatsData
.
attachTo
(
document
);
StatsData
.
attachTo
(
document
);
TodosData
.
attachTo
(
document
);
TodosData
.
attachTo
(
document
);
NewItemUI
.
attachTo
(
'
#new-todo
'
);
NewItemUI
.
attachTo
(
'
#new-todo
'
);
MainSelectorUI
.
attachTo
(
"
#main
"
);
MainSelectorUI
.
attachTo
(
'
#main
'
);
StatsUI
.
attachTo
(
'
#footer
'
);
StatsUI
.
attachTo
(
'
#footer
'
);
ToggleAllUI
.
attachTo
(
'
#toggle-all
'
);
ToggleAllUI
.
attachTo
(
'
#toggle-all
'
);
TodoListUI
.
attachTo
(
'
#todo-list
'
);
TodoListUI
.
attachTo
(
'
#todo-list
'
);
}
}
;
return
{
return
{
initialize
:
initialize
initialize
:
initialize
...
...
dependency-examples/flight/app/js/data/stats.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
flight/component
'
,
'
flight/component
'
,
'
../store
'
'
../store
'
],
],
function
(
defineComponent
,
dataStore
)
{
function
(
defineComponent
,
dataStore
)
{
return
defineComponent
(
stats
);
return
defineComponent
(
stats
);
function
stats
()
{
function
stats
()
{
...
@@ -16,7 +15,7 @@ define(
...
@@ -16,7 +15,7 @@ define(
var
todos
=
dataStore
.
all
();
var
todos
=
dataStore
.
all
();
var
all
=
todos
.
length
;
var
all
=
todos
.
length
;
var
remaining
=
todos
.
reduce
(
function
(
memo
,
each
)
{
var
remaining
=
todos
.
reduce
(
function
(
memo
,
each
)
{
return
memo
+=
(
each
.
completed
)
?
0
:
1
;
return
memo
+=
each
.
completed
?
0
:
1
;
},
0
);
},
0
);
this
.
trigger
(
'
dataStatsCounted
'
,
{
this
.
trigger
(
'
dataStatsCounted
'
,
{
...
@@ -25,7 +24,7 @@ define(
...
@@ -25,7 +24,7 @@ define(
completed
:
all
-
remaining
,
completed
:
all
-
remaining
,
filter
:
localStorage
.
getItem
(
'
filter
'
)
||
''
filter
:
localStorage
.
getItem
(
'
filter
'
)
||
''
});
});
}
}
;
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
on
(
document
,
'
dataTodosLoaded
'
,
this
.
recount
);
this
.
on
(
document
,
'
dataTodosLoaded
'
,
this
.
recount
);
...
...
dependency-examples/flight/app/js/data/todos.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
flight/component
'
,
'
flight/component
'
,
'
../store
'
'
../store
'
],
],
function
(
defineComponent
,
dataStore
)
{
function
(
defineComponent
,
dataStore
)
{
return
defineComponent
(
todos
);
return
defineComponent
(
todos
);
function
todos
()
{
function
todos
()
{
var
filter
;
var
filter
;
this
.
add
=
function
(
e
,
data
)
{
this
.
add
=
function
(
e
,
data
)
{
...
@@ -22,13 +20,13 @@ define(
...
@@ -22,13 +20,13 @@ define(
});
});
this
.
trigger
(
'
dataTodoAdded
'
,
{
todo
:
todo
,
filter
:
filter
});
this
.
trigger
(
'
dataTodoAdded
'
,
{
todo
:
todo
,
filter
:
filter
});
}
};
this
.
remove
=
function
(
e
,
data
)
{
this
.
remove
=
function
(
e
,
data
)
{
var
todo
=
dataStore
.
destroy
(
data
.
id
);
var
todo
=
dataStore
.
destroy
(
data
.
id
);
this
.
trigger
(
'
dataTodoRemoved
'
,
todo
);
this
.
trigger
(
'
dataTodoRemoved
'
,
todo
);
}
};
this
.
load
=
function
(
e
,
data
)
{
this
.
load
=
function
(
e
,
data
)
{
var
todos
;
var
todos
;
...
@@ -36,11 +34,11 @@ define(
...
@@ -36,11 +34,11 @@ define(
filter
=
localStorage
.
getItem
(
'
filter
'
);
filter
=
localStorage
.
getItem
(
'
filter
'
);
todos
=
this
.
find
();
todos
=
this
.
find
();
this
.
trigger
(
'
dataTodosLoaded
'
,
{
todos
:
todos
});
this
.
trigger
(
'
dataTodosLoaded
'
,
{
todos
:
todos
});
}
};
this
.
update
=
function
(
e
,
data
)
{
this
.
update
=
function
(
e
,
data
)
{
dataStore
.
save
(
data
);
dataStore
.
save
(
data
);
}
};
this
.
toggleCompleted
=
function
(
e
,
data
)
{
this
.
toggleCompleted
=
function
(
e
,
data
)
{
var
eventType
;
var
eventType
;
...
@@ -49,15 +47,15 @@ define(
...
@@ -49,15 +47,15 @@ define(
todo
.
completed
=
!
todo
.
completed
;
todo
.
completed
=
!
todo
.
completed
;
dataStore
.
save
(
todo
);
dataStore
.
save
(
todo
);
eventType
=
(
filter
)
?
'
dataTodoRemoved
'
:
'
dataTodoToggled
'
;
eventType
=
filter
?
'
dataTodoRemoved
'
:
'
dataTodoToggled
'
;
this
.
trigger
(
eventType
,
todo
);
this
.
trigger
(
eventType
,
todo
);
}
};
this
.
toggleAllCompleted
=
function
(
e
,
data
)
{
this
.
toggleAllCompleted
=
function
(
e
,
data
)
{
dataStore
.
updateAll
({
completed
:
data
.
completed
});
dataStore
.
updateAll
({
completed
:
data
.
completed
});
this
.
trigger
(
'
dataTodoToggledAll
'
,
{
todos
:
this
.
find
(
filter
)
});
this
.
trigger
(
'
dataTodoToggledAll
'
,
{
todos
:
this
.
find
(
filter
)
});
}
};
this
.
filter
=
function
(
e
,
data
)
{
this
.
filter
=
function
(
e
,
data
)
{
var
todos
;
var
todos
;
...
@@ -67,7 +65,7 @@ define(
...
@@ -67,7 +65,7 @@ define(
todos
=
this
.
find
();
todos
=
this
.
find
();
this
.
trigger
(
'
dataTodosFiltered
'
,
{
todos
:
todos
});
this
.
trigger
(
'
dataTodosFiltered
'
,
{
todos
:
todos
});
}
};
this
.
find
=
function
()
{
this
.
find
=
function
()
{
var
todos
;
var
todos
;
...
@@ -82,7 +80,7 @@ define(
...
@@ -82,7 +80,7 @@ define(
}
}
return
todos
;
return
todos
;
}
};
this
.
clearCompleted
=
function
()
{
this
.
clearCompleted
=
function
()
{
var
todos
;
var
todos
;
...
@@ -90,7 +88,7 @@ define(
...
@@ -90,7 +88,7 @@ define(
dataStore
.
destroyAll
({
completed
:
true
});
dataStore
.
destroyAll
({
completed
:
true
});
todos
=
dataStore
.
all
();
todos
=
dataStore
.
all
();
this
.
trigger
(
'
dataClearedCompleted
'
,
{
todos
:
todos
});
this
.
trigger
(
'
dataClearedCompleted
'
,
{
todos
:
todos
});
}
};
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
on
(
document
,
'
uiAddRequested
'
,
this
.
add
);
this
.
on
(
document
,
'
uiAddRequested
'
,
this
.
add
);
...
...
dependency-examples/flight/app/js/store.js
View file @
a543e298
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
depot
'
'
depot
'
],
],
...
...
dependency-examples/flight/app/js/ui/main_selector.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
flight/component
'
'
flight/component
'
],
],
function
(
defineComponent
)
{
function
(
defineComponent
)
{
return
defineComponent
(
mainSelector
);
return
defineComponent
(
mainSelector
);
function
mainSelector
()
{
function
mainSelector
()
{
this
.
toggle
=
function
(
e
,
data
)
{
this
.
toggle
=
function
(
e
,
data
)
{
var
toggle
=
data
.
all
>
0
;
var
toggle
=
data
.
all
>
0
;
this
.
$node
.
toggle
(
toggle
);
this
.
$node
.
toggle
(
toggle
);
}
}
;
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
$node
.
hide
();
this
.
$node
.
hide
();
...
...
dependency-examples/flight/app/js/ui/new_item.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
flight/component
'
'
flight/component
'
],
],
function
(
defineComponent
)
{
function
(
defineComponent
)
{
return
defineComponent
(
newItem
);
return
defineComponent
(
newItem
);
function
newItem
()
{
function
newItem
()
{
var
ENTER_KEY
=
13
;
var
ENTER_KEY
=
13
;
this
.
createOnEnter
=
function
(
e
)
{
this
.
createOnEnter
=
function
(
e
)
{
...
@@ -25,7 +23,7 @@ define(
...
@@ -25,7 +23,7 @@ define(
});
});
this
.
$node
.
val
(
''
);
this
.
$node
.
val
(
''
);
}
}
;
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
on
(
'
keydown
'
,
this
.
createOnEnter
);
this
.
on
(
'
keydown
'
,
this
.
createOnEnter
);
...
...
dependency-examples/flight/app/js/ui/stats.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
flight/component
'
,
'
flight/component
'
,
'
./with_filters
'
,
'
./with_filters
'
,
...
@@ -10,7 +10,6 @@ define(
...
@@ -10,7 +10,6 @@ define(
],
],
function
(
defineComponent
,
withFilters
,
statsTmpl
,
utils
)
{
function
(
defineComponent
,
withFilters
,
statsTmpl
,
utils
)
{
return
defineComponent
(
stats
,
withFilters
);
return
defineComponent
(
stats
,
withFilters
);
function
stats
()
{
function
stats
()
{
...
@@ -26,11 +25,11 @@ define(
...
@@ -26,11 +25,11 @@ define(
this
.
$node
.
html
(
template
(
data
));
this
.
$node
.
html
(
template
(
data
));
this
.
$node
.
toggle
(
toggle
);
this
.
$node
.
toggle
(
toggle
);
this
.
markSelected
(
data
.
filter
);
this
.
markSelected
(
data
.
filter
);
}
}
;
this
.
clearCompleted
=
function
(
e
,
data
)
{
this
.
clearCompleted
=
function
(
e
,
data
)
{
this
.
trigger
(
'
uiClearRequested
'
);
this
.
trigger
(
'
uiClearRequested
'
);
}
}
;
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
$node
.
hide
();
this
.
$node
.
hide
();
...
...
dependency-examples/flight/app/js/ui/todo_list.js
View file @
a543e298
/*global define $ */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
flight/component
'
,
'
flight/component
'
,
'
text!app/templates/todo.html
'
,
'
text!app/templates/todo.html
'
,
...
@@ -9,11 +9,9 @@ define(
...
@@ -9,11 +9,9 @@ define(
],
],
function
(
defineComponent
,
todoTmpl
,
utils
)
{
function
(
defineComponent
,
todoTmpl
,
utils
)
{
return
defineComponent
(
todoList
);
return
defineComponent
(
todoList
);
function
todoList
()
{
function
todoList
()
{
var
ENTER_KEY
=
13
;
var
ENTER_KEY
=
13
;
var
template
=
utils
.
tmpl
(
todoTmpl
);
var
template
=
utils
.
tmpl
(
todoTmpl
);
...
@@ -29,23 +27,22 @@ define(
...
@@ -29,23 +27,22 @@ define(
data
.
todos
.
forEach
(
function
(
each
)
{
data
.
todos
.
forEach
(
function
(
each
)
{
this
.
render
(
e
,
{
todo
:
each
});
this
.
render
(
e
,
{
todo
:
each
});
},
this
);
},
this
);
}
}
;
this
.
render
=
function
(
e
,
data
)
{
this
.
render
=
function
(
e
,
data
)
{
if
(
e
.
type
==
'
dataTodoAdded
'
if
(
e
.
type
===
'
dataTodoAdded
'
&&
data
.
filter
===
'
completed
'
)
{
&&
data
.
filter
==
'
completed
'
)
{
return
;
return
;
}
}
this
.
$node
.
append
(
template
(
data
.
todo
));
this
.
$node
.
append
(
template
(
data
.
todo
));
}
}
;
this
.
edit
=
function
(
e
,
data
)
{
this
.
edit
=
function
(
e
,
data
)
{
var
$todoEl
=
$
(
data
.
el
).
parents
(
'
li
'
);
var
$todoEl
=
$
(
data
.
el
).
parents
(
'
li
'
);
$todoEl
.
addClass
(
'
editing
'
);
$todoEl
.
addClass
(
'
editing
'
);
this
.
select
(
'
editSelector
'
).
focus
();
this
.
select
(
'
editSelector
'
).
focus
();
}
}
;
this
.
requestUpdate
=
function
(
e
,
data
)
{
this
.
requestUpdate
=
function
(
e
,
data
)
{
var
$inputEl
=
$
(
e
.
currentTarget
);
var
$inputEl
=
$
(
e
.
currentTarget
);
...
@@ -65,30 +62,30 @@ define(
...
@@ -65,30 +62,30 @@ define(
}
else
{
}
else
{
this
.
trigger
(
'
uiRemoveRequested
'
,
{
id
:
id
});
this
.
trigger
(
'
uiRemoveRequested
'
,
{
id
:
id
});
}
}
}
,
}
;
this
.
requestUpdateOnEnter
=
function
(
e
,
data
)
{
this
.
requestUpdateOnEnter
=
function
(
e
,
data
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
this
.
requestUpdate
(
e
,
data
);
this
.
requestUpdate
(
e
,
data
);
}
}
}
,
}
;
this
.
requestRemove
=
function
(
e
,
data
)
{
this
.
requestRemove
=
function
(
e
,
data
)
{
var
id
=
$
(
data
.
el
).
attr
(
'
id
'
).
split
(
'
_
'
)[
1
];
var
id
=
$
(
data
.
el
).
attr
(
'
id
'
).
split
(
'
_
'
)[
1
];
this
.
trigger
(
'
uiRemoveRequested
'
,
{
id
:
id
});
this
.
trigger
(
'
uiRemoveRequested
'
,
{
id
:
id
});
}
}
;
this
.
remove
=
function
(
e
,
data
)
{
this
.
remove
=
function
(
e
,
data
)
{
var
$todoEl
=
this
.
$node
.
find
(
'
#
'
+
data
.
id
);
var
$todoEl
=
this
.
$node
.
find
(
'
#
'
+
data
.
id
);
$todoEl
.
remove
();
$todoEl
.
remove
();
}
}
;
this
.
toggle
=
function
(
e
,
data
)
{
this
.
toggle
=
function
(
e
,
data
)
{
var
$todoEl
=
$
(
data
.
el
).
parents
(
'
li
'
);
var
$todoEl
=
$
(
data
.
el
).
parents
(
'
li
'
);
$todoEl
.
toggleClass
(
'
completed
'
);
$todoEl
.
toggleClass
(
'
completed
'
);
this
.
trigger
(
'
uiToggleRequested
'
,
{
id
:
$todoEl
.
attr
(
'
id
'
)
});
this
.
trigger
(
'
uiToggleRequested
'
,
{
id
:
$todoEl
.
attr
(
'
id
'
)
});
}
}
;
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
on
(
document
,
'
dataTodoAdded
'
,
this
.
render
);
this
.
on
(
document
,
'
dataTodoAdded
'
,
this
.
render
);
...
...
dependency-examples/flight/app/js/ui/toggle_all.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
[
[
'
flight/component
'
'
flight/component
'
],
],
function
(
defineComponent
)
{
function
(
defineComponent
)
{
return
defineComponent
(
toggleAll
);
return
defineComponent
(
toggleAll
);
function
toggleAll
()
{
function
toggleAll
()
{
...
@@ -15,11 +14,11 @@ define(
...
@@ -15,11 +14,11 @@ define(
this
.
trigger
(
'
uiToggleAllRequested
'
,
{
this
.
trigger
(
'
uiToggleAllRequested
'
,
{
completed
:
this
.
$node
.
is
(
'
:checked
'
)
completed
:
this
.
$node
.
is
(
'
:checked
'
)
});
});
}
}
;
this
.
toggleCheckbox
=
function
(
e
,
data
)
{
this
.
toggleCheckbox
=
function
(
e
,
data
)
{
this
.
$node
[
0
].
checked
=
!
data
.
remaining
;
this
.
$node
[
0
].
checked
=
!
data
.
remaining
;
}
}
;
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
on
(
'
click
'
,
this
.
toggleAllComplete
);
this
.
on
(
'
click
'
,
this
.
toggleAllComplete
);
...
...
dependency-examples/flight/app/js/ui/with_filters.js
View file @
a543e298
/*global define $ */
'
use strict
'
;
'
use strict
'
;
define
(
define
(
function
()
{
function
()
{
return
function
withFilters
()
{
return
withFilters
;
function
withFilters
()
{
this
.
defaultAttrs
({
this
.
defaultAttrs
({
filterSelector
:
'
#filters a
'
filterSelector
:
'
#filters a
'
});
});
...
@@ -17,15 +14,15 @@ define(
...
@@ -17,15 +14,15 @@ define(
this
.
select
(
'
filterSelector
'
).
removeClass
(
'
selected
'
);
this
.
select
(
'
filterSelector
'
).
removeClass
(
'
selected
'
);
$
(
data
.
el
).
addClass
(
'
selected
'
);
$
(
data
.
el
).
addClass
(
'
selected
'
);
this
.
trigger
(
'
uiFilterRequested
'
,
{
filter
:
filter
});
this
.
trigger
(
'
uiFilterRequested
'
,
{
filter
:
filter
});
}
}
;
this
.
markSelected
=
function
(
filter
)
{
this
.
markSelected
=
function
(
filter
)
{
this
.
$node
.
find
(
'
[href="#/
'
+
filter
+
'
"]
'
).
addClass
(
'
selected
'
);
this
.
$node
.
find
(
'
[href="#/
'
+
filter
+
'
"]
'
).
addClass
(
'
selected
'
);
}
}
;
this
.
after
(
'
initialize
'
,
function
()
{
this
.
after
(
'
initialize
'
,
function
()
{
this
.
on
(
'
click
'
,
{
filterSelector
:
this
.
chooseFilter
});
this
.
on
(
'
click
'
,
{
filterSelector
:
this
.
chooseFilter
});
});
});
}
}
;
}
}
);
);
dependency-examples/flight/app/js/utils.js
View file @
a543e298
/*global define */
'
use strict
'
;
'
use strict
'
;
// tmpl function scooped from underscore.
// tmpl function scooped from underscore.
...
@@ -13,6 +14,7 @@ define(function () {
...
@@ -13,6 +14,7 @@ define(function () {
'
<
'
:
'
<
'
,
'
<
'
:
'
<
'
,
'
>
'
:
'
>
'
,
'
>
'
:
'
>
'
,
'
"
'
:
'
"
'
,
'
"
'
:
'
"
'
,
/*jshint quotmark:false */
"
'
"
:
'
'
'
,
"
'
"
:
'
'
'
,
'
/
'
:
'
/
'
'
/
'
:
'
/
'
}
}
...
@@ -28,23 +30,27 @@ define(function () {
...
@@ -28,23 +30,27 @@ define(function () {
};
};
// Functions for escaping and unescaping strings to/from HTML interpolation.
// Functions for escaping and unescaping strings to/from HTML interpolation.
[
'
escape
'
,
'
unescape
'
].
forEach
(
function
(
method
)
{
[
'
escape
'
,
'
unescape
'
].
forEach
(
function
(
method
)
{
_
[
method
]
=
function
(
string
)
{
_
[
method
]
=
function
(
string
)
{
if
(
string
==
null
)
return
''
;
if
(
string
===
null
||
string
===
undefined
)
{
return
(
''
+
string
).
replace
(
entityRegexes
[
method
],
function
(
match
)
{
return
''
;
}
return
(
''
+
string
).
replace
(
entityRegexes
[
method
],
function
(
match
)
{
return
entityMap
[
method
][
match
];
return
entityMap
[
method
][
match
];
});
});
};
};
});
});
var
settings
=
{
var
settings
=
{
evaluate
:
/<%
([\s\S]
+
?)
%>/g
,
evaluate
:
/<%
([\s\S]
+
?)
%>/g
,
interpolate
:
/<%=
([\s\S]
+
?)
%>/g
,
interpolate
:
/<%=
([\s\S]
+
?)
%>/g
,
escape
:
/<%-
([\s\S]
+
?)
%>/g
escape
:
/<%-
([\s\S]
+
?)
%>/g
};
};
var
noMatch
=
/
(
.
)
^/
;
var
noMatch
=
/
(
.
)
^/
;
var
escapes
=
{
var
escapes
=
{
/*jshint quotmark:false */
"
'
"
:
"
'
"
,
"
'
"
:
"
'
"
,
'
\\
'
:
'
\\
'
,
'
\\
'
:
'
\\
'
,
'
\r
'
:
'
r
'
,
'
\r
'
:
'
r
'
,
...
@@ -59,7 +65,7 @@ define(function () {
...
@@ -59,7 +65,7 @@ define(function () {
// JavaScript micro-templating, similar to John Resig's implementation.
// JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
// and correctly escapes quotes within interpolated code.
var
template
=
function
(
text
,
data
)
{
var
template
=
function
(
text
,
data
)
{
var
render
;
var
render
;
// Combine delimiters into one regular expression via alternation.
// Combine delimiters into one regular expression via alternation.
...
@@ -72,9 +78,11 @@ define(function () {
...
@@ -72,9 +78,11 @@ define(function () {
// Compile the template source, escaping string literals appropriately.
// Compile the template source, escaping string literals appropriately.
var
index
=
0
;
var
index
=
0
;
var
source
=
"
__p+='
"
;
var
source
=
"
__p+='
"
;
text
.
replace
(
matcher
,
function
(
match
,
escape
,
interpolate
,
evaluate
,
offset
)
{
text
.
replace
(
matcher
,
function
(
match
,
escape
,
interpolate
,
evaluate
,
offset
)
{
source
+=
text
.
slice
(
index
,
offset
)
source
+=
text
.
slice
(
index
,
offset
)
.
replace
(
escaper
,
function
(
match
)
{
return
'
\\
'
+
escapes
[
match
];
});
.
replace
(
escaper
,
function
(
match
)
{
return
'
\\
'
+
escapes
[
match
];
});
if
(
escape
)
{
if
(
escape
)
{
source
+=
"
'+
\n
((__t=(
"
+
escape
+
"
))==null?'':_.escape(__t))+
\n
'
"
;
source
+=
"
'+
\n
((__t=(
"
+
escape
+
"
))==null?'':_.escape(__t))+
\n
'
"
;
...
@@ -91,7 +99,9 @@ define(function () {
...
@@ -91,7 +99,9 @@ define(function () {
source
+=
"
';
\n
"
;
source
+=
"
';
\n
"
;
// If a variable is not specified, place data values in local scope.
// If a variable is not specified, place data values in local scope.
if
(
!
settings
.
variable
)
source
=
'
with(obj||{}){
\n
'
+
source
+
'
}
\n
'
;
if
(
!
settings
.
variable
)
{
source
=
'
with(obj||{}){
\n
'
+
source
+
'
}
\n
'
;
}
source
=
"
var __t,__p='',__j=Array.prototype.join,
"
+
source
=
"
var __t,__p='',__j=Array.prototype.join,
"
+
"
print=function(){__p+=__j.call(arguments,'');};
\n
"
+
"
print=function(){__p+=__j.call(arguments,'');};
\n
"
+
...
@@ -99,13 +109,16 @@ define(function () {
...
@@ -99,13 +109,16 @@ define(function () {
try
{
try
{
render
=
new
Function
(
settings
.
variable
||
'
obj
'
,
'
_
'
,
source
);
render
=
new
Function
(
settings
.
variable
||
'
obj
'
,
'
_
'
,
source
);
}
catch
(
e
)
{
}
catch
(
err
)
{
e
.
source
=
source
;
err
.
source
=
source
;
throw
e
;
throw
err
;
}
if
(
data
)
{
return
render
(
data
,
_
);
}
}
if
(
data
)
return
render
(
data
,
_
);
var
template
=
function
(
data
)
{
var
template
=
function
(
data
)
{
return
render
.
call
(
this
,
data
,
_
);
return
render
.
call
(
this
,
data
,
_
);
};
};
...
...
dependency-examples/flight/index.html
View file @
a543e298
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<title>
Flight • Todo
</title>
<title>
Flight • Todo
</title>
<link
rel=
"stylesheet"
href=
"../../assets/base.css"
>
<link
rel=
"stylesheet"
href=
"../../assets/base.css"
>
</head>
</head>
<body>
<body>
<section
id=
"todoapp"
>
<section
id=
"todoapp"
>
<header
id=
"header"
>
<header
id=
"header"
>
<h1>
todos
</h1>
<h1>
todos
</h1>
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
<p>
Created by
<a
href=
"http://github.com/mkuklis"
>
Michal Kuklis
</a></p>
<p>
Created by
<a
href=
"http://github.com/mkuklis"
>
Michal Kuklis
</a></p>
<p>
Part of
<a
href=
"http://todomvc.com"
>
TodoMVC
</a></p>
<p>
Part of
<a
href=
"http://todomvc.com"
>
TodoMVC
</a></p>
</footer>
</footer>
<script
src=
"../../assets/base.js"
></script>
<script
data-main=
"app/js/main"
src=
"components/requirejs/requirejs.js"
></script>
<script
data-main=
"app/js/main"
src=
"components/requirejs/requirejs.js"
></script>
</body>
</body>
</html>
</html>
template/index.html
View file @
a543e298
<!doctype html>
<!doctype html>
<html
lang=
"en"
>
<html
lang=
"en"
>
<head>
<head>
<meta
charset=
"utf-8"
>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
>
<title>
Template • TodoMVC
</title>
<title>
Template • TodoMVC
</title>
...
@@ -10,8 +10,8 @@
...
@@ -10,8 +10,8 @@
<!--[if IE]>
<!--[if IE]>
<script src="../assets/ie.js"></script>
<script src="../assets/ie.js"></script>
<![endif]-->
<![endif]-->
</head>
</head>
<body>
<body>
<section
id=
"todoapp"
>
<section
id=
"todoapp"
>
<header
id=
"header"
>
<header
id=
"header"
>
<h1>
todos
</h1>
<h1>
todos
</h1>
...
@@ -72,5 +72,5 @@
...
@@ -72,5 +72,5 @@
<!-- Scripts here. Don't remove this ↓ -->
<!-- Scripts here. Don't remove this ↓ -->
<script
src=
"../assets/base.js"
></script>
<script
src=
"../assets/base.js"
></script>
<script
src=
"js/app.js"
></script>
<script
src=
"js/app.js"
></script>
</body>
</body>
</html>
</html>
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