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
084b52bd
authored
2012-07-15 14:52:19 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Revert back to only binding child elements.
1 parent
252e79dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
37 deletions
lib/rivets.js
lib/rivets.min.js
src/rivets.coffee
lib/rivets.js
View file @
084b52b
...
...
@@ -96,43 +96,51 @@
};
View
.
prototype
.
build
=
function
()
{
var
attribute
,
bindType
,
bindingRegExp
,
e
lements
,
eventRegExp
,
keypath
,
model
,
node
,
path
,
pipe
,
pipes
,
type
,
_i
,
_j
,
_len
,
_len1
,
_ref
;
var
attribute
,
bindType
,
bindingRegExp
,
e
ventRegExp
,
keypath
,
model
,
node
,
path
,
pipe
,
pipes
,
type
,
_i
,
_len
,
_ref
,
_results
;
this
.
bindings
=
[];
bindingRegExp
=
this
.
bindingRegExp
();
eventRegExp
=
/^on-/
;
elements
=
[
this
.
el
];
elements
.
concat
(
Array
.
prototype
.
slice
.
call
(
this
.
el
.
getElementsByTagName
(
'*'
)));
for
(
_i
=
0
,
_len
=
elements
.
length
;
_i
<
_len
;
_i
++
)
{
node
=
elements
[
_i
];
_ref
=
node
.
attributes
;
for
(
_j
=
0
,
_len1
=
_ref
.
length
;
_j
<
_len1
;
_j
++
)
{
attribute
=
_ref
[
_j
];
if
(
bindingRegExp
.
test
(
attribute
.
name
))
{
bindType
=
"attribute"
;
type
=
attribute
.
name
.
replace
(
bindingRegExp
,
''
);
pipes
=
(
function
()
{
var
_k
,
_len2
,
_ref1
,
_results
;
_ref1
=
attribute
.
value
.
split
(
'|'
);
_results
=
[];
for
(
_k
=
0
,
_len2
=
_ref1
.
length
;
_k
<
_len2
;
_k
++
)
{
pipe
=
_ref1
[
_k
];
_results
.
push
(
pipe
.
trim
());
_ref
=
this
.
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
(
bindingRegExp
.
test
(
attribute
.
name
))
{
bindType
=
"attribute"
;
type
=
attribute
.
name
.
replace
(
bindingRegExp
,
''
);
pipes
=
(
function
()
{
var
_k
,
_len2
,
_ref2
,
_results2
;
_ref2
=
attribute
.
value
.
split
(
'|'
);
_results2
=
[];
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
pipe
=
_ref2
[
_k
];
_results2
.
push
(
pipe
.
trim
());
}
return
_results2
;
})();
path
=
pipes
.
shift
().
split
(
'.'
);
model
=
this
.
models
[
path
.
shift
()];
keypath
=
path
.
join
(
'.'
);
if
(
eventRegExp
.
test
(
type
))
{
type
=
type
.
replace
(
eventRegExp
,
''
);
bindType
=
"event"
;
}
else
if
(
__indexOf
.
call
(
bidirectionals
,
type
)
>=
0
)
{
bindType
=
"bidirectional"
;
}
return
_results
;
})();
path
=
pipes
.
shift
().
split
(
'.'
);
model
=
this
.
models
[
path
.
shift
()];
keypath
=
path
.
join
(
'.'
);
if
(
eventRegExp
.
test
(
type
))
{
type
=
type
.
replace
(
eventRegExp
,
''
);
bindType
=
"event"
;
}
else
if
(
__indexOf
.
call
(
bidirectionals
,
type
)
>=
0
)
{
bindType
=
"bidirectional"
;
_results1
.
push
(
this
.
bindings
.
push
(
new
Rivets
.
Binding
(
node
,
type
,
bindType
,
model
,
keypath
,
pipes
)));
}
else
{
_results1
.
push
(
void
0
);
}
this
.
bindings
.
push
(
new
Rivets
.
Binding
(
node
,
type
,
bindType
,
model
,
keypath
,
pipes
));
}
}
return
_results1
;
}).
call
(
this
));
}
return
_results
;
};
View
.
prototype
.
bind
=
function
()
{
...
...
lib/rivets.min.js
View file @
084b52b
(
function
(){
var
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
=
function
(
a
,
b
){
return
function
(){
return
a
.
apply
(
b
,
arguments
)}},
j
=
[].
indexOf
||
function
(
a
){
for
(
var
b
=
0
,
c
=
this
.
length
;
b
<
c
;
b
++
)
if
(
b
in
this
&&
this
[
b
]
===
a
)
return
b
;
return
-
1
};
a
=
{},
String
.
prototype
.
trim
||
(
String
.
prototype
.
trim
=
function
(){
return
this
.
replace
(
/^
\s
+|
\s
+$/g
,
""
)}),
a
.
Binding
=
function
(){
function
c
(
c
,
d
,
f
,
g
,
h
,
j
){
this
.
el
=
c
,
this
.
type
=
d
,
this
.
bindType
=
f
,
this
.
model
=
g
,
this
.
keypath
=
h
,
this
.
formatters
=
j
!=
null
?
j
:[],
this
.
publish
=
i
(
this
.
publish
,
this
),
this
.
bind
=
i
(
this
.
bind
,
this
),
this
.
set
=
i
(
this
.
set
,
this
),
this
.
bindType
===
"event"
?
this
.
routine
=
e
(
this
.
type
):
this
.
routine
=
a
.
routines
[
this
.
type
]
||
b
(
this
.
type
)}
return
c
.
prototype
.
set
=
function
(
b
){
var
c
,
d
,
e
,
f
;
f
=
this
.
formatters
;
for
(
d
=
0
,
e
=
f
.
length
;
d
<
e
;
d
++
)
c
=
f
[
d
],
b
=
a
.
config
.
formatters
[
c
](
b
);
return
this
.
bindType
===
"event"
?(
this
.
routine
(
this
.
el
,
b
,
this
.
currentListener
),
this
.
currentListener
=
b
):
this
.
routine
(
this
.
el
,
b
)},
c
.
prototype
.
bind
=
function
(){
a
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
set
),
a
.
config
.
preloadData
&&
this
.
set
(
a
.
config
.
adapter
.
read
(
this
.
model
,
this
.
keypath
));
if
(
this
.
bindType
===
"bidirectional"
)
return
d
(
this
.
el
,
"change"
,
this
.
publish
)},
c
.
prototype
.
publish
=
function
(
b
){
var
c
;
return
c
=
b
.
target
||
b
.
srcElement
,
a
.
config
.
adapter
.
publish
(
this
.
model
,
this
.
keypath
,
f
(
c
))},
c
}(),
a
.
View
=
function
(){
function
b
(
a
,
b
){
this
.
el
=
a
,
this
.
models
=
b
,
this
.
bind
=
i
(
this
.
bind
,
this
),
this
.
build
=
i
(
this
.
build
,
this
),
this
.
bindingRegExp
=
i
(
this
.
bindingRegExp
,
this
),
this
.
el
.
jquery
&&
(
this
.
el
=
this
.
el
.
get
(
0
)),
this
.
build
()}
return
b
.
prototype
.
bindingRegExp
=
function
(){
var
b
;
return
b
=
a
.
config
.
prefix
,
b
?
new
RegExp
(
"^data-"
+
b
+
"-"
):
/^data-/
},
b
.
prototype
.
build
=
function
(){
var
b
,
d
,
e
,
f
,
g
,
h
,
i
,
k
,
l
,
m
,
n
,
o
,
p
,
q
,
r
,
s
,
t
;
this
.
bindings
=
[],
e
=
this
.
bindingRegExp
(),
g
=
/^on-/
,
f
=
[
this
.
el
],
f
.
concat
(
Array
.
prototype
.
slice
.
call
(
this
.
el
.
getElementsByTagName
(
"*"
)));
for
(
p
=
0
,
r
=
f
.
length
;
p
<
r
;
p
++
){
k
=
f
[
p
],
t
=
k
.
attributes
;
for
(
q
=
0
,
s
=
t
.
length
;
q
<
s
;
q
++
)
b
=
t
[
q
],
e
.
test
(
b
.
name
)
&&
(
d
=
"attribute"
,
o
=
b
.
name
.
replace
(
e
,
""
),
n
=
function
(){
var
a
,
c
,
d
,
e
;
d
=
b
.
value
.
split
(
"|"
),
e
=
[];
for
(
a
=
0
,
c
=
d
.
length
;
a
<
c
;
a
++
)
m
=
d
[
a
],
e
.
push
(
m
.
trim
());
return
e
}(),
l
=
n
.
shift
().
split
(
"."
),
i
=
this
.
models
[
l
.
shift
()],
h
=
l
.
join
(
"."
),
g
.
test
(
o
)?(
o
=
o
.
replace
(
g
,
""
),
d
=
"event"
):
j
.
call
(
c
,
o
)
>=
0
&&
(
d
=
"bidirectional"
),
this
.
bindings
.
push
(
new
a
.
Binding
(
k
,
o
,
d
,
i
,
h
,
n
)))}},
b
.
prototype
.
bind
=
function
(){
var
a
,
b
,
c
,
d
,
e
;
d
=
this
.
bindings
,
e
=
[];
for
(
b
=
0
,
c
=
d
.
length
;
b
<
c
;
b
++
)
a
=
d
[
b
],
e
.
push
(
a
.
bind
());
return
e
},
b
}(),
d
=
function
(
a
,
b
,
c
){
return
window
.
addEventListener
?
a
.
addEventListener
(
b
,
c
):
a
.
attachEvent
(
b
,
c
)},
h
=
function
(
a
,
b
,
c
){
return
window
.
removeEventListener
?
a
.
removeEventListener
(
b
,
c
):
a
.
detachEvent
(
b
,
c
)},
f
=
function
(
a
){
switch
(
a
.
type
){
case
"text"
:
case
"textarea"
:
case
"password"
:
case
"select-one"
:
return
a
.
value
;
case
"checkbox"
:
case
"radio"
:
return
a
.
checked
}},
e
=
function
(
a
){
return
function
(
b
,
c
,
e
){
c
&&
d
(
b
,
a
,
c
);
if
(
e
)
return
h
(
b
,
a
,
e
)}},
b
=
function
(
a
){
return
function
(
b
,
c
){
return
c
?
b
.
setAttribute
(
a
,
c
):
b
.
removeAttribute
(
a
)}},
c
=
[
"value"
,
"checked"
,
"unchecked"
,
"selected"
,
"unselected"
],
a
.
routines
=
{
enabled
:
function
(
a
,
b
){
return
a
.
disabled
=!
b
},
disabled
:
function
(
a
,
b
){
return
a
.
disabled
=!!
b
},
checked
:
function
(
a
,
b
){
return
a
.
checked
=!!
b
},
unchecked
:
function
(
a
,
b
){
return
a
.
checked
=!
b
},
selected
:
function
(
a
,
b
){
return
a
.
selected
=!!
b
},
unselected
:
function
(
a
,
b
){
return
a
.
selected
=!
b
},
show
:
function
(
a
,
b
){
return
a
.
style
.
display
=
b
?
""
:
"none"
},
hide
:
function
(
a
,
b
){
return
a
.
style
.
display
=
b
?
"none"
:
""
},
html
:
function
(
a
,
b
){
return
a
.
innerHTML
=
b
||
""
},
value
:
function
(
a
,
b
){
return
a
.
value
=
b
},
text
:
function
(
a
,
b
){
return
a
.
innerText
!=
null
?
a
.
innerText
=
b
||
""
:
a
.
textContent
=
b
||
""
}},
a
.
config
=
{
preloadData
:
!
0
},
g
=
{
configure
:
function
(
b
){
var
c
,
d
,
e
;
b
==
null
&&
(
b
=
{}),
e
=
[];
for
(
c
in
b
)
d
=
b
[
c
],
e
.
push
(
a
.
config
[
c
]
=
d
);
return
e
},
register
:
function
(
b
,
c
){
return
a
.
routines
[
b
]
=
c
},
bind
:
function
(
b
,
c
){
var
d
;
return
c
==
null
&&
(
c
=
{}),
d
=
new
a
.
View
(
b
,
c
),
d
.
bind
(),
d
}},
typeof
module
!=
"undefined"
&&
module
!==
null
?
module
.
exports
=
g
:
this
.
rivets
=
g
}).
call
(
this
);
\ No newline at end of file
(
function
(){
var
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
=
function
(
a
,
b
){
return
function
(){
return
a
.
apply
(
b
,
arguments
)}},
j
=
[].
indexOf
||
function
(
a
){
for
(
var
b
=
0
,
c
=
this
.
length
;
b
<
c
;
b
++
)
if
(
b
in
this
&&
this
[
b
]
===
a
)
return
b
;
return
-
1
};
a
=
{},
String
.
prototype
.
trim
||
(
String
.
prototype
.
trim
=
function
(){
return
this
.
replace
(
/^
\s
+|
\s
+$/g
,
""
)}),
a
.
Binding
=
function
(){
function
c
(
c
,
d
,
f
,
g
,
h
,
j
){
this
.
el
=
c
,
this
.
type
=
d
,
this
.
bindType
=
f
,
this
.
model
=
g
,
this
.
keypath
=
h
,
this
.
formatters
=
j
!=
null
?
j
:[],
this
.
publish
=
i
(
this
.
publish
,
this
),
this
.
bind
=
i
(
this
.
bind
,
this
),
this
.
set
=
i
(
this
.
set
,
this
),
this
.
bindType
===
"event"
?
this
.
routine
=
e
(
this
.
type
):
this
.
routine
=
a
.
routines
[
this
.
type
]
||
b
(
this
.
type
)}
return
c
.
prototype
.
set
=
function
(
b
){
var
c
,
d
,
e
,
f
;
f
=
this
.
formatters
;
for
(
d
=
0
,
e
=
f
.
length
;
d
<
e
;
d
++
)
c
=
f
[
d
],
b
=
a
.
config
.
formatters
[
c
](
b
);
return
this
.
bindType
===
"event"
?(
this
.
routine
(
this
.
el
,
b
,
this
.
currentListener
),
this
.
currentListener
=
b
):
this
.
routine
(
this
.
el
,
b
)},
c
.
prototype
.
bind
=
function
(){
a
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
set
),
a
.
config
.
preloadData
&&
this
.
set
(
a
.
config
.
adapter
.
read
(
this
.
model
,
this
.
keypath
));
if
(
this
.
bindType
===
"bidirectional"
)
return
d
(
this
.
el
,
"change"
,
this
.
publish
)},
c
.
prototype
.
publish
=
function
(
b
){
var
c
;
return
c
=
b
.
target
||
b
.
srcElement
,
a
.
config
.
adapter
.
publish
(
this
.
model
,
this
.
keypath
,
f
(
c
))},
c
}(),
a
.
View
=
function
(){
function
b
(
a
,
b
){
this
.
el
=
a
,
this
.
models
=
b
,
this
.
bind
=
i
(
this
.
bind
,
this
),
this
.
build
=
i
(
this
.
build
,
this
),
this
.
bindingRegExp
=
i
(
this
.
bindingRegExp
,
this
),
this
.
el
.
jquery
&&
(
this
.
el
=
this
.
el
.
get
(
0
)),
this
.
build
()}
return
b
.
prototype
.
bindingRegExp
=
function
(){
var
b
;
return
b
=
a
.
config
.
prefix
,
b
?
new
RegExp
(
"^data-"
+
b
+
"-"
):
/^data-/
},
b
.
prototype
.
build
=
function
(){
var
b
,
d
,
e
,
f
,
g
,
h
,
i
,
k
,
l
,
m
,
n
,
o
,
p
,
q
,
r
;
this
.
bindings
=
[],
e
=
this
.
bindingRegExp
(),
f
=
/^on-/
,
q
=
this
.
el
.
getElementsByTagName
(
"*"
),
r
=
[];
for
(
o
=
0
,
p
=
q
.
length
;
o
<
p
;
o
++
)
i
=
q
[
o
],
r
.
push
(
function
(){
var
o
,
p
,
q
,
r
;
q
=
i
.
attributes
,
r
=
[];
for
(
o
=
0
,
p
=
q
.
length
;
o
<
p
;
o
++
)
b
=
q
[
o
],
e
.
test
(
b
.
name
)?(
d
=
"attribute"
,
n
=
b
.
name
.
replace
(
e
,
""
),
m
=
function
(){
var
a
,
c
,
d
,
e
;
d
=
b
.
value
.
split
(
"|"
),
e
=
[];
for
(
a
=
0
,
c
=
d
.
length
;
a
<
c
;
a
++
)
l
=
d
[
a
],
e
.
push
(
l
.
trim
());
return
e
}(),
k
=
m
.
shift
().
split
(
"."
),
h
=
this
.
models
[
k
.
shift
()],
g
=
k
.
join
(
"."
),
f
.
test
(
n
)?(
n
=
n
.
replace
(
f
,
""
),
d
=
"event"
):
j
.
call
(
c
,
n
)
>=
0
&&
(
d
=
"bidirectional"
),
r
.
push
(
this
.
bindings
.
push
(
new
a
.
Binding
(
i
,
n
,
d
,
h
,
g
,
m
)))):
r
.
push
(
void
0
);
return
r
}.
call
(
this
));
return
r
},
b
.
prototype
.
bind
=
function
(){
var
a
,
b
,
c
,
d
,
e
;
d
=
this
.
bindings
,
e
=
[];
for
(
b
=
0
,
c
=
d
.
length
;
b
<
c
;
b
++
)
a
=
d
[
b
],
e
.
push
(
a
.
bind
());
return
e
},
b
}(),
d
=
function
(
a
,
b
,
c
){
return
window
.
addEventListener
?
a
.
addEventListener
(
b
,
c
):
a
.
attachEvent
(
b
,
c
)},
h
=
function
(
a
,
b
,
c
){
return
window
.
removeEventListener
?
a
.
removeEventListener
(
b
,
c
):
a
.
detachEvent
(
b
,
c
)},
f
=
function
(
a
){
switch
(
a
.
type
){
case
"text"
:
case
"textarea"
:
case
"password"
:
case
"select-one"
:
return
a
.
value
;
case
"checkbox"
:
case
"radio"
:
return
a
.
checked
}},
e
=
function
(
a
){
return
function
(
b
,
c
,
e
){
c
&&
d
(
b
,
a
,
c
);
if
(
e
)
return
h
(
b
,
a
,
e
)}},
b
=
function
(
a
){
return
function
(
b
,
c
){
return
c
?
b
.
setAttribute
(
a
,
c
):
b
.
removeAttribute
(
a
)}},
c
=
[
"value"
,
"checked"
,
"unchecked"
,
"selected"
,
"unselected"
],
a
.
routines
=
{
enabled
:
function
(
a
,
b
){
return
a
.
disabled
=!
b
},
disabled
:
function
(
a
,
b
){
return
a
.
disabled
=!!
b
},
checked
:
function
(
a
,
b
){
return
a
.
checked
=!!
b
},
unchecked
:
function
(
a
,
b
){
return
a
.
checked
=!
b
},
selected
:
function
(
a
,
b
){
return
a
.
selected
=!!
b
},
unselected
:
function
(
a
,
b
){
return
a
.
selected
=!
b
},
show
:
function
(
a
,
b
){
return
a
.
style
.
display
=
b
?
""
:
"none"
},
hide
:
function
(
a
,
b
){
return
a
.
style
.
display
=
b
?
"none"
:
""
},
html
:
function
(
a
,
b
){
return
a
.
innerHTML
=
b
||
""
},
value
:
function
(
a
,
b
){
return
a
.
value
=
b
},
text
:
function
(
a
,
b
){
return
a
.
innerText
!=
null
?
a
.
innerText
=
b
||
""
:
a
.
textContent
=
b
||
""
}},
a
.
config
=
{
preloadData
:
!
0
},
g
=
{
configure
:
function
(
b
){
var
c
,
d
,
e
;
b
==
null
&&
(
b
=
{}),
e
=
[];
for
(
c
in
b
)
d
=
b
[
c
],
e
.
push
(
a
.
config
[
c
]
=
d
);
return
e
},
register
:
function
(
b
,
c
){
return
a
.
routines
[
b
]
=
c
},
bind
:
function
(
b
,
c
){
var
d
;
return
c
==
null
&&
(
c
=
{}),
d
=
new
a
.
View
(
b
,
c
),
d
.
bind
(),
d
}},
typeof
module
!=
"undefined"
&&
module
!==
null
?
module
.
exports
=
g
:
this
.
rivets
=
g
}).
call
(
this
);
\ No newline at end of file
...
...
src/rivets.coffee
View file @
084b52b
...
...
@@ -67,9 +67,7 @@ class Rivets.View
@
bindings
=
[]
bindingRegExp
=
@
bindingRegExp
()
eventRegExp
=
/^on-/
elements
=
[
@
el
]
elements
.
concat
Array
::
slice
.
call
@
el
.
getElementsByTagName
'*'
for
node
in
elements
for
node
in
@
el
.
getElementsByTagName
'*'
for
attribute
in
node
.
attributes
if
bindingRegExp
.
test
attribute
.
name
bindType
=
"attribute"
...
...
@@ -87,9 +85,6 @@ class Rivets.View
@
bindings
.
push
new
Rivets
.
Binding
node
,
type
,
bindType
,
model
,
keypath
,
pipes
# To avoid returning the result of the loop
return
# Binds all of the current bindings for this view.
bind
:
=>
binding
.
bind
()
for
binding
in
@
bindings
...
...
Please
register
or
sign in
to post a comment