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
85d3d710
authored
2012-07-01 15:46:13 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Implement configuration option for setting a data attribute prefix. [Closes #4]
1 parent
f81c4d1a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
lib/rivets.js
src/rivets.coffee
lib/rivets.js
View file @
85d3d71
...
...
@@ -60,11 +60,23 @@
this
.
build
=
__bind
(
this
.
build
,
this
);
this
.
bindingRegExp
=
__bind
(
this
.
bindingRegExp
,
this
);
this
.
build
();
}
View
.
prototype
.
bindingRegExp
=
function
()
{
var
prefix
;
prefix
=
Rivets
.
config
.
prefix
;
if
(
prefix
)
{
return
new
RegExp
(
"^data-"
+
prefix
+
"-"
);
}
else
{
return
/^data-/
;
}
};
View
.
prototype
.
build
=
function
()
{
var
attribute
,
context
,
keypath
,
node
,
path
,
type
,
_i
,
_len
,
_ref
,
_results
;
var
attribute
,
context
,
dataRegExp
,
keypath
,
node
,
path
,
type
,
_i
,
_len
,
_ref
,
_results
;
this
.
bindings
=
[];
_ref
=
this
.
el
.
getElementsByTagName
(
'*'
);
_results
=
[];
...
...
@@ -76,8 +88,9 @@
_results1
=
[];
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
attribute
=
_ref1
[
_j
];
if
(
/^data-/
.
test
(
attribute
.
name
))
{
type
=
attribute
.
name
.
replace
(
'data-'
,
''
);
dataRegExp
=
new
RegExp
(
this
.
data
,
'g'
);
if
(
this
.
bindingRegExp
().
test
(
attribute
.
name
))
{
type
=
attribute
.
name
.
replace
(
this
.
bindingRegExp
(),
''
);
path
=
attribute
.
value
.
split
(
'.'
);
context
=
this
.
contexts
[
path
.
shift
()];
keypath
=
path
.
join
(
'.'
);
...
...
src/rivets.coffee
View file @
85d3d71
...
...
@@ -37,14 +37,20 @@ class Rivets.View
constructor
:
(
@
el
,
@
contexts
)
->
@
build
()
# The regular expression used to match Rivets.js data binding attributes.
bindingRegExp
:
=>
prefix
=
Rivets
.
config
.
prefix
if
prefix
then
new
RegExp
(
"^data-
#{
prefix
}
-"
)
else
/^data-/
# Parses and builds new Rivets.Binding instances for the data bindings.
build
:
=>
@
bindings
=
[]
for
node
in
@
el
.
getElementsByTagName
'*'
for
attribute
in
node
.
attributes
if
/^data-/
.
test
attribute
.
name
type
=
attribute
.
name
.
replace
'data-'
,
''
dataRegExp
=
new
RegExp
(
@
data
,
'g'
)
if
@
bindingRegExp
().
test
attribute
.
name
type
=
attribute
.
name
.
replace
@
bindingRegExp
(),
''
path
=
attribute
.
value
.
split
'.'
context
=
@
contexts
[
path
.
shift
()]
keypath
=
path
.
join
'.'
...
...
Please
register
or
sign in
to post a comment