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
3a89d3a2
authored
2012-08-12 23:31:31 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add a class toggle binding, data-class-[class].
1 parent
67c5564b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
src/rivets.coffee
src/rivets.coffee
View file @
3a89d3a
...
...
@@ -17,6 +17,7 @@ class Rivets.Binding
constructor
:
(
@
el
,
@
type
,
@
model
,
@
keypath
,
@
options
=
{})
->
@
routine
=
switch
@
options
.
special
when
"event"
then
eventBinding
@
type
when
"class"
then
classBinding
@
type
when
"iteration"
then
iterationBinding
@
type
else
Rivets
.
routines
[
@
type
]
||
attributeBinding
@
type
...
...
@@ -118,6 +119,7 @@ class Rivets.View
iterator
=
null
bindingRegExp
=
@
bindingRegExp
()
eventRegExp
=
/^on-/
classRegExp
=
/^class-/
iterationRegExp
=
/^each-/
parseNode
=
(
node
)
=>
...
...
@@ -153,6 +155,10 @@ class Rivets.View
type
=
type
.
replace
eventRegExp
,
''
options
.
special
=
"event"
if
classRegExp
.
test
type
type
=
type
.
replace
classRegExp
,
''
options
.
special
=
"class"
if
iterationRegExp
.
test
type
type
=
type
.
replace
iterationRegExp
,
''
options
.
special
=
"iteration"
...
...
@@ -208,6 +214,17 @@ eventBinding = (event) -> (el, bind, unbind) ->
bindEvent
el
,
event
,
bind
if
bind
unbindEvent
el
,
event
,
unbind
if
unbind
# Returns a class binding routine for the specified class name.
classBinding
=
(
name
)
->
(
el
,
value
)
->
elClass
=
"
#{
el
.
className
}
"
hasClass
=
elClass
.
indexOf
(
"
#{
name
}
"
)
!=
-
1
if
!
value
is
hasClass
el
.
className
=
if
value
"
#{
el
.
className
}
#{
name
}
"
else
elClass
.
replace
(
"
#{
name
}
"
,
" "
).
trim
()
# Returns an iteration binding routine for the specified collection.
iterationBinding
=
(
name
)
->
(
el
,
collection
,
binding
)
->
if
binding
.
iterated
?
...
...
Please
register
or
sign in
to post a comment