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
bf17b6e5
Commit
bf17b6e5
authored
May 16, 2012
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SammyJS: Fix paths, minify js, correct folder structure.
parent
ca401cea
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
39 additions
and
7902 deletions
+39
-7902
labs/architecture-examples/sammyjs/css/app.css
labs/architecture-examples/sammyjs/css/app.css
+1
-1
labs/architecture-examples/sammyjs/css/destroy.png
labs/architecture-examples/sammyjs/css/destroy.png
+0
-0
labs/architecture-examples/sammyjs/index.html
labs/architecture-examples/sammyjs/index.html
+8
-8
labs/architecture-examples/sammyjs/js/app.js
labs/architecture-examples/sammyjs/js/app.js
+0
-0
labs/architecture-examples/sammyjs/js/lib/model.js
labs/architecture-examples/sammyjs/js/lib/model.js
+4
-0
labs/architecture-examples/sammyjs/js/lib/sammy.js
labs/architecture-examples/sammyjs/js/lib/sammy.js
+24
-0
labs/architecture-examples/sammyjs/js/lib/sammy.template.js
labs/architecture-examples/sammyjs/js/lib/sammy.template.js
+2
-0
labs/architecture-examples/sammyjs/lib/jquery-1.4.2.js
labs/architecture-examples/sammyjs/lib/jquery-1.4.2.js
+0
-6240
labs/architecture-examples/sammyjs/lib/model.js
labs/architecture-examples/sammyjs/lib/model.js
+0
-155
labs/architecture-examples/sammyjs/lib/sammy.js
labs/architecture-examples/sammyjs/lib/sammy.js
+0
-1381
labs/architecture-examples/sammyjs/lib/sammy.template.js
labs/architecture-examples/sammyjs/lib/sammy.template.js
+0
-117
No files found.
labs/architecture-examples/sammyjs/app.css
→
labs/architecture-examples/sammyjs/
css/
app.css
View file @
bf17b6e5
...
...
@@ -22,7 +22,7 @@ p { position: absolute; top: 116px; left: 80px; margin: 0; padding: 0; width: 27
.new
:hover
{
opacity
:
.75
;
}
.trashcan
{
position
:
absolute
;
top
:
63px
;
left
:
57px
;
width
:
25px
;
height
:
25px
;
cursor
:
pointer
;
background
:
url(
assets/
destroy.png)
no-repeat
;
}
.trashcan
{
position
:
absolute
;
top
:
63px
;
left
:
57px
;
width
:
25px
;
height
:
25px
;
cursor
:
pointer
;
background
:
url(destroy.png)
no-repeat
;
}
.trashcan
:hover
{
opacity
:
.75
;
}
li
.trashcan
{
float
:
right
;
left
:
95%
;
...
...
labs/architecture-examples/sammyjs/css/destroy.png
0 → 100644
View file @
bf17b6e5
259 Bytes
labs/architecture-examples/sammyjs/index.html
View file @
bf17b6e5
...
...
@@ -4,9 +4,9 @@
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
>
<title>
Sammy.js • TodoMVC
</title>
<link
rel=
"stylesheet"
href=
"app.css"
>
<link
rel=
"stylesheet"
href=
"
css/
app.css"
>
<!--[if IE]>
<script src="../../assets/ie.js"></script>
<script src="../../
../
assets/ie.js"></script>
<![endif]-->
</head>
<body>
...
...
@@ -31,11 +31,11 @@
<br
/>
based on some code by Brandon Aaron
</div>
<script
src=
"../../assets/base.js"
></script>
<script
src=
"../../assets/jquery.min.js"
></script>
<script
src=
"lib/sammy.js"
></script>
<script
src=
"lib/sammy.template.js"
></script>
<script
src=
"lib/model.js"
></script>
<script
src=
"app.js"
></script>
<script
src=
"../../
../
assets/base.js"
></script>
<script
src=
"../../
../
assets/jquery.min.js"
></script>
<script
src=
"
js/
lib/sammy.js"
></script>
<script
src=
"
js/
lib/sammy.template.js"
></script>
<script
src=
"
js/
lib/model.js"
></script>
<script
src=
"
js/
app.js"
></script>
</body>
</html>
\ No newline at end of file
labs/architecture-examples/sammyjs/app.js
→
labs/architecture-examples/sammyjs/
js/
app.js
View file @
bf17b6e5
File moved
labs/architecture-examples/sammyjs/js/lib/model.js
0 → 100644
View file @
bf17b6e5
Model
=
{
name
:
"
model
"
,
init
:
function
(){
this
.
_id
=
0
;
this
.
_data
=
[];
this
.
_deserialize
();
return
this
},
create
:
function
(
a
,
b
){
a
.
id
=
this
.
_newId
();
var
c
=
this
.
_data
[
this
.
_data
.
push
(
a
)
-
1
];
!
1
!==
b
&&
this
.
save
();
return
this
.
_clone
(
c
)},
first
:
function
(){
return
this
.
_clone
(
this
.
_data
[
0
])},
last
:
function
(){
return
this
.
_clone
(
_data
[
this
.
_data
.
length
-
1
])},
get
:
function
(
a
){
return
this
.
_clone
(
this
.
_get
(
a
))},
getAll
:
function
(){
return
this
.
_clone
(
this
.
_data
)},
filter
:
function
(
a
,
b
){
return
this
.
_clone
(
this
.
_filter
(
a
,
b
))},
multiFilter
:
function
(){
return
this
.
_clone
(
this
.
_multiFilter
(
filter
))},
update
:
function
(
a
,
b
,
c
){
if
(
a
=
this
.
_get
(
a
)
||!
1
)
this
.
_mixin
(
a
,
b
),
!
1
!==
c
&&
this
.
save
();
return
a
},
destroy
:
function
(
a
,
b
){
this
.
_data
.
splice
(
this
.
_indexOf
(
a
),
1
);
!
1
!==
b
&&
this
.
save
();
return
!
0
},
destroyAll
:
function
(
a
){
this
.
_data
=
[];
!
1
!==
a
&&
this
.
save
();
return
!
0
},
save
:
function
(){
this
.
_serialize
();
return
!
0
},
_first
:
function
(){
return
this
.
_data
[
0
]},
_last
:
function
(){
return
_data
[
this
.
_data
.
length
-
1
]},
_get
:
function
(
a
){
return
this
.
_filter
(
"
id
"
,
a
)[
0
]},
_filter
:
function
(
a
,
b
){
var
c
=
[],
d
,
e
,
f
=
"
undefined
"
==
typeof
b
;
for
(
d
in
this
.
_data
)
this
.
_data
.
hasOwnProperty
(
d
)
&&
(
e
=
this
.
_data
[
d
],(
f
||
e
[
a
]
==
b
)
&&
c
.
push
(
e
));
return
c
},
_multiFilter
:
function
(
a
){
var
b
=
[],
c
,
d
,
e
;
for
(
c
in
this
.
_data
)
if
(
this
.
_data
.
hasOwnProperty
(
c
))
for
(
d
in
e
=
this
.
_data
[
c
],
a
)
a
.
hasOwnProperty
(
d
)
&&
a
[
d
]
==
e
[
d
]
&&
b
.
push
(
e
);
return
b
},
_indexOf
:
function
(
a
){
return
this
.
_data
.
indexOf
(
this
.
_get
(
a
))},
_serialize
:
function
(){
localStorage
[
this
.
name
]
=
JSON
.
stringify
({
prevId
:
this
.
_id
,
data
:
this
.
_data
})},
_deserialize
:
function
(){
var
a
=
localStorage
[
this
.
name
];
a
&&
(
a
=
JSON
.
parse
(
a
),
this
.
_id
=
a
.
prevId
,
this
.
_data
=
a
.
data
)},
_newId
:
function
(){
return
this
.
_id
++
},
_mixin
:
function
(
a
,
b
){
for
(
var
c
in
b
)
b
.
hasOwnProperty
(
c
)
&&
(
a
[
c
]
=
b
[
c
])},
_clone
:
function
(
a
){
var
b
=
Object
.
prototype
.
toString
.
call
(
a
),
c
=
a
;
if
(
"
[object Object]
"
==
b
){
var
c
=
{},
d
;
for
(
d
in
a
)
a
.
hasOwnProperty
(
d
)
&&
(
c
[
d
]
=
this
.
_clone
(
a
[
d
]))}
else
if
(
"
[object Array]
"
==
b
){
c
=
[];
b
=
0
;
for
(
d
=
a
.
length
;
b
<
d
;
b
++
)
c
[
b
]
=
this
.
_clone
(
a
[
b
])}
return
c
}};
"
function
"
!==
typeof
Object
.
create
&&
(
Object
.
create
=
function
(
a
){
function
b
(){}
b
.
prototype
=
a
;
return
new
b
});
\ No newline at end of file
labs/architecture-examples/sammyjs/js/lib/sammy.js
0 → 100755
View file @
bf17b6e5
This diff is collapsed.
Click to expand it.
labs/architecture-examples/sammyjs/js/lib/sammy.template.js
0 → 100755
View file @
bf17b6e5
(
function
(
f
){
var
d
=
{};
Sammy
=
Sammy
||
{};
Sammy
.
Template
=
function
(
g
,
e
){
e
||
(
e
=
"
template
"
);
g
.
helper
(
e
,
function
(
a
,
c
,
b
){
"
undefined
"
==
typeof
b
&&
(
b
=
a
);
a
:{
c
=
f
.
extend
({},
this
,
c
);
if
(
d
[
b
])
fn
=
d
[
b
];
else
{
if
(
"
undefined
"
==
typeof
a
){
a
=!
1
;
break
a
}
fn
=
d
[
b
]
=
new
Function
(
"
obj
"
,
'
var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push("
'
+
a
.
replace
(
/
[\r\t\n]
/g
,
"
"
).
replace
(
/
\"
/g
,
'
\\
"
'
).
split
(
"
<%
"
).
join
(
"
\t
"
).
replace
(
/
((
^|%>
)[^\t]
*
)
/g
,
"
$1
\r
"
).
replace
(
/
\t
=
(
.*
?)
%>/g
,
'
",$1,"
'
).
split
(
"
\t
"
).
join
(
'
");
'
).
split
(
"
%>
"
).
join
(
'
p.push("
'
).
split
(
"
\r
"
).
join
(
""
)
+
"
\"
);}return p.join('');
"
)}
a
=
"
undefined
"
!=
typeof
c
?
fn
(
c
):
fn
}
return
a
})}})(
jQuery
);
\ No newline at end of file
labs/architecture-examples/sammyjs/lib/jquery-1.4.2.js
deleted
100644 → 0
View file @
ca401cea
This diff is collapsed.
Click to expand it.
labs/architecture-examples/sammyjs/lib/model.js
deleted
100644 → 0
View file @
ca401cea
Model
=
{
name
:
'
model
'
,
init
:
function
()
{
this
.
_id
=
0
;
this
.
_data
=
[];
this
.
_deserialize
();
return
this
;
},
create
:
function
(
attributes
,
save
)
{
attributes
.
id
=
this
.
_newId
();
var
item
=
this
.
_data
[
(
this
.
_data
.
push
(
attributes
))
-
1
];
if
(
save
!==
false
)
{
this
.
save
();
}
return
this
.
_clone
(
item
);
},
first
:
function
()
{
return
this
.
_clone
(
this
.
_data
[
0
]);
},
last
:
function
()
{
return
this
.
_clone
(
_data
[
this
.
_data
.
length
-
1
]);
},
get
:
function
(
id
)
{
return
this
.
_clone
(
this
.
_get
(
id
));
},
getAll
:
function
()
{
return
this
.
_clone
(
this
.
_data
);
},
filter
:
function
(
attribute
,
value
)
{
return
this
.
_clone
(
this
.
_filter
(
attribute
,
value
));
},
multiFilter
:
function
(
filters
)
{
return
this
.
_clone
(
this
.
_multiFilter
(
filter
));
},
update
:
function
(
id
,
attributes
,
save
)
{
var
item
=
this
.
_get
(
id
)
||
false
;
if
(
item
)
{
this
.
_mixin
(
item
,
attributes
);
if
(
save
!==
false
)
{
this
.
save
();
}
}
return
item
;
},
destroy
:
function
(
id
,
save
)
{
this
.
_data
.
splice
(
this
.
_indexOf
(
id
),
1
);
if
(
save
!==
false
)
{
this
.
save
();
}
return
true
;
},
destroyAll
:
function
(
save
)
{
this
.
_data
=
[];
if
(
save
!==
false
)
{
this
.
save
();
}
return
true
;
},
save
:
function
()
{
this
.
_serialize
();
return
true
;
},
_first
:
function
()
{
return
this
.
_data
[
0
];
},
_last
:
function
()
{
return
_data
[
this
.
_data
.
length
-
1
];
},
_get
:
function
(
id
)
{
return
this
.
_filter
(
'
id
'
,
id
)[
0
];
},
_filter
:
function
(
attribute
,
value
)
{
var
items
=
[],
key
,
item
,
undefValue
=
(
typeof
value
==
"
undefined
"
);
for
(
key
in
this
.
_data
)
{
if
(
this
.
_data
.
hasOwnProperty
(
key
))
{
item
=
this
.
_data
[
key
];
if
(
undefValue
||
item
[
attribute
]
==
value
)
{
items
.
push
(
item
);
}
}
}
return
items
;
},
_multiFilter
:
function
(
filters
)
{
var
items
=
[],
key
,
attribute
,
item
;
for
(
key
in
this
.
_data
)
{
if
(
this
.
_data
.
hasOwnProperty
(
key
))
{
item
=
this
.
_data
[
key
];
for
(
attribute
in
filters
)
{
if
(
filters
.
hasOwnProperty
(
attribute
))
{
if
(
filters
[
attribute
]
==
item
[
attribute
])
{
items
.
push
(
item
);
}
}
}
}
}
return
items
;
},
_indexOf
:
function
(
id
)
{
return
this
.
_data
.
indexOf
(
this
.
_get
(
id
));
},
_serialize
:
function
()
{
var
data
=
{
prevId
:
this
.
_id
,
data
:
this
.
_data
};
localStorage
[
this
.
name
]
=
JSON
.
stringify
(
data
);
},
_deserialize
:
function
()
{
var
data
=
localStorage
[
this
.
name
];
if
(
data
)
{
data
=
JSON
.
parse
(
data
);
this
.
_id
=
data
.
prevId
;
this
.
_data
=
data
.
data
;
}
},
_newId
:
function
()
{
return
this
.
_id
++
;
},
_mixin
:
function
(
to
,
from
)
{
for
(
var
key
in
from
)
{
if
(
from
.
hasOwnProperty
(
key
))
{
to
[
key
]
=
from
[
key
];
}
}
},
_clone
:
function
(
obj
)
{
var
type
=
Object
.
prototype
.
toString
.
call
(
obj
),
cloned
=
obj
;
if
(
type
==
'
[object Object]
'
)
{
cloned
=
{};
for
(
var
key
in
obj
)
{
obj
.
hasOwnProperty
(
key
)
&&
(
cloned
[
key
]
=
this
.
_clone
(
obj
[
key
]));
}
}
else
if
(
type
==
'
[object Array]
'
)
{
cloned
=
[];
for
(
var
index
=
0
,
length
=
obj
.
length
;
index
<
length
;
index
++
)
{
cloned
[
index
]
=
this
.
_clone
(
obj
[
index
]);
}
}
return
cloned
;
}
};
// http://javascript.crockford.com/prototypal.html
if
(
typeof
Object
.
create
!==
'
function
'
)
{
Object
.
create
=
function
(
o
)
{
function
F
()
{}
F
.
prototype
=
o
;
return
new
F
();
};
}
\ No newline at end of file
labs/architecture-examples/sammyjs/lib/sammy.js
deleted
100755 → 0
View file @
ca401cea
This diff is collapsed.
Click to expand it.
labs/architecture-examples/sammyjs/lib/sammy.template.js
deleted
100755 → 0
View file @
ca401cea
(
function
(
$
)
{
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
// adapted from: http://ejohn.org/blog/javascript-micro-templating/
// originally $.srender by Greg Borenstein http://ideasfordozens.com in Feb 2009
// modified for Sammy by Aaron Quint for caching templates by name
var
srender_cache
=
{};
var
srender
=
function
(
name
,
template
,
data
)
{
// target is an optional element; if provided, the result will be inserted into it
// otherwise the result will simply be returned to the caller
if
(
srender_cache
[
name
])
{
fn
=
srender_cache
[
name
];
}
else
{
if
(
typeof
template
==
'
undefined
'
)
{
// was a cache check, return false
return
false
;
}
// Generate a reusable function that will serve as a template
// generator (and which will be cached).
fn
=
srender_cache
[
name
]
=
new
Function
(
"
obj
"
,
"
var p=[],print=function(){p.push.apply(p,arguments);};
"
+
// Introduce the data as local variables using with(){}
"
with(obj){p.push(
\"
"
+
// Convert the template into pure JavaScript
template
.
replace
(
/
[\r\t\n]
/g
,
"
"
)
.
replace
(
/
\"
/g
,
'
\\
"
'
)
.
split
(
"
<%
"
).
join
(
"
\t
"
)
.
replace
(
/
((
^|%>
)[^\t]
*
)
/g
,
"
$1
\r
"
)
.
replace
(
/
\t
=
(
.*
?)
%>/g
,
"
\"
,$1,
\"
"
)
.
split
(
"
\t
"
).
join
(
"
\"
);
"
)
.
split
(
"
%>
"
).
join
(
"
p.push(
\"
"
)
.
split
(
"
\r
"
).
join
(
""
)
+
"
\"
);}return p.join('');
"
);
}
if
(
typeof
data
!=
'
undefined
'
)
{
return
fn
(
data
);
}
else
{
return
fn
;
}
};
Sammy
=
Sammy
||
{};
// <tt>Sammy.Template</tt> is a simple plugin that provides a way to create
// and render client side templates. The rendering code is based on John Resig's
// quick templates and Greg Borenstien's srender plugin.
// This is also a great template/boilerplate for Sammy plugins.
//
// Templates use <% %> tags to denote embedded javascript.
//
// === Examples
//
// Here is an example template (user.template):
//
// <div class="user">
// <div class="user-name"><%= user.name %></div>
// <% if (user.photo_url) { %>
// <div class="photo"><img src="<%= user.photo_url %>" /></div>
// <% } %>
// </div>
//
// Given that is a publicly accesible file, you would render it like:
//
// $.sammy(function() {
// // include the plugin
// this.use(Sammy.Template);
//
// this.get('#/', function() {
// // the template is rendered in the current context.
// this.user = {name: 'Aaron Quint'};
// // partial calls template() because of the file extension
// this.partial('user.template');
// })
// });
//
// You can also pass a second argument to use() that will alias the template
// method and therefore allow you to use a different extension for template files
// in <tt>partial()</tt>
//
// // alias to 'tpl'
// this.use(Sammy.Template, 'tpl');
//
// // now .tpl files will be run through srender
// this.get('#/', function() {
// this.partial('myfile.tpl');
// });
//
Sammy
.
Template
=
function
(
app
,
method_alias
)
{
// *Helper:* Uses simple templating to parse ERB like templates.
//
// === Arguments
//
// +template+:: A String template. '<% %>' tags are evaluated as Javascript and replaced with the elements in data.
// +data+:: An Object containing the replacement values for the template.
// data is extended with the <tt>EventContext</tt> allowing you to call its methods within the template.
// +name+:: An optional String name to cache the template.
//
var
template
=
function
(
template
,
data
,
name
)
{
// use name for caching
if
(
typeof
name
==
'
undefined
'
)
name
=
template
;
return
srender
(
name
,
template
,
$
.
extend
({},
this
,
data
));
};
// set the default method name/extension
if
(
!
method_alias
)
method_alias
=
'
template
'
;
// create the helper at the method alias
app
.
helper
(
method_alias
,
template
);
};
})(
jQuery
);
\ No newline at end of file
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