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
d9e1bb5d
authored
2012-05-12 16:22:52 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Export library for both CommonJS and the browser.
1 parent
4f30463c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
12 deletions
lib/rivets.js
src/rivets.coffee
lib/rivets.js
View file @
d9e1bb5
// Generated by CoffeeScript 1.3.1
(
function
()
{
var
__indexOf
=
[].
indexOf
||
function
(
item
)
{
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
if
(
i
in
this
&&
this
[
i
]
===
item
)
return
i
;
}
return
-
1
;
};
var
attributeBinding
,
bidirectionalBindings
,
bindings
,
getInputValue
,
registerBinding
,
rivets
,
setAttribute
,
__indexOf
=
[].
indexOf
||
function
(
item
)
{
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
if
(
i
in
this
&&
this
[
i
]
===
item
)
return
i
;
}
return
-
1
;
};
window
.
rivets
=
(
function
()
{
var
attributeBinding
,
bidirectionalBindings
,
bindings
,
getInputValue
,
registerBinding
,
setAttribute
;
registerBinding
=
function
(
el
,
adapter
,
type
,
context
,
keypath
)
{
var
bind
;
bind
=
bindings
[
type
]
||
attributeBinding
(
type
);
...
...
@@ -17,6 +16,7 @@
});
}
};
setAttribute
=
function
(
el
,
attr
,
value
,
mirrored
)
{
if
(
mirrored
==
null
)
{
mirrored
=
false
;
...
...
@@ -27,6 +27,7 @@
return
el
.
removeAttribute
(
attr
);
}
};
getInputValue
=
function
(
el
)
{
switch
(
el
.
type
)
{
case
'text'
:
...
...
@@ -38,6 +39,7 @@
return
el
.
checked
;
}
};
bindings
=
{
show
:
function
(
el
,
value
)
{
return
el
.
style
.
display
=
value
?
''
:
'none'
;
...
...
@@ -70,13 +72,16 @@
return
el
.
value
=
value
;
}
};
attributeBinding
=
function
(
attr
)
{
return
function
(
el
,
value
)
{
return
setAttribute
(
el
,
attr
,
value
);
};
};
bidirectionalBindings
=
[
'value'
,
'checked'
,
'unchecked'
,
'selected'
,
'unselected'
];
return
{
rivets
=
{
bind
:
function
(
el
,
adapter
,
contexts
)
{
var
nodes
,
_i
,
_ref
,
_results
;
if
(
contexts
==
null
)
{
...
...
@@ -110,6 +115,11 @@
});
}
};
})();
if
(
typeof
module
!==
"undefined"
&&
module
!==
null
)
{
module
.
exports
=
rivets
;
}
else
{
this
.
rivets
=
rivets
;
}
}).
call
(
this
);
...
...
src/rivets.coffee
View file @
d9e1bb5
...
...
@@ -3,8 +3,7 @@
# author : Michael Richards
# license : MIT
window
.
rivets
=
do
->
registerBinding
=
(
el
,
adapter
,
type
,
context
,
keypath
)
->
registerBinding
=
(
el
,
adapter
,
type
,
context
,
keypath
)
->
bind
=
bindings
[
type
]
||
attributeBinding
type
bind
el
,
adapter
.
read
context
,
keypath
...
...
@@ -15,18 +14,18 @@ window.rivets = do ->
el
.
addEventListener
'change'
,
->
adapter
.
publish
context
,
keypath
,
getInputValue
this
setAttribute
=
(
el
,
attr
,
value
,
mirrored
=
false
)
->
setAttribute
=
(
el
,
attr
,
value
,
mirrored
=
false
)
->
if
value
el
.
setAttribute
attr
,
if
mirrored
then
attr
else
value
else
el
.
removeAttribute
attr
getInputValue
=
(
el
)
->
getInputValue
=
(
el
)
->
switch
el
.
type
when
'text'
,
'textarea'
,
'password'
,
'select-one'
then
el
.
value
when
'checkbox'
then
el
.
checked
bindings
=
bindings
=
show
:
(
el
,
value
)
->
el
.
style
.
display
=
if
value
then
''
else
'none'
hide
:
(
el
,
value
)
->
...
...
@@ -48,12 +47,13 @@ window.rivets = do ->
value
:
(
el
,
value
)
->
el
.
value
=
value
attributeBinding
=
(
attr
)
->
attributeBinding
=
(
attr
)
->
(
el
,
value
)
->
setAttribute
el
,
attr
,
value
bidirectionalBindings
=
[
'value'
,
'checked'
,
'unchecked'
,
'selected'
,
'unselected'
]
bidirectionalBindings
=
[
'value'
,
'checked'
,
'unchecked'
,
'selected'
,
'unselected'
]
rivets
=
bind
:
(
el
,
adapter
,
contexts
=
{})
->
nodes
=
el
.
getElementsByTagName
'*'
...
...
@@ -70,3 +70,8 @@ window.rivets = do ->
context
=
path
.
shift
()
keypath
=
path
.
join
'.'
registerBinding
node
,
adapter
,
type
,
contexts
[
context
],
keypath
if
module
?
module
.
exports
=
rivets
else
@
rivets
=
rivets
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment