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
e24eae60
Commit
e24eae60
authored
Jan 01, 2012
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove dependency on store.js
parent
14895be2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
152 deletions
+10
-152
todo-example/jquery/index.html
todo-example/jquery/index.html
+0
-1
todo-example/jquery/js/app.js
todo-example/jquery/js/app.js
+10
-3
todo-example/jquery/js/store.js
todo-example/jquery/js/store.js
+0
-148
No files found.
todo-example/jquery/index.html
View file @
e24eae60
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
<script
src=
"js/json2.js"
></script>
<script
src=
"js/json2.js"
></script>
<script
src=
"js/jquery.min.js"
></script>
<script
src=
"js/jquery.min.js"
></script>
<script
src=
"js/jquery.tmpl.js"
></script>
<script
src=
"js/jquery.tmpl.js"
></script>
<script
src=
"js/store.js"
></script>
<script
src=
"js/app.js"
></script>
<script
src=
"js/app.js"
></script>
<script
type=
"text/x-jquery-tmpl"
id=
"todo-template"
>
<script
type=
"text/x-jquery-tmpl"
id=
"todo-template"
>
<
li
class
=
"
item {{if done}}done{{/if}}
"
data
-
id
=
"
${id}
"
>
<
li
class
=
"
item {{if done}}done{{/if}}
"
data
-
id
=
"
${id}
"
>
...
...
todo-example/jquery/js/app.js
View file @
e24eae60
...
@@ -37,9 +37,8 @@ jQuery(function($) {
...
@@ -37,9 +37,8 @@ jQuery(function($) {
var
App
=
{
var
App
=
{
init
:
function
()
{
init
:
function
()
{
this
.
todos
=
this
.
store
();
this
.
cacheElements
();
this
.
cacheElements
();
this
.
store
=
new
Store
(
'
todo-jquery
'
);
this
.
todos
=
this
.
store
.
get
(
'
todos
'
)
||
[];
this
.
bindEvents
();
this
.
bindEvents
();
this
.
render
();
this
.
render
();
},
},
...
@@ -51,6 +50,14 @@ jQuery(function($) {
...
@@ -51,6 +50,14 @@ jQuery(function($) {
this
.
$count
=
this
.
$footer
.
find
(
'
.count
'
);
this
.
$count
=
this
.
$footer
.
find
(
'
.count
'
);
this
.
$clearBtn
=
this
.
$footer
.
find
(
'
.clear
'
);
this
.
$clearBtn
=
this
.
$footer
.
find
(
'
.clear
'
);
},
},
store
:
function
(
data
)
{
if
(
arguments
.
length
)
{
return
localStorage
.
setItem
(
'
todo-jquery
'
,
JSON
.
stringify
(
data
)
);
}
else
{
var
store
=
localStorage
.
getItem
(
'
todo-jquery
'
);
return
(
store
&&
JSON
.
parse
(
store
)
)
||
[];
}
},
bindEvents
:
function
()
{
bindEvents
:
function
()
{
var
app
=
this
.
$todoApp
,
var
app
=
this
.
$todoApp
,
list
=
this
.
$todoList
;
list
=
this
.
$todoList
;
...
@@ -66,7 +73,7 @@ jQuery(function($) {
...
@@ -66,7 +73,7 @@ jQuery(function($) {
var
html
=
this
.
$template
.
tmpl
(
this
.
todos
);
var
html
=
this
.
$template
.
tmpl
(
this
.
todos
);
this
.
$todoList
.
html
(
html
);
this
.
$todoList
.
html
(
html
);
this
.
renderFooter
();
this
.
renderFooter
();
this
.
store
.
set
(
'
todos
'
,
this
.
todos
);
this
.
store
(
this
.
todos
);
},
},
renderFooter
:
function
()
{
renderFooter
:
function
()
{
var
todoCount
=
this
.
todos
.
length
,
var
todoCount
=
this
.
todos
.
length
,
...
...
todo-example/jquery/js/store.js
deleted
100755 → 0
View file @
14895be2
//
// Copyright (c) 2011 Frank Kohlhepp
// https://github.com/frankkohlhepp/store-js
// License: MIT-license
//
(
function
()
{
var
Store
=
this
.
Store
=
function
(
name
,
defaults
,
watcherSpeed
)
{
var
that
=
this
;
this
.
name
=
name
;
this
.
listeners
=
{};
// Set defaults
if
(
defaults
)
{
for
(
var
key
in
defaults
)
{
if
(
defaults
.
hasOwnProperty
(
key
)
&&
this
.
get
(
key
)
===
undefined
)
{
this
.
set
(
key
,
defaults
[
key
]);
}
}
}
// Fake events
var
fireEvent
=
function
(
name
,
value
)
{
([
name
,
"
*
"
]).
each
(
function
(
selector
)
{
if
(
that
.
listeners
[
selector
])
{
that
.
listeners
[
selector
].
each
(
function
(
callback
)
{
callback
(
value
,
name
,
that
.
name
);
});
}
});
};
var
oldObj
=
this
.
toObject
();
var
standby
=
function
()
{
watcher
(
true
);
};
var
watcher
=
function
(
skipCheck
)
{
if
(
Object
.
keys
(
that
.
listeners
).
length
!==
0
)
{
var
newObj
=
that
.
toObject
();
if
(
!
skipCheck
)
{
for
(
var
key
in
newObj
)
{
if
(
newObj
.
hasOwnProperty
(
key
)
&&
newObj
[
key
]
!==
oldObj
[
key
])
{
fireEvent
(
key
,
newObj
[
key
]);
}
}
for
(
var
key
in
oldObj
)
{
if
(
oldObj
.
hasOwnProperty
(
key
)
&&
!
newObj
.
hasOwnProperty
(
key
))
{
fireEvent
(
key
,
newObj
[
key
]);
}
}
}
oldObj
=
newObj
;
setTimeout
(
watcher
,
(
watcherSpeed
||
300
));
}
else
{
setTimeout
(
standby
,
1000
);
}
};
standby
();
};
Store
.
__proto__
=
function
Empty
()
{};
Store
.
__proto__
.
clear
=
function
()
{
localStorage
.
clear
();
};
Store
.
prototype
.
get
=
function
(
name
)
{
var
value
=
localStorage
.
getItem
(
"
store.
"
+
this
.
name
+
"
.
"
+
name
);
if
(
value
===
null
)
{
return
;
}
try
{
return
JSON
.
parse
(
value
);
}
catch
(
e
)
{
return
null
;
}
};
Store
.
prototype
.
set
=
function
(
name
,
value
)
{
if
(
value
===
undefined
)
{
this
.
remove
(
name
);
}
else
{
if
(
typeof
value
===
"
function
"
)
{
value
=
null
;
}
else
{
try
{
value
=
JSON
.
stringify
(
value
);
}
catch
(
e
)
{
value
=
null
;
}
}
localStorage
.
setItem
(
"
store.
"
+
this
.
name
+
"
.
"
+
name
,
value
);
}
return
this
;
};
Store
.
prototype
.
remove
=
function
(
name
)
{
localStorage
.
removeItem
(
"
store.
"
+
this
.
name
+
"
.
"
+
name
);
return
this
;
};
Store
.
prototype
.
removeAll
=
function
()
{
var
name
=
"
store.
"
+
this
.
name
+
"
.
"
;
for
(
var
i
=
(
localStorage
.
length
-
1
);
i
>=
0
;
i
--
)
{
if
(
localStorage
.
key
(
i
).
substring
(
0
,
name
.
length
)
===
name
)
{
localStorage
.
removeItem
(
localStorage
.
key
(
i
));
}
}
return
this
;
};
Store
.
prototype
.
toObject
=
function
()
{
var
values
=
{};
var
name
=
"
store.
"
+
this
.
name
+
"
.
"
;
for
(
var
i
=
(
localStorage
.
length
-
1
);
i
>=
0
;
i
--
)
{
if
(
localStorage
.
key
(
i
).
substring
(
0
,
name
.
length
)
===
name
)
{
var
key
=
localStorage
.
key
(
i
).
substring
(
name
.
length
);
var
value
=
this
.
get
(
key
);
if
(
value
!==
undefined
)
{
values
[
key
]
=
value
;
}
}
}
return
values
;
};
Store
.
prototype
.
fromObject
=
function
(
values
,
merge
)
{
if
(
!
merge
)
{
this
.
removeAll
();
}
for
(
var
key
in
values
)
{
if
(
values
.
hasOwnProperty
(
key
))
{
this
.
set
(
key
,
values
[
key
]);
}
}
return
this
;
};
Store
.
prototype
.
addEvent
=
function
(
selector
,
callback
)
{
if
(
!
this
.
listeners
[
selector
])
{
this
.
listeners
[
selector
]
=
[];
}
this
.
listeners
[
selector
].
push
(
callback
);
return
this
;
};
Store
.
prototype
.
removeEvent
=
function
(
selector
,
callback
)
{
for
(
var
i
=
(
this
.
listeners
[
selector
].
length
-
1
);
i
>=
0
;
i
--
)
{
if
(
this
.
listeners
[
selector
][
i
]
===
callback
)
{
this
.
listeners
[
selector
].
splice
(
i
,
1
);
}
}
if
(
this
.
listeners
[
selector
].
length
===
0
)
{
delete
this
.
listeners
[
selector
];
}
return
this
;
};
}());
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