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
19a39894
authored
2012-07-21 16:51:00 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Change the formatter arguments to be whitespace separated.
1 parent
2bd579cc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
3 deletions
lib/rivets.js
lib/rivets.min.js
src/rivets.coffee
lib/rivets.js
View file @
19a3989
...
...
@@ -43,7 +43,7 @@
_ref
=
this
.
formatters
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
formatter
=
_ref
[
_i
];
args
=
formatter
.
split
(
/
\
W
+/
);
args
=
formatter
.
split
(
/
\
s
+/
);
id
=
args
.
shift
();
value
=
(
_ref1
=
Rivets
.
config
.
formatters
)[
id
].
apply
(
_ref1
,
[
value
].
concat
(
__slice
.
call
(
args
)));
}
...
...
lib/rivets.min.js
View file @
19a3989
(
function
(){
var
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
=
function
(
a
,
b
){
return
function
(){
return
a
.
apply
(
b
,
arguments
)}},
j
=
[].
slice
,
k
=
[].
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
.
unbind
=
i
(
this
.
unbind
,
this
),
this
.
publish
=
i
(
this
.
publish
,
this
),
this
.
bind
=
i
(
this
.
bind
,
this
),
this
.
set
=
i
(
this
.
set
,
this
),
this
.
formattedValue
=
i
(
this
.
formattedValue
,
this
),
this
.
bindType
===
"event"
?
this
.
routine
=
e
(
this
.
type
):
this
.
routine
=
a
.
routines
[
this
.
type
]
||
b
(
this
.
type
)}
return
c
.
prototype
.
formattedValue
=
function
(
b
){
var
c
,
d
,
e
,
f
,
g
,
h
,
i
;
h
=
this
.
formatters
;
for
(
f
=
0
,
g
=
h
.
length
;
f
<
g
;
f
++
)
d
=
h
[
f
],
c
=
d
.
split
(
/
\W
+/
),
e
=
c
.
shift
(),
b
=
(
i
=
a
.
config
.
formatters
)[
e
].
apply
(
i
,[
b
].
concat
(
j
.
call
(
c
)));
return
b
},
c
.
prototype
.
set
=
function
(
a
){
return
a
=
this
.
formattedValue
(
a
),
this
.
bindType
===
"event"
?(
this
.
routine
(
this
.
el
,
a
,
this
.
currentListener
),
this
.
currentListener
=
a
):
this
.
routine
(
this
.
el
,
a
)},
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
.
prototype
.
unbind
=
function
(){
a
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
set
);
if
(
this
.
bindType
===
"bidirectional"
)
return
this
.
el
.
removeEventListener
(
"change"
,
this
.
publish
)},
c
}(),
a
.
View
=
function
(){
function
b
(
a
,
b
){
this
.
el
=
a
,
this
.
models
=
b
,
this
.
unbind
=
i
(
this
.
unbind
,
this
),
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
,
j
,
l
=
this
;
this
.
bindings
=
[],
b
=
this
.
bindingRegExp
(),
d
=
/^on-/
,
f
=
function
(
e
){
var
f
,
g
,
h
,
i
,
j
,
m
,
n
,
o
,
p
,
q
,
r
,
s
;
r
=
e
.
attributes
,
s
=
[];
for
(
p
=
0
,
q
=
r
.
length
;
p
<
q
;
p
++
)
f
=
r
[
p
],
b
.
test
(
f
.
name
)?(
g
=
"attribute"
,
o
=
f
.
name
.
replace
(
b
,
""
),
n
=
function
(){
var
a
,
b
,
c
,
d
;
c
=
f
.
value
.
split
(
"|"
),
d
=
[];
for
(
a
=
0
,
b
=
c
.
length
;
a
<
b
;
a
++
)
m
=
c
[
a
],
d
.
push
(
m
.
trim
());
return
d
}(),
j
=
n
.
shift
().
split
(
"."
),
i
=
l
.
models
[
j
.
shift
()],
h
=
j
.
join
(
"."
),
d
.
test
(
o
)?(
o
=
o
.
replace
(
d
,
""
),
g
=
"event"
):
k
.
call
(
c
,
o
)
>=
0
&&
(
g
=
"bidirectional"
),
s
.
push
(
l
.
bindings
.
push
(
new
a
.
Binding
(
e
,
o
,
g
,
i
,
h
,
n
)))):
s
.
push
(
void
0
);
return
s
},
f
(
this
.
el
),
i
=
this
.
el
.
getElementsByTagName
(
"*"
),
j
=
[];
for
(
g
=
0
,
h
=
i
.
length
;
g
<
h
;
g
++
)
e
=
i
[
g
],
j
.
push
(
f
(
e
));
return
j
},
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
.
prototype
.
unbind
=
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
.
unbind
());
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"
:
case
"radio"
:
return
a
.
value
;
case
"checkbox"
:
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"
],
a
.
routines
=
{
enabled
:
function
(
a
,
b
){
return
a
.
disabled
=!
b
},
disabled
:
function
(
a
,
b
){
return
a
.
disabled
=!!
b
},
checked
:
function
(
a
,
b
){
return
a
.
type
===
"radio"
?
a
.
checked
=
a
.
value
===
b
:
a
.
checked
=!!
b
},
unchecked
:
function
(
a
,
b
){
return
a
.
type
===
"radio"
?
a
.
checked
=
a
.
value
!==
b
:
a
.
checked
=!
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
=
{
routines
:
a
.
routines
,
config
:
a
.
config
,
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
},
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
=
[].
slice
,
k
=
[].
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
.
unbind
=
i
(
this
.
unbind
,
this
),
this
.
publish
=
i
(
this
.
publish
,
this
),
this
.
bind
=
i
(
this
.
bind
,
this
),
this
.
set
=
i
(
this
.
set
,
this
),
this
.
formattedValue
=
i
(
this
.
formattedValue
,
this
),
this
.
bindType
===
"event"
?
this
.
routine
=
e
(
this
.
type
):
this
.
routine
=
a
.
routines
[
this
.
type
]
||
b
(
this
.
type
)}
return
c
.
prototype
.
formattedValue
=
function
(
b
){
var
c
,
d
,
e
,
f
,
g
,
h
,
i
;
h
=
this
.
formatters
;
for
(
f
=
0
,
g
=
h
.
length
;
f
<
g
;
f
++
)
d
=
h
[
f
],
c
=
d
.
split
(
/
\s
+/
),
e
=
c
.
shift
(),
b
=
(
i
=
a
.
config
.
formatters
)[
e
].
apply
(
i
,[
b
].
concat
(
j
.
call
(
c
)));
return
b
},
c
.
prototype
.
set
=
function
(
a
){
return
a
=
this
.
formattedValue
(
a
),
this
.
bindType
===
"event"
?(
this
.
routine
(
this
.
el
,
a
,
this
.
currentListener
),
this
.
currentListener
=
a
):
this
.
routine
(
this
.
el
,
a
)},
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
.
prototype
.
unbind
=
function
(){
a
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
set
);
if
(
this
.
bindType
===
"bidirectional"
)
return
this
.
el
.
removeEventListener
(
"change"
,
this
.
publish
)},
c
}(),
a
.
View
=
function
(){
function
b
(
a
,
b
){
this
.
el
=
a
,
this
.
models
=
b
,
this
.
unbind
=
i
(
this
.
unbind
,
this
),
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
,
j
,
l
=
this
;
this
.
bindings
=
[],
b
=
this
.
bindingRegExp
(),
d
=
/^on-/
,
f
=
function
(
e
){
var
f
,
g
,
h
,
i
,
j
,
m
,
n
,
o
,
p
,
q
,
r
,
s
;
r
=
e
.
attributes
,
s
=
[];
for
(
p
=
0
,
q
=
r
.
length
;
p
<
q
;
p
++
)
f
=
r
[
p
],
b
.
test
(
f
.
name
)?(
g
=
"attribute"
,
o
=
f
.
name
.
replace
(
b
,
""
),
n
=
function
(){
var
a
,
b
,
c
,
d
;
c
=
f
.
value
.
split
(
"|"
),
d
=
[];
for
(
a
=
0
,
b
=
c
.
length
;
a
<
b
;
a
++
)
m
=
c
[
a
],
d
.
push
(
m
.
trim
());
return
d
}(),
j
=
n
.
shift
().
split
(
"."
),
i
=
l
.
models
[
j
.
shift
()],
h
=
j
.
join
(
"."
),
d
.
test
(
o
)?(
o
=
o
.
replace
(
d
,
""
),
g
=
"event"
):
k
.
call
(
c
,
o
)
>=
0
&&
(
g
=
"bidirectional"
),
s
.
push
(
l
.
bindings
.
push
(
new
a
.
Binding
(
e
,
o
,
g
,
i
,
h
,
n
)))):
s
.
push
(
void
0
);
return
s
},
f
(
this
.
el
),
i
=
this
.
el
.
getElementsByTagName
(
"*"
),
j
=
[];
for
(
g
=
0
,
h
=
i
.
length
;
g
<
h
;
g
++
)
e
=
i
[
g
],
j
.
push
(
f
(
e
));
return
j
},
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
.
prototype
.
unbind
=
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
.
unbind
());
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"
:
case
"radio"
:
return
a
.
value
;
case
"checkbox"
:
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"
],
a
.
routines
=
{
enabled
:
function
(
a
,
b
){
return
a
.
disabled
=!
b
},
disabled
:
function
(
a
,
b
){
return
a
.
disabled
=!!
b
},
checked
:
function
(
a
,
b
){
return
a
.
type
===
"radio"
?
a
.
checked
=
a
.
value
===
b
:
a
.
checked
=!!
b
},
unchecked
:
function
(
a
,
b
){
return
a
.
type
===
"radio"
?
a
.
checked
=
a
.
value
!==
b
:
a
.
checked
=!
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
=
{
routines
:
a
.
routines
,
config
:
a
.
config
,
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
},
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 @
19a3989
...
...
@@ -24,7 +24,7 @@ class Rivets.Binding
# formatted value.
formattedValue
:
(
value
)
=>
for
formatter
in
@
formatters
args
=
formatter
.
split
/\
W
+/
args
=
formatter
.
split
/\
s
+/
id
=
args
.
shift
()
value
=
Rivets
.
config
.
formatters
[
id
]
value
,
args
...
...
...
Please
register
or
sign in
to post a comment