Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
fe9918e1
authored
2012-05-13 23:55:00 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refactor element parsing in the exposed bind function.
1 parent
ee8c7f77
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
36 deletions
lib/rivets.js
src/rivets.coffee
lib/rivets.js
View file @
fe9918e
...
...
@@ -77,36 +77,34 @@
rivets
=
{
bind
:
function
(
el
,
adapter
,
contexts
)
{
var
nodes
,
_i
,
_ref
,
_results
;
var
attribute
,
context
,
keypath
,
node
,
path
,
type
,
_i
,
_len
,
_ref
,
_results
;
if
(
contexts
==
null
)
{
contexts
=
{};
}
nodes
=
el
.
getElementsByTagName
(
'*'
);
return
(
function
()
{
_results
=
[];
for
(
var
_i
=
0
,
_ref
=
nodes
.
length
-
1
;
0
<=
_ref
?
_i
<=
_ref
:
_i
>=
_ref
;
0
<=
_ref
?
_i
++
:
_i
--
){
_results
.
push
(
_i
);
}
return
_results
;
}).
apply
(
this
).
forEach
(
function
(
n
)
{
var
node
,
_i
,
_ref
,
_results
;
node
=
nodes
[
n
];
if
(
node
.
attributes
.
length
>
0
)
{
return
(
function
()
{
_results
=
[];
for
(
var
_i
=
0
,
_ref
=
node
.
attributes
.
length
-
1
;
0
<=
_ref
?
_i
<=
_ref
:
_i
>=
_ref
;
0
<=
_ref
?
_i
++
:
_i
--
){
_results
.
push
(
_i
);
}
return
_results
;
}).
apply
(
this
).
forEach
(
function
(
n
)
{
var
attribute
,
context
,
keypath
,
path
,
type
;
attribute
=
node
.
attributes
[
n
];
_ref
=
el
.
getElementsByTagName
(
'*'
);
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
node
=
_ref
[
_i
];
_results
.
push
((
function
()
{
var
_j
,
_len1
,
_ref1
,
_results1
;
_ref1
=
node
.
attributes
;
_results1
=
[];
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
attribute
=
_ref1
[
_j
];
if
(
/^data-/
.
test
(
attribute
.
name
))
{
type
=
attribute
.
name
.
replace
(
'data-'
,
''
);
path
=
attribute
.
value
.
split
(
'.'
);
context
=
path
.
shift
();
keypath
=
path
.
join
(
'.'
);
return
registerBinding
(
node
,
adapter
,
type
,
contexts
[
context
],
keypath
);
_results1
.
push
(
registerBinding
(
node
,
adapter
,
type
,
contexts
[
context
],
keypath
));
}
else
{
_results1
.
push
(
void
0
);
}
});
}
});
}
return
_results1
;
})());
}
return
_results
;
}
};
...
...
src/rivets.coffee
View file @
fe9918e
...
...
@@ -53,21 +53,14 @@ bidirectionals = ['value', 'checked', 'unchecked', 'selected', 'unselected']
rivets
=
bind
:
(
el
,
adapter
,
contexts
=
{})
->
nodes
=
el
.
getElementsByTagName
'*'
[
0
..(
nodes
.
length
-
1
)].
forEach
(
n
)
->
node
=
nodes
[
n
]
if
node
.
attributes
.
length
>
0
[
0
..(
node
.
attributes
.
length
-
1
)].
forEach
(
n
)
->
attribute
=
node
.
attributes
[
n
]
if
/^data-/
.
test
attribute
.
name
type
=
attribute
.
name
.
replace
'data-'
,
''
path
=
attribute
.
value
.
split
'.'
context
=
path
.
shift
()
keypath
=
path
.
join
'.'
registerBinding
node
,
adapter
,
type
,
contexts
[
context
],
keypath
for
node
in
el
.
getElementsByTagName
'*'
for
attribute
in
node
.
attributes
if
/^data-/
.
test
attribute
.
name
type
=
attribute
.
name
.
replace
'data-'
,
''
path
=
attribute
.
value
.
split
'.'
context
=
path
.
shift
()
keypath
=
path
.
join
'.'
registerBinding
node
,
adapter
,
type
,
contexts
[
context
],
keypath
if
module
?
module
.
exports
=
rivets
...
...
Please
register
or
sign in
to post a comment