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
5c1a0455
Commit
5c1a0455
authored
Feb 24, 2014
by
Daniel Hug
Committed by
Sindre Sorhus
Feb 24, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close GH-862: Vanilla js improvements.
parent
67b8062c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
122 deletions
+105
-122
vanilla-examples/vanillajs/index.html
vanilla-examples/vanillajs/index.html
+1
-1
vanilla-examples/vanillajs/js/helpers.js
vanilla-examples/vanillajs/js/helpers.js
+11
-7
vanilla-examples/vanillajs/js/view.js
vanilla-examples/vanillajs/js/view.js
+93
-114
No files found.
vanilla-examples/vanillajs/index.html
View file @
5c1a0455
...
...
@@ -20,7 +20,7 @@
<span
id=
"todo-count"
></span>
<ul
id=
"filters"
>
<li>
<a
href=
"#/"
>
All
</a>
<a
href=
"#/"
class=
"selected"
>
All
</a>
</li>
<li>
<a
href=
"#/active"
>
Active
</a>
...
...
vanilla-examples/vanillajs/js/helpers.js
View file @
5c1a0455
...
...
@@ -2,9 +2,13 @@
(
function
(
window
)
{
'
use strict
'
;
// Cache the querySelector/All for easier and faster reuse
window
.
$
=
document
.
querySelectorAll
.
bind
(
document
);
window
.
$$
=
document
.
querySelector
.
bind
(
document
);
// Get element(s) by CSS selector:
window
.
qs
=
function
(
selector
,
scope
)
{
return
(
scope
||
document
).
querySelector
(
selector
);
};
window
.
qsa
=
function
(
selector
,
scope
)
{
return
(
scope
||
document
).
querySelectorAll
(
selector
);
};
// Register events on elements that may or may not exist yet:
// $live('div a', 'click', function (event) {});
...
...
@@ -15,11 +19,11 @@
var
targetElement
=
event
.
target
;
eventRegistry
[
event
.
type
].
forEach
(
function
(
entry
)
{
var
potentialElements
=
document
.
querySelectorAll
(
entry
.
selector
);
var
potentialElements
=
window
.
qsa
(
entry
.
selector
);
var
hasMatch
=
Array
.
prototype
.
indexOf
.
call
(
potentialElements
,
targetElement
)
>=
0
;
if
(
hasMatch
)
{
entry
.
handler
(
event
);
entry
.
handler
.
call
(
targetElement
,
event
);
}
});
}
...
...
@@ -38,7 +42,7 @@
}());
// Find the element's parent with the given tag name:
// $parent(
$$
('a'), 'div');
// $parent(
qs
('a'), 'div');
window
.
$parent
=
function
(
element
,
tagName
)
{
if
(
!
element
.
parentNode
)
{
return
;
...
...
@@ -50,6 +54,6 @@
};
// Allow for looping on nodes by chaining:
//
$
('.foo').forEach(function () {})
//
qsa
('.foo').forEach(function () {})
NodeList
.
prototype
.
forEach
=
Array
.
prototype
.
forEach
;
})(
window
);
vanilla-examples/vanillajs/js/view.js
View file @
5c1a0455
This diff is collapsed.
Click to expand it.
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