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
e0a4fdc8
authored
2012-10-23 18:27:32 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Build 0.4.0.
1 parent
d0b185b9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
176 additions
and
164 deletions
lib/rivets.js
lib/rivets.min.js
package.json
src/rivets.coffee
lib/rivets.js
View file @
e0a4fdc
// rivets.js
// version: 0.
3.13
// version: 0.
4.0
// author: Michael Richards
// license: MIT
(
function
()
{
var
Rivets
,
attributeBinding
,
bindEvent
,
classBinding
,
eventBinding
,
getInputValue
,
iterationBinding
,
rivets
,
unbindEvent
,
var
Rivets
,
bindEvent
,
getInputValue
,
rivets
,
unbindEvent
,
__bind
=
function
(
fn
,
me
){
return
function
(){
return
fn
.
apply
(
me
,
arguments
);
};
},
__slice
=
[].
slice
,
__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
;
};
...
...
@@ -19,6 +19,7 @@
Rivets
.
Binding
=
(
function
()
{
function
Binding
(
el
,
type
,
model
,
keypath
,
options
)
{
var
identifier
,
regexp
,
value
,
_ref
;
this
.
el
=
el
;
this
.
type
=
type
;
this
.
model
=
model
;
...
...
@@ -36,27 +37,28 @@
this
.
formattedValue
=
__bind
(
this
.
formattedValue
,
this
);
this
.
isBidirectional
=
__bind
(
this
.
isBidirectional
,
this
);
this
.
routine
=
(
function
()
{
switch
(
this
.
options
.
special
)
{
case
'event'
:
return
eventBinding
(
this
.
type
);
case
'class'
:
return
classBinding
(
this
.
type
);
case
'iteration'
:
return
iterationBinding
(
this
.
type
);
default
:
return
Rivets
.
routines
[
this
.
type
]
||
attributeBinding
(
this
.
type
);
if
(
!
(
this
.
binder
=
Rivets
.
binders
[
type
]))
{
_ref
=
Rivets
.
binders
;
for
(
identifier
in
_ref
)
{
value
=
_ref
[
identifier
];
if
(
identifier
!==
'*'
&&
identifier
.
indexOf
(
'*'
)
!==
-
1
)
{
regexp
=
new
RegExp
(
"^"
+
(
identifier
.
replace
(
'*'
,
'.+'
))
+
"$"
);
if
(
regexp
.
test
(
type
))
{
this
.
binder
=
value
;
this
.
args
=
new
RegExp
(
"^"
+
(
identifier
.
replace
(
'*'
,
'(.+)'
))
+
"$"
).
exec
(
type
);
this
.
args
.
shift
();
}
}).
call
(
this
);
this
.
formatters
=
this
.
options
.
formatters
||
[];
}
Binding
.
prototype
.
isBidirectional
=
function
()
{
var
_ref
;
return
(
_ref
=
this
.
type
)
===
'value'
||
_ref
===
'checked'
||
_ref
===
'unchecked'
;
}
}
this
.
binder
||
(
this
.
binder
=
Rivets
.
binders
[
'*'
]);
if
(
this
.
binder
instanceof
Function
)
{
this
.
binder
=
{
routine
:
this
.
binder
};
}
this
.
formatters
=
this
.
options
.
formatters
||
[];
}
Binding
.
prototype
.
formattedValue
=
function
(
value
)
{
var
args
,
formatter
,
id
,
_i
,
_len
,
_ref
,
_ref1
,
_ref2
;
...
...
@@ -71,14 +73,9 @@
};
Binding
.
prototype
.
set
=
function
(
value
)
{
value
=
value
instanceof
Function
&&
this
.
options
.
special
!==
'event'
?
this
.
formattedValue
(
value
.
call
(
this
.
model
))
:
this
.
formattedValue
(
value
);
if
(
this
.
options
.
special
===
'event'
)
{
return
this
.
currentListener
=
this
.
routine
(
this
.
el
,
this
.
model
,
value
,
this
.
currentListener
);
}
else
if
(
this
.
options
.
special
===
'iteration'
)
{
return
this
.
routine
(
this
.
el
,
value
,
this
);
}
else
{
return
this
.
routine
(
this
.
el
,
value
);
}
var
_ref
;
value
=
value
instanceof
Function
&&
!
this
.
binder
[
"function"
]
?
this
.
formattedValue
(
value
.
call
(
this
.
model
))
:
this
.
formattedValue
(
value
);
return
(
_ref
=
this
.
binder
.
routine
)
!=
null
?
_ref
.
call
(
this
,
this
.
el
,
value
)
:
void
0
;
};
Binding
.
prototype
.
sync
=
function
()
{
...
...
@@ -90,23 +87,23 @@
};
Binding
.
prototype
.
bind
=
function
()
{
var
dependency
,
keypath
,
model
,
_i
,
_len
,
_ref
,
_ref1
,
_results
;
var
dependency
,
keypath
,
model
,
_i
,
_len
,
_ref
,
_ref1
,
_re
f2
,
_re
sults
;
if
(
this
.
options
.
bypass
)
{
this
.
sync
();
}
else
{
if
((
_ref
=
this
.
binder
.
bind
)
!=
null
)
{
_ref
.
call
(
this
,
this
.
el
);
}
Rivets
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
);
if
(
Rivets
.
config
.
preloadData
)
{
this
.
sync
();
}
if
(
this
.
isBidirectional
())
{
bindEvent
(
this
.
el
,
'change'
,
this
.
publish
);
}
}
if
((
_ref
=
this
.
options
.
dependencies
)
!=
null
?
_ref
.
length
:
void
0
)
{
_ref
1
=
this
.
options
.
dependencies
;
if
((
_ref
1
=
this
.
options
.
dependencies
)
!=
null
?
_ref1
.
length
:
void
0
)
{
_ref
2
=
this
.
options
.
dependencies
;
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
1
.
length
;
_i
<
_len
;
_i
++
)
{
dependency
=
_ref
1
[
_i
];
for
(
_i
=
0
,
_len
=
_ref
2
.
length
;
_i
<
_len
;
_i
++
)
{
dependency
=
_ref
2
[
_i
];
if
(
/^
\.
/
.
test
(
dependency
))
{
model
=
this
.
model
;
keypath
=
dependency
.
substr
(
1
);
...
...
@@ -122,18 +119,18 @@
};
Binding
.
prototype
.
unbind
=
function
()
{
var
keypath
,
_i
,
_len
,
_ref
,
_ref1
,
_results
;
var
keypath
,
_i
,
_len
,
_ref
,
_ref1
,
_re
f2
,
_re
sults
;
if
(
!
this
.
options
.
bypass
)
{
Rivets
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
);
if
(
this
.
isBidirectional
())
{
unbindEvent
(
this
.
el
,
'change'
,
this
.
publish
);
if
((
_ref
=
this
.
binder
.
unbind
)
!=
null
)
{
_ref
.
call
(
this
,
this
.
el
);
}
Rivets
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
);
}
if
((
_ref
=
this
.
options
.
dependencies
)
!=
null
?
_ref
.
length
:
void
0
)
{
_ref
1
=
this
.
options
.
dependencies
;
if
((
_ref
1
=
this
.
options
.
dependencies
)
!=
null
?
_ref1
.
length
:
void
0
)
{
_ref
2
=
this
.
options
.
dependencies
;
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
1
.
length
;
_i
<
_len
;
_i
++
)
{
keypath
=
_ref
1
[
_i
];
for
(
_i
=
0
,
_len
=
_ref
2
.
length
;
_i
<
_len
;
_i
++
)
{
keypath
=
_ref
2
[
_i
];
_results
.
push
(
Rivets
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
keypath
,
this
.
sync
));
}
return
_results
;
...
...
@@ -180,57 +177,64 @@
};
View
.
prototype
.
build
=
function
()
{
var
bindingRegExp
,
classRegExp
,
el
,
eventRegExp
,
iterationRegExp
,
iterator
,
node
,
parseNode
,
skipNodes
,
_i
,
_j
,
_len
,
_len1
,
_ref
,
_ref1
,
var
bindingRegExp
,
el
,
node
,
parseNode
,
skipNodes
,
_i
,
_j
,
_len
,
_len1
,
_ref
,
_ref1
,
_this
=
this
;
this
.
bindings
=
[];
skipNodes
=
[];
iterator
=
null
;
bindingRegExp
=
this
.
bindingRegExp
();
eventRegExp
=
/^on-/
;
classRegExp
=
/^class-/
;
iterationRegExp
=
/^each-/
;
parseNode
=
function
(
node
)
{
var
a
,
attribute
,
binding
,
context
,
ctx
,
dependencies
,
keypath
,
model
,
n
,
options
,
path
,
pipe
,
pipes
,
splitPath
,
type
,
_i
,
_j
,
_k
,
_l
,
_len
,
_len1
,
_len2
,
_len3
,
_ref
,
_ref1
,
_ref2
;
var
a
ttribute
,
attributes
,
binder
,
binding
,
context
,
ctx
,
dependencies
,
identifier
,
keypath
,
model
,
n
,
options
,
path
,
pipe
,
pipes
,
regexp
,
splitPath
,
type
,
value
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
,
_ref3
;
if
(
__indexOf
.
call
(
skipNodes
,
node
)
<
0
)
{
_ref
=
node
.
attributes
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
attribute
=
_ref
[
_i
];
if
(
bindingRegExp
.
test
(
attribute
.
name
))
{
type
=
attribute
.
name
.
replace
(
bindingRegExp
,
''
);
if
(
iterationRegExp
.
test
(
type
))
{
if
(
!
_this
.
models
[
type
.
replace
(
iterationRegExp
,
''
)])
{
_ref1
=
node
.
getElementsByTagName
(
'*'
);
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
n
=
_ref1
[
_j
];
skipNodes
.
push
(
n
);
if
(
!
(
binder
=
Rivets
.
binders
[
type
]))
{
_ref1
=
Rivets
.
binders
;
for
(
identifier
in
_ref1
)
{
value
=
_ref1
[
identifier
];
if
(
identifier
!==
'*'
&&
identifier
.
indexOf
(
'*'
)
!==
-
1
)
{
regexp
=
new
RegExp
(
"^"
+
(
identifier
.
replace
(
'*'
,
'.+'
))
+
"$"
);
if
(
regexp
.
test
(
type
))
{
binder
=
value
;
}
}
}
iterator
=
[
attribute
];
}
binder
||
(
binder
=
Rivets
.
binders
[
'*'
]);
if
(
binder
.
block
)
{
_ref2
=
node
.
getElementsByTagName
(
'*'
);
for
(
_j
=
0
,
_len1
=
_ref2
.
length
;
_j
<
_len1
;
_j
++
)
{
n
=
_ref2
[
_j
];
skipNodes
.
push
(
n
);
}
attributes
=
[
attribute
];
}
}
}
_ref
2
=
iterator
||
node
.
attributes
;
for
(
_k
=
0
,
_len2
=
_ref
2
.
length
;
_k
<
_len2
;
_k
++
)
{
attribute
=
_ref
2
[
_k
];
_ref
3
=
attributes
||
node
.
attributes
;
for
(
_k
=
0
,
_len2
=
_ref
3
.
length
;
_k
<
_len2
;
_k
++
)
{
attribute
=
_ref
3
[
_k
];
if
(
bindingRegExp
.
test
(
attribute
.
name
))
{
options
=
{};
type
=
attribute
.
name
.
replace
(
bindingRegExp
,
''
);
pipes
=
(
function
()
{
var
_l
,
_len3
,
_ref
3
,
_results
;
_ref
3
=
attribute
.
value
.
split
(
'|'
);
var
_l
,
_len3
,
_ref
4
,
_results
;
_ref
4
=
attribute
.
value
.
split
(
'|'
);
_results
=
[];
for
(
_l
=
0
,
_len3
=
_ref
3
.
length
;
_l
<
_len3
;
_l
++
)
{
pipe
=
_ref
3
[
_l
];
for
(
_l
=
0
,
_len3
=
_ref
4
.
length
;
_l
<
_len3
;
_l
++
)
{
pipe
=
_ref
4
[
_l
];
_results
.
push
(
pipe
.
trim
());
}
return
_results
;
})();
context
=
(
function
()
{
var
_l
,
_len3
,
_ref
3
,
_results
;
_ref
3
=
pipes
.
shift
().
split
(
'<'
);
var
_l
,
_len3
,
_ref
4
,
_results
;
_ref
4
=
pipes
.
shift
().
split
(
'<'
);
_results
=
[];
for
(
_l
=
0
,
_len3
=
_ref
3
.
length
;
_l
<
_len3
;
_l
++
)
{
ctx
=
_ref
3
[
_l
];
for
(
_l
=
0
,
_len3
=
_ref
4
.
length
;
_l
<
_len3
;
_l
++
)
{
ctx
=
_ref
4
[
_l
];
_results
.
push
(
ctx
.
trim
());
}
return
_results
;
...
...
@@ -250,30 +254,14 @@
if
(
dependencies
=
context
.
shift
())
{
options
.
dependencies
=
dependencies
.
split
(
/
\s
+/
);
}
if
(
eventRegExp
.
test
(
type
))
{
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'
;
}
binding
=
new
Rivets
.
Binding
(
node
,
type
,
model
,
keypath
,
options
);
binding
.
view
=
_this
;
_this
.
bindings
.
push
(
binding
);
}
}
if
(
iterator
)
{
for
(
_l
=
0
,
_len3
=
iterator
.
length
;
_l
<
_len3
;
_l
++
)
{
a
=
iterator
[
_l
];
node
.
removeAttribute
(
a
.
name
);
}
iterator
=
null
;
}
if
(
attributes
)
{
attributes
=
null
;
}
}
};
...
...
@@ -338,7 +326,7 @@
View
.
prototype
.
publish
=
function
()
{
var
binding
,
_i
,
_len
,
_ref
,
_results
;
_ref
=
this
.
select
(
function
(
b
)
{
return
b
.
isBidirectional
()
;
return
b
.
binder
.
publishes
;
});
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
...
...
@@ -409,94 +397,44 @@
}
};
eventBinding
=
function
(
event
)
{
return
function
(
el
,
context
,
bind
,
unbind
)
{
if
(
unbind
)
{
unbindEvent
(
el
,
event
,
unbind
);
}
return
bindEvent
(
el
,
event
,
bind
,
context
);
};
};
classBinding
=
function
(
name
)
{
return
function
(
el
,
value
)
{
var
elClass
,
hasClass
;
elClass
=
" "
+
el
.
className
+
" "
;
hasClass
=
elClass
.
indexOf
(
" "
+
name
+
" "
)
!==
-
1
;
if
(
!
value
===
hasClass
)
{
return
el
.
className
=
value
?
""
+
el
.
className
+
" "
+
name
:
elClass
.
replace
(
" "
+
name
+
" "
,
' '
).
trim
();
}
};
};
iterationBinding
=
function
(
name
)
{
return
function
(
el
,
collection
,
binding
)
{
var
data
,
item
,
itemEl
,
iteration
,
m
,
n
,
previous
,
_i
,
_j
,
_len
,
_len1
,
_ref
,
_ref1
,
_ref2
,
_results
;
if
(
binding
.
iterated
!=
null
)
{
_ref
=
binding
.
iterated
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
iteration
=
_ref
[
_i
];
iteration
.
view
.
unbind
();
iteration
.
el
.
parentNode
.
removeChild
(
iteration
.
el
);
}
}
else
{
binding
.
marker
=
document
.
createComment
(
" rivets: each-"
+
name
+
" "
);
el
.
parentNode
.
insertBefore
(
binding
.
marker
,
el
);
el
.
parentNode
.
removeChild
(
el
);
}
binding
.
iterated
=
[];
_results
=
[];
for
(
_j
=
0
,
_len1
=
collection
.
length
;
_j
<
_len1
;
_j
++
)
{
item
=
collection
[
_j
];
data
=
{};
_ref1
=
binding
.
view
.
models
;
for
(
n
in
_ref1
)
{
m
=
_ref1
[
n
];
data
[
n
]
=
m
;
}
data
[
name
]
=
item
;
itemEl
=
el
.
cloneNode
(
true
);
previous
=
binding
.
iterated
[
binding
.
iterated
.
length
-
1
]
||
binding
.
marker
;
binding
.
marker
.
parentNode
.
insertBefore
(
itemEl
,
(
_ref2
=
previous
.
nextSibling
)
!=
null
?
_ref2
:
null
);
_results
.
push
(
binding
.
iterated
.
push
({
el
:
itemEl
,
view
:
rivets
.
bind
(
itemEl
,
data
)
}));
}
return
_results
;
};
};
attributeBinding
=
function
(
attr
)
{
return
function
(
el
,
value
)
{
if
(
value
)
{
return
el
.
setAttribute
(
attr
,
value
);
}
else
{
return
el
.
removeAttribute
(
attr
);
}
};
};
Rivets
.
routines
=
{
Rivets
.
binders
=
{
enabled
:
function
(
el
,
value
)
{
return
el
.
disabled
=
!
value
;
},
disabled
:
function
(
el
,
value
)
{
return
el
.
disabled
=
!!
value
;
},
checked
:
function
(
el
,
value
)
{
checked
:
{
publishes
:
true
,
bind
:
function
(
el
)
{
return
bindEvent
(
el
,
'change'
,
this
.
publish
);
},
unbind
:
function
(
el
)
{
return
unbindEvent
(
el
,
'change'
,
this
.
publish
);
},
routine
:
function
(
el
,
value
)
{
if
(
el
.
type
===
'radio'
)
{
return
el
.
checked
=
el
.
value
===
value
;
}
else
{
return
el
.
checked
=
!!
value
;
}
}
},
unchecked
:
{
publishes
:
true
,
bind
:
function
(
el
)
{
return
bindEvent
(
el
,
'change'
,
this
.
publish
);
},
unbind
:
function
(
el
)
{
return
unbindEvent
(
el
,
'change'
,
this
.
publish
);
},
unchecked
:
function
(
el
,
value
)
{
routine
:
function
(
el
,
value
)
{
if
(
el
.
type
===
'radio'
)
{
return
el
.
checked
=
el
.
value
!==
value
;
}
else
{
return
el
.
checked
=
!
value
;
}
}
},
show
:
function
(
el
,
value
)
{
return
el
.
style
.
display
=
value
?
''
:
'none'
;
...
...
@@ -507,7 +445,15 @@
html
:
function
(
el
,
value
)
{
return
el
.
innerHTML
=
value
!=
null
?
value
:
''
;
},
value
:
function
(
el
,
value
)
{
value
:
{
publishes
:
true
,
bind
:
function
(
el
)
{
return
bindEvent
(
el
,
'change'
,
this
.
publish
);
},
unbind
:
function
(
el
)
{
return
unbindEvent
(
el
,
'change'
,
this
.
publish
);
},
routine
:
function
(
el
,
value
)
{
var
o
,
_i
,
_len
,
_ref
,
_results
;
if
(
el
.
type
===
'select-multiple'
)
{
if
(
value
!=
null
)
{
...
...
@@ -521,6 +467,7 @@
}
else
{
return
el
.
value
=
value
!=
null
?
value
:
''
;
}
}
},
text
:
function
(
el
,
value
)
{
if
(
el
.
innerText
!=
null
)
{
...
...
@@ -528,6 +475,71 @@
}
else
{
return
el
.
textContent
=
value
!=
null
?
value
:
''
;
}
},
"on-*"
:
{
"function"
:
true
,
routine
:
function
(
el
,
value
)
{
if
(
this
.
currentListener
)
{
unbindEvent
(
el
,
this
.
args
[
0
],
this
.
currentListener
);
}
return
this
.
currentListener
=
bindEvent
(
el
,
this
.
args
[
0
],
value
,
this
.
model
);
}
},
"each-*"
:
{
block
:
true
,
bind
:
function
(
el
,
collection
)
{
return
el
.
removeAttribute
([
'data'
,
rivets
.
config
.
prefix
,
this
.
type
].
join
(
'-'
).
replace
(
'--'
,
'-'
));
},
routine
:
function
(
el
,
collection
)
{
var
data
,
e
,
item
,
itemEl
,
m
,
n
,
previous
,
view
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
,
_ref3
,
_results
;
if
(
this
.
iterated
!=
null
)
{
_ref
=
this
.
iterated
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
view
=
_ref
[
_i
];
view
.
unbind
();
_ref1
=
view
.
els
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
e
=
_ref1
[
_j
];
e
.
parentNode
.
removeChild
(
e
);
}
}
}
else
{
this
.
marker
=
document
.
createComment
(
" rivets: "
+
this
.
type
+
" "
);
el
.
parentNode
.
insertBefore
(
this
.
marker
,
el
);
el
.
parentNode
.
removeChild
(
el
);
}
this
.
iterated
=
[];
_results
=
[];
for
(
_k
=
0
,
_len2
=
collection
.
length
;
_k
<
_len2
;
_k
++
)
{
item
=
collection
[
_k
];
data
=
{};
_ref2
=
this
.
view
.
models
;
for
(
n
in
_ref2
)
{
m
=
_ref2
[
n
];
data
[
n
]
=
m
;
}
data
[
this
.
args
[
0
]]
=
item
;
itemEl
=
el
.
cloneNode
(
true
);
previous
=
this
.
iterated
[
this
.
iterated
.
length
-
1
]
||
this
.
marker
;
this
.
marker
.
parentNode
.
insertBefore
(
itemEl
,
(
_ref3
=
previous
.
nextSibling
)
!=
null
?
_ref3
:
null
);
_results
.
push
(
this
.
iterated
.
push
(
rivets
.
bind
(
itemEl
,
data
)));
}
return
_results
;
}
},
"class-*"
:
function
(
el
,
value
)
{
var
elClass
;
elClass
=
" "
+
el
.
className
+
" "
;
if
(
!
value
===
(
elClass
.
indexOf
(
" "
+
this
.
args
[
0
]
+
" "
)
!==
-
1
))
{
return
el
.
className
=
value
?
""
+
el
.
className
+
" "
+
this
.
args
[
0
]
:
elClass
.
replace
(
" "
+
this
.
args
[
0
]
+
" "
,
' '
).
trim
();
}
},
"*"
:
function
(
el
,
value
)
{
if
(
value
)
{
return
el
.
setAttribute
(
this
.
type
,
value
);
}
else
{
return
el
.
removeAttribute
(
this
.
type
);
}
}
};
...
...
@@ -538,7 +550,7 @@
Rivets
.
formatters
=
{};
rivets
=
{
routines
:
Rivets
.
routine
s
,
binders
:
Rivets
.
binder
s
,
formatters
:
Rivets
.
formatters
,
config
:
Rivets
.
config
,
configure
:
function
(
options
)
{
...
...
lib/rivets.min.js
View file @
e0a4fdc
// rivets.js
// version: 0.
3.13
// version: 0.
4.0
// author: Michael Richards
// license: MIT
(
function
(){
var
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
=
function
(
a
,
b
){
return
function
(){
return
a
.
apply
(
b
,
arguments
)}},
k
=
[].
slice
,
l
=
[].
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
h
(
c
,
f
,
h
,
i
,
k
){
this
.
el
=
c
,
this
.
type
=
f
,
this
.
model
=
h
,
this
.
keypath
=
i
,
this
.
options
=
k
!=
null
?
k
:{},
this
.
unbind
=
j
(
this
.
unbind
,
this
),
this
.
bind
=
j
(
this
.
bind
,
this
),
this
.
publish
=
j
(
this
.
publish
,
this
),
this
.
sync
=
j
(
this
.
sync
,
this
),
this
.
set
=
j
(
this
.
set
,
this
),
this
.
formattedValue
=
j
(
this
.
formattedValue
,
this
),
this
.
isBidirectional
=
j
(
this
.
isBidirectional
,
this
),
this
.
routine
=
function
(){
switch
(
this
.
options
.
special
){
case
"event"
:
return
e
(
this
.
type
);
case
"class"
:
return
d
(
this
.
type
);
case
"iteration"
:
return
g
(
this
.
type
);
default
:
return
a
.
routines
[
this
.
type
]
||
b
(
this
.
type
)}}.
call
(
this
),
this
.
formatters
=
this
.
options
.
formatters
||
[]}
return
h
.
prototype
.
isBidirectional
=
function
(){
var
a
;
return
(
a
=
this
.
type
)
===
"value"
||
a
===
"checked"
||
a
===
"unchecked"
},
h
.
prototype
.
formattedValue
=
function
(
b
){
var
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
;
h
=
this
.
formatters
;
for
(
f
=
0
,
g
=
h
.
length
;
f
<
g
;
f
++
)
d
=
h
[
f
],
c
=
d
.
split
(
/
\s
+/
),
e
=
c
.
shift
(),
b
=
this
.
model
[
e
]
instanceof
Function
?(
i
=
this
.
model
)[
e
].
apply
(
i
,[
b
].
concat
(
k
.
call
(
c
))):
a
.
formatters
[
e
]?(
j
=
a
.
formatters
)[
e
].
apply
(
j
,[
b
].
concat
(
k
.
call
(
c
))):
void
0
;
return
b
},
h
.
prototype
.
set
=
function
(
a
){
return
a
=
a
instanceof
Function
&&
this
.
options
.
special
!==
"event"
?
this
.
formattedValue
(
a
.
call
(
this
.
model
)):
this
.
formattedValue
(
a
),
this
.
options
.
special
===
"event"
?
this
.
currentListener
=
this
.
routine
(
this
.
el
,
this
.
model
,
a
,
this
.
currentListener
):
this
.
options
.
special
===
"iteration"
?
this
.
routine
(
this
.
el
,
a
,
this
):
this
.
routine
(
this
.
el
,
a
)},
h
.
prototype
.
sync
=
function
(){
return
this
.
set
(
this
.
options
.
bypass
?
this
.
model
[
this
.
keypath
]:
a
.
config
.
adapter
.
read
(
this
.
model
,
this
.
keypath
))},
h
.
prototype
.
publish
=
function
(){
return
a
.
config
.
adapter
.
publish
(
this
.
model
,
this
.
keypath
,
f
(
this
.
el
))},
h
.
prototype
.
bind
=
function
(){
var
b
,
d
,
e
,
f
,
g
,
h
,
i
,
j
;
this
.
options
.
bypass
?
this
.
sync
():(
a
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
),
a
.
config
.
preloadData
&&
this
.
sync
(),
this
.
isBidirectional
()
&&
c
(
this
.
el
,
"change"
,
this
.
publish
));
if
((
h
=
this
.
options
.
dependencies
)
!=
null
?
h
.
length
:
void
0
){
i
=
this
.
options
.
dependencies
,
j
=
[];
for
(
f
=
0
,
g
=
i
.
length
;
f
<
g
;
f
++
)
b
=
i
[
f
],
/^
\.
/
.
test
(
b
)?(
e
=
this
.
model
,
d
=
b
.
substr
(
1
)):(
b
=
b
.
split
(
"."
),
e
=
this
.
view
.
models
[
b
.
shift
()],
d
=
b
.
join
(
"."
)),
j
.
push
(
a
.
config
.
adapter
.
subscribe
(
e
,
d
,
this
.
sync
));
return
j
}},
h
.
prototype
.
unbind
=
function
(){
var
b
,
c
,
d
,
e
,
f
,
g
;
this
.
options
.
bypass
||
(
a
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
),
this
.
isBidirectional
()
&&
i
(
this
.
el
,
"change"
,
this
.
publish
));
if
((
e
=
this
.
options
.
dependencies
)
!=
null
?
e
.
length
:
void
0
){
f
=
this
.
options
.
dependencies
,
g
=
[];
for
(
c
=
0
,
d
=
f
.
length
;
c
<
d
;
c
++
)
b
=
f
[
c
],
g
.
push
(
a
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
b
,
this
.
sync
));
return
g
}},
h
}(),
a
.
View
=
function
(){
function
b
(
a
,
b
){
this
.
els
=
a
,
this
.
models
=
b
,
this
.
publish
=
j
(
this
.
publish
,
this
),
this
.
sync
=
j
(
this
.
sync
,
this
),
this
.
unbind
=
j
(
this
.
unbind
,
this
),
this
.
bind
=
j
(
this
.
bind
,
this
),
this
.
select
=
j
(
this
.
select
,
this
),
this
.
build
=
j
(
this
.
build
,
this
),
this
.
bindingRegExp
=
j
(
this
.
bindingRegExp
,
this
),
this
.
els
.
jquery
||
this
.
els
instanceof
Array
||
(
this
.
els
=
[
this
.
els
]),
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
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
,
k
,
m
,
n
,
o
,
p
,
q
,
r
=
this
;
this
.
bindings
=
[],
j
=
[],
g
=
null
,
b
=
this
.
bindingRegExp
(),
e
=
/^on-/
,
c
=
/^class-/
,
f
=
/^each-/
,
i
=
function
(
d
){
var
h
,
i
,
k
,
m
,
n
,
o
,
p
,
q
,
s
,
t
,
u
,
v
,
w
,
x
,
y
,
z
,
A
,
B
,
C
,
D
,
E
,
F
,
G
,
H
,
I
,
J
;
if
(
l
.
call
(
j
,
d
)
<
0
){
H
=
d
.
attributes
;
for
(
z
=
0
,
D
=
H
.
length
;
z
<
D
;
z
++
){
i
=
H
[
z
];
if
(
b
.
test
(
i
.
name
)){
y
=
i
.
name
.
replace
(
b
,
""
);
if
(
f
.
test
(
y
)
&&!
r
.
models
[
y
.
replace
(
f
,
""
)]){
I
=
d
.
getElementsByTagName
(
"*"
);
for
(
A
=
0
,
E
=
I
.
length
;
A
<
E
;
A
++
)
s
=
I
[
A
],
j
.
push
(
s
);
g
=
[
i
]}}}
J
=
g
||
d
.
attributes
;
for
(
B
=
0
,
F
=
J
.
length
;
B
<
F
;
B
++
){
i
=
J
[
B
];
if
(
b
.
test
(
i
.
name
)){
t
=
{},
y
=
i
.
name
.
replace
(
b
,
""
),
w
=
function
(){
var
a
,
b
,
c
,
d
;
c
=
i
.
value
.
split
(
"|"
),
d
=
[];
for
(
a
=
0
,
b
=
c
.
length
;
a
<
b
;
a
++
)
v
=
c
[
a
],
d
.
push
(
v
.
trim
());
return
d
}(),
m
=
function
(){
var
a
,
b
,
c
,
d
;
c
=
w
.
shift
().
split
(
"<"
),
d
=
[];
for
(
a
=
0
,
b
=
c
.
length
;
a
<
b
;
a
++
)
n
=
c
[
a
],
d
.
push
(
n
.
trim
());
return
d
}(),
u
=
m
.
shift
(),
x
=
u
.
split
(
/
\.
|:/
),
t
.
formatters
=
w
,
t
.
bypass
=
u
.
indexOf
(
":"
)
!==-
1
,
x
[
0
]?
q
=
r
.
models
[
x
.
shift
()]:(
q
=
r
.
models
,
x
.
shift
()),
p
=
x
.
join
(
"."
);
if
(
q
){
if
(
o
=
m
.
shift
())
t
.
dependencies
=
o
.
split
(
/
\s
+/
);
e
.
test
(
y
)
&&
(
y
=
y
.
replace
(
e
,
""
),
t
.
special
=
"event"
),
c
.
test
(
y
)
&&
(
y
=
y
.
replace
(
c
,
""
),
t
.
special
=
"class"
),
f
.
test
(
y
)
&&
(
y
=
y
.
replace
(
f
,
""
),
t
.
special
=
"iteration"
),
k
=
new
a
.
Binding
(
d
,
y
,
q
,
p
,
t
),
k
.
view
=
r
,
r
.
bindings
.
push
(
k
)}}
if
(
g
){
for
(
C
=
0
,
G
=
g
.
length
;
C
<
G
;
C
++
)
h
=
g
[
C
],
d
.
removeAttribute
(
h
.
name
);
g
=
null
}}}},
p
=
this
.
els
;
for
(
k
=
0
,
n
=
p
.
length
;
k
<
n
;
k
++
){
d
=
p
[
k
],
i
(
d
),
q
=
d
.
getElementsByTagName
(
"*"
);
for
(
m
=
0
,
o
=
q
.
length
;
m
<
o
;
m
++
)
h
=
q
[
m
],
i
(
h
)}},
b
.
prototype
.
select
=
function
(
a
){
var
b
,
c
,
d
,
e
,
f
;
e
=
this
.
bindings
,
f
=
[];
for
(
c
=
0
,
d
=
e
.
length
;
c
<
d
;
c
++
)
b
=
e
[
c
],
a
(
b
)
&&
f
.
push
(
b
);
return
f
},
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
.
prototype
.
sync
=
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
.
sync
());
return
e
},
b
.
prototype
.
publish
=
function
(){
var
a
,
b
,
c
,
d
,
e
;
d
=
this
.
select
(
function
(
a
){
return
a
.
isBidirectional
()}),
e
=
[];
for
(
b
=
0
,
c
=
d
.
length
;
b
<
c
;
b
++
)
a
=
d
[
b
],
e
.
push
(
a
.
publish
());
return
e
},
b
}(),
c
=
function
(
a
,
b
,
c
,
d
){
var
e
;
return
e
=
function
(
a
){
return
c
.
call
(
d
,
a
)},
window
.
jQuery
!=
null
?(
a
=
jQuery
(
a
),
a
.
on
!=
null
?
a
.
on
(
b
,
e
):
a
.
bind
(
b
,
e
)):
window
.
addEventListener
!=
null
?
a
.
addEventListener
(
b
,
e
,
!
1
):(
b
=
"on"
+
b
,
a
.
attachEvent
(
b
,
e
)),
e
},
i
=
function
(
a
,
b
,
c
){
return
window
.
jQuery
!=
null
?(
a
=
jQuery
(
a
),
a
.
off
!=
null
?
a
.
off
(
b
,
c
):
a
.
unbind
(
b
,
c
)):
window
.
removeEventListener
?
a
.
removeEventListener
(
b
,
c
,
!
1
):(
b
=
"on"
+
b
,
a
.
detachEvent
(
b
,
c
))},
f
=
function
(
a
){
var
b
,
c
,
d
,
e
;
switch
(
a
.
type
){
case
"checkbox"
:
return
a
.
checked
;
case
"select-multiple"
:
e
=
[];
for
(
c
=
0
,
d
=
a
.
length
;
c
<
d
;
c
++
)
b
=
a
[
c
],
b
.
selected
&&
e
.
push
(
b
.
value
);
return
e
;
default
:
return
a
.
value
}},
e
=
function
(
a
){
return
function
(
b
,
d
,
e
,
f
){
return
f
&&
i
(
b
,
a
,
f
),
c
(
b
,
a
,
e
,
d
)}},
d
=
function
(
a
){
return
function
(
b
,
c
){
var
d
,
e
;
d
=
" "
+
b
.
className
+
" "
,
e
=
d
.
indexOf
(
" "
+
a
+
" "
)
!==-
1
;
if
(
!
c
===
e
)
return
b
.
className
=
c
?
""
+
b
.
className
+
" "
+
a
:
d
.
replace
(
" "
+
a
+
" "
,
" "
).
trim
()}},
g
=
function
(
a
){
return
function
(
b
,
c
,
d
){
var
e
,
f
,
g
,
i
,
j
,
k
,
l
,
m
,
n
,
o
,
p
,
q
,
r
,
s
,
t
;
if
(
d
.
iterated
!=
null
){
q
=
d
.
iterated
;
for
(
m
=
0
,
o
=
q
.
length
;
m
<
o
;
m
++
)
i
=
q
[
m
],
i
.
view
.
unbind
(),
i
.
el
.
parentNode
.
removeChild
(
i
.
el
)}
else
d
.
marker
=
document
.
createComment
(
" rivets: each-"
+
a
+
" "
),
b
.
parentNode
.
insertBefore
(
d
.
marker
,
b
),
b
.
parentNode
.
removeChild
(
b
);
d
.
iterated
=
[],
t
=
[];
for
(
n
=
0
,
p
=
c
.
length
;
n
<
p
;
n
++
){
f
=
c
[
n
],
e
=
{},
r
=
d
.
view
.
models
;
for
(
k
in
r
)
j
=
r
[
k
],
e
[
k
]
=
j
;
e
[
a
]
=
f
,
g
=
b
.
cloneNode
(
!
0
),
l
=
d
.
iterated
[
d
.
iterated
.
length
-
1
]
||
d
.
marker
,
d
.
marker
.
parentNode
.
insertBefore
(
g
,(
s
=
l
.
nextSibling
)
!=
null
?
s
:
null
),
t
.
push
(
d
.
iterated
.
push
({
el
:
g
,
view
:
h
.
bind
(
g
,
e
)}))}
return
t
}},
b
=
function
(
a
){
return
function
(
b
,
c
){
return
c
?
b
.
setAttribute
(
a
,
c
):
b
.
removeAttribute
(
a
)}},
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
!=
null
?
b
:
""
},
value
:
function
(
a
,
b
){
var
c
,
d
,
e
,
f
,
g
;
if
(
a
.
type
!==
"select-multiple"
)
return
a
.
value
=
b
!=
null
?
b
:
""
;
if
(
b
!=
null
){
g
=
[];
for
(
d
=
0
,
e
=
a
.
length
;
d
<
e
;
d
++
)
c
=
a
[
d
],
g
.
push
(
c
.
selected
=
(
f
=
c
.
value
,
l
.
call
(
b
,
f
)
>=
0
));
return
g
}},
text
:
function
(
a
,
b
){
return
a
.
innerText
!=
null
?
a
.
innerText
=
b
!=
null
?
b
:
""
:
a
.
textContent
=
b
!=
null
?
b
:
""
}},
a
.
config
=
{
preloadData
:
!
0
},
a
.
formatters
=
{},
h
=
{
routines
:
a
.
routines
,
formatters
:
a
.
formatters
,
config
:
a
.
config
,
configure
:
function
(
b
){
var
c
,
d
;
b
==
null
&&
(
b
=
{});
for
(
c
in
b
)
d
=
b
[
c
],
a
.
config
[
c
]
=
d
},
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
=
h
:
this
.
rivets
=
h
}).
call
(
this
);
\ No newline at end of file
(
function
(){
var
a
,
b
,
c
,
d
,
e
,
f
=
function
(
a
,
b
){
return
function
(){
return
a
.
apply
(
b
,
arguments
)}},
g
=
[].
slice
,
h
=
[].
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
b
(
b
,
c
,
d
,
e
,
g
){
var
h
,
i
,
j
,
k
;
this
.
el
=
b
,
this
.
type
=
c
,
this
.
model
=
d
,
this
.
keypath
=
e
,
this
.
options
=
g
!=
null
?
g
:{},
this
.
unbind
=
f
(
this
.
unbind
,
this
),
this
.
bind
=
f
(
this
.
bind
,
this
),
this
.
publish
=
f
(
this
.
publish
,
this
),
this
.
sync
=
f
(
this
.
sync
,
this
),
this
.
set
=
f
(
this
.
set
,
this
),
this
.
formattedValue
=
f
(
this
.
formattedValue
,
this
);
if
(
!
(
this
.
binder
=
a
.
binders
[
c
])){
k
=
a
.
binders
;
for
(
h
in
k
)
j
=
k
[
h
],
h
!==
"*"
&&
h
.
indexOf
(
"*"
)
!==-
1
&&
(
i
=
new
RegExp
(
"^"
+
h
.
replace
(
"*"
,
".+"
)
+
"$"
),
i
.
test
(
c
)
&&
(
this
.
binder
=
j
,
this
.
args
=
(
new
RegExp
(
"^"
+
h
.
replace
(
"*"
,
"(.+)"
)
+
"$"
)).
exec
(
c
),
this
.
args
.
shift
()))}
this
.
binder
||
(
this
.
binder
=
a
.
binders
[
"*"
]),
this
.
binder
instanceof
Function
&&
(
this
.
binder
=
{
routine
:
this
.
binder
}),
this
.
formatters
=
this
.
options
.
formatters
||
[]}
return
b
.
prototype
.
formattedValue
=
function
(
b
){
var
c
,
d
,
e
,
f
,
h
,
i
,
j
,
k
;
i
=
this
.
formatters
;
for
(
f
=
0
,
h
=
i
.
length
;
f
<
h
;
f
++
)
d
=
i
[
f
],
c
=
d
.
split
(
/
\s
+/
),
e
=
c
.
shift
(),
b
=
this
.
model
[
e
]
instanceof
Function
?(
j
=
this
.
model
)[
e
].
apply
(
j
,[
b
].
concat
(
g
.
call
(
c
))):
a
.
formatters
[
e
]?(
k
=
a
.
formatters
)[
e
].
apply
(
k
,[
b
].
concat
(
g
.
call
(
c
))):
void
0
;
return
b
},
b
.
prototype
.
set
=
function
(
a
){
var
b
;
return
a
=
a
instanceof
Function
&&!
this
.
binder
[
"function"
]?
this
.
formattedValue
(
a
.
call
(
this
.
model
)):
this
.
formattedValue
(
a
),(
b
=
this
.
binder
.
routine
)
!=
null
?
b
.
call
(
this
,
this
.
el
,
a
):
void
0
},
b
.
prototype
.
sync
=
function
(){
return
this
.
set
(
this
.
options
.
bypass
?
this
.
model
[
this
.
keypath
]:
a
.
config
.
adapter
.
read
(
this
.
model
,
this
.
keypath
))},
b
.
prototype
.
publish
=
function
(){
return
a
.
config
.
adapter
.
publish
(
this
.
model
,
this
.
keypath
,
c
(
this
.
el
))},
b
.
prototype
.
bind
=
function
(){
var
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
;
this
.
options
.
bypass
?
this
.
sync
():((
g
=
this
.
binder
.
bind
)
!=
null
&&
g
.
call
(
this
,
this
.
el
),
a
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
),
a
.
config
.
preloadData
&&
this
.
sync
());
if
((
h
=
this
.
options
.
dependencies
)
!=
null
?
h
.
length
:
void
0
){
i
=
this
.
options
.
dependencies
,
j
=
[];
for
(
e
=
0
,
f
=
i
.
length
;
e
<
f
;
e
++
)
b
=
i
[
e
],
/^
\.
/
.
test
(
b
)?(
d
=
this
.
model
,
c
=
b
.
substr
(
1
)):(
b
=
b
.
split
(
"."
),
d
=
this
.
view
.
models
[
b
.
shift
()],
c
=
b
.
join
(
"."
)),
j
.
push
(
a
.
config
.
adapter
.
subscribe
(
d
,
c
,
this
.
sync
));
return
j
}},
b
.
prototype
.
unbind
=
function
(){
var
b
,
c
,
d
,
e
,
f
,
g
,
h
;
this
.
options
.
bypass
||
((
e
=
this
.
binder
.
unbind
)
!=
null
&&
e
.
call
(
this
,
this
.
el
),
a
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
));
if
((
f
=
this
.
options
.
dependencies
)
!=
null
?
f
.
length
:
void
0
){
g
=
this
.
options
.
dependencies
,
h
=
[];
for
(
c
=
0
,
d
=
g
.
length
;
c
<
d
;
c
++
)
b
=
g
[
c
],
h
.
push
(
a
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
b
,
this
.
sync
));
return
h
}},
b
}(),
a
.
View
=
function
(){
function
b
(
a
,
b
){
this
.
els
=
a
,
this
.
models
=
b
,
this
.
publish
=
f
(
this
.
publish
,
this
),
this
.
sync
=
f
(
this
.
sync
,
this
),
this
.
unbind
=
f
(
this
.
unbind
,
this
),
this
.
bind
=
f
(
this
.
bind
,
this
),
this
.
select
=
f
(
this
.
select
,
this
),
this
.
build
=
f
(
this
.
build
,
this
),
this
.
bindingRegExp
=
f
(
this
.
bindingRegExp
,
this
),
this
.
els
.
jquery
||
this
.
els
instanceof
Array
||
(
this
.
els
=
[
this
.
els
]),
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
,
c
,
d
,
e
,
f
,
g
,
i
,
j
,
k
,
l
,
m
,
n
=
this
;
this
.
bindings
=
[],
f
=
[],
b
=
this
.
bindingRegExp
(),
e
=
function
(
c
){
var
d
,
e
,
g
,
i
,
j
,
k
,
l
,
m
,
o
,
p
,
q
,
r
,
s
,
t
,
u
,
v
,
w
,
x
,
y
,
z
,
A
,
B
,
C
,
D
,
E
,
F
,
G
,
H
,
I
;
if
(
h
.
call
(
f
,
c
)
<
0
){
F
=
c
.
attributes
;
for
(
z
=
0
,
C
=
F
.
length
;
z
<
C
;
z
++
){
d
=
F
[
z
];
if
(
b
.
test
(
d
.
name
)){
x
=
d
.
name
.
replace
(
b
,
""
);
if
(
!
(
g
=
a
.
binders
[
x
])){
G
=
a
.
binders
;
for
(
m
in
G
)
y
=
G
[
m
],
m
!==
"*"
&&
m
.
indexOf
(
"*"
)
!==-
1
&&
(
v
=
new
RegExp
(
"^"
+
m
.
replace
(
"*"
,
".+"
)
+
"$"
),
v
.
test
(
x
)
&&
(
g
=
y
))}
g
||
(
g
=
a
.
binders
[
"*"
]);
if
(
g
.
block
){
H
=
c
.
getElementsByTagName
(
"*"
);
for
(
A
=
0
,
D
=
H
.
length
;
A
<
D
;
A
++
)
q
=
H
[
A
],
f
.
push
(
q
);
e
=
[
d
]}}}
I
=
e
||
c
.
attributes
;
for
(
B
=
0
,
E
=
I
.
length
;
B
<
E
;
B
++
){
d
=
I
[
B
];
if
(
b
.
test
(
d
.
name
)){
r
=
{},
x
=
d
.
name
.
replace
(
b
,
""
),
u
=
function
(){
var
a
,
b
,
c
,
e
;
c
=
d
.
value
.
split
(
"|"
),
e
=
[];
for
(
a
=
0
,
b
=
c
.
length
;
a
<
b
;
a
++
)
t
=
c
[
a
],
e
.
push
(
t
.
trim
());
return
e
}(),
j
=
function
(){
var
a
,
b
,
c
,
d
;
c
=
u
.
shift
().
split
(
"<"
),
d
=
[];
for
(
a
=
0
,
b
=
c
.
length
;
a
<
b
;
a
++
)
k
=
c
[
a
],
d
.
push
(
k
.
trim
());
return
d
}(),
s
=
j
.
shift
(),
w
=
s
.
split
(
/
\.
|:/
),
r
.
formatters
=
u
,
r
.
bypass
=
s
.
indexOf
(
":"
)
!==-
1
,
w
[
0
]?
p
=
n
.
models
[
w
.
shift
()]:(
p
=
n
.
models
,
w
.
shift
()),
o
=
w
.
join
(
"."
);
if
(
p
){
if
(
l
=
j
.
shift
())
r
.
dependencies
=
l
.
split
(
/
\s
+/
);
i
=
new
a
.
Binding
(
c
,
x
,
p
,
o
,
r
),
i
.
view
=
n
,
n
.
bindings
.
push
(
i
)}}}
e
&&
(
e
=
null
)}},
l
=
this
.
els
;
for
(
g
=
0
,
j
=
l
.
length
;
g
<
j
;
g
++
){
c
=
l
[
g
],
e
(
c
),
m
=
c
.
getElementsByTagName
(
"*"
);
for
(
i
=
0
,
k
=
m
.
length
;
i
<
k
;
i
++
)
d
=
m
[
i
],
e
(
d
)}},
b
.
prototype
.
select
=
function
(
a
){
var
b
,
c
,
d
,
e
,
f
;
e
=
this
.
bindings
,
f
=
[];
for
(
c
=
0
,
d
=
e
.
length
;
c
<
d
;
c
++
)
b
=
e
[
c
],
a
(
b
)
&&
f
.
push
(
b
);
return
f
},
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
.
prototype
.
sync
=
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
.
sync
());
return
e
},
b
.
prototype
.
publish
=
function
(){
var
a
,
b
,
c
,
d
,
e
;
d
=
this
.
select
(
function
(
a
){
return
a
.
binder
.
publishes
}),
e
=
[];
for
(
b
=
0
,
c
=
d
.
length
;
b
<
c
;
b
++
)
a
=
d
[
b
],
e
.
push
(
a
.
publish
());
return
e
},
b
}(),
b
=
function
(
a
,
b
,
c
,
d
){
var
e
;
return
e
=
function
(
a
){
return
c
.
call
(
d
,
a
)},
window
.
jQuery
!=
null
?(
a
=
jQuery
(
a
),
a
.
on
!=
null
?
a
.
on
(
b
,
e
):
a
.
bind
(
b
,
e
)):
window
.
addEventListener
!=
null
?
a
.
addEventListener
(
b
,
e
,
!
1
):(
b
=
"on"
+
b
,
a
.
attachEvent
(
b
,
e
)),
e
},
e
=
function
(
a
,
b
,
c
){
return
window
.
jQuery
!=
null
?(
a
=
jQuery
(
a
),
a
.
off
!=
null
?
a
.
off
(
b
,
c
):
a
.
unbind
(
b
,
c
)):
window
.
removeEventListener
?
a
.
removeEventListener
(
b
,
c
,
!
1
):(
b
=
"on"
+
b
,
a
.
detachEvent
(
b
,
c
))},
c
=
function
(
a
){
var
b
,
c
,
d
,
e
;
switch
(
a
.
type
){
case
"checkbox"
:
return
a
.
checked
;
case
"select-multiple"
:
e
=
[];
for
(
c
=
0
,
d
=
a
.
length
;
c
<
d
;
c
++
)
b
=
a
[
c
],
b
.
selected
&&
e
.
push
(
b
.
value
);
return
e
;
default
:
return
a
.
value
}},
a
.
binders
=
{
enabled
:
function
(
a
,
b
){
return
a
.
disabled
=!
b
},
disabled
:
function
(
a
,
b
){
return
a
.
disabled
=!!
b
},
checked
:{
publishes
:
!
0
,
bind
:
function
(
a
){
return
b
(
a
,
"change"
,
this
.
publish
)},
unbind
:
function
(
a
){
return
e
(
a
,
"change"
,
this
.
publish
)},
routine
:
function
(
a
,
b
){
return
a
.
type
===
"radio"
?
a
.
checked
=
a
.
value
===
b
:
a
.
checked
=!!
b
}},
unchecked
:{
publishes
:
!
0
,
bind
:
function
(
a
){
return
b
(
a
,
"change"
,
this
.
publish
)},
unbind
:
function
(
a
){
return
e
(
a
,
"change"
,
this
.
publish
)},
routine
:
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
!=
null
?
b
:
""
},
value
:{
publishes
:
!
0
,
bind
:
function
(
a
){
return
b
(
a
,
"change"
,
this
.
publish
)},
unbind
:
function
(
a
){
return
e
(
a
,
"change"
,
this
.
publish
)},
routine
:
function
(
a
,
b
){
var
c
,
d
,
e
,
f
,
g
;
if
(
a
.
type
!==
"select-multiple"
)
return
a
.
value
=
b
!=
null
?
b
:
""
;
if
(
b
!=
null
){
g
=
[];
for
(
d
=
0
,
e
=
a
.
length
;
d
<
e
;
d
++
)
c
=
a
[
d
],
g
.
push
(
c
.
selected
=
(
f
=
c
.
value
,
h
.
call
(
b
,
f
)
>=
0
));
return
g
}}},
text
:
function
(
a
,
b
){
return
a
.
innerText
!=
null
?
a
.
innerText
=
b
!=
null
?
b
:
""
:
a
.
textContent
=
b
!=
null
?
b
:
""
},
"on-*"
:{
"function"
:
!
0
,
routine
:
function
(
a
,
c
){
return
this
.
currentListener
&&
e
(
a
,
this
.
args
[
0
],
this
.
currentListener
),
this
.
currentListener
=
b
(
a
,
this
.
args
[
0
],
c
,
this
.
model
)}},
"each-*"
:{
block
:
!
0
,
bind
:
function
(
a
,
b
){
return
a
.
removeAttribute
([
"data"
,
d
.
config
.
prefix
,
this
.
type
].
join
(
"-"
).
replace
(
"--"
,
"-"
))},
routine
:
function
(
a
,
b
){
var
c
,
e
,
f
,
g
,
h
,
i
,
j
,
k
,
l
,
m
,
n
,
o
,
p
,
q
,
r
,
s
,
t
,
u
,
v
;
if
(
this
.
iterated
!=
null
){
r
=
this
.
iterated
;
for
(
l
=
0
,
o
=
r
.
length
;
l
<
o
;
l
++
){
k
=
r
[
l
],
k
.
unbind
(),
s
=
k
.
els
;
for
(
m
=
0
,
p
=
s
.
length
;
m
<
p
;
m
++
)
e
=
s
[
m
],
e
.
parentNode
.
removeChild
(
e
)}}
else
this
.
marker
=
document
.
createComment
(
" rivets: "
+
this
.
type
+
" "
),
a
.
parentNode
.
insertBefore
(
this
.
marker
,
a
),
a
.
parentNode
.
removeChild
(
a
);
this
.
iterated
=
[],
v
=
[];
for
(
n
=
0
,
q
=
b
.
length
;
n
<
q
;
n
++
){
f
=
b
[
n
],
c
=
{},
t
=
this
.
view
.
models
;
for
(
i
in
t
)
h
=
t
[
i
],
c
[
i
]
=
h
;
c
[
this
.
args
[
0
]]
=
f
,
g
=
a
.
cloneNode
(
!
0
),
j
=
this
.
iterated
[
this
.
iterated
.
length
-
1
]
||
this
.
marker
,
this
.
marker
.
parentNode
.
insertBefore
(
g
,(
u
=
j
.
nextSibling
)
!=
null
?
u
:
null
),
v
.
push
(
this
.
iterated
.
push
(
d
.
bind
(
g
,
c
)))}
return
v
}},
"class-*"
:
function
(
a
,
b
){
var
c
;
c
=
" "
+
a
.
className
+
" "
;
if
(
!
b
==
(
c
.
indexOf
(
" "
+
this
.
args
[
0
]
+
" "
)
!==-
1
))
return
a
.
className
=
b
?
""
+
a
.
className
+
" "
+
this
.
args
[
0
]:
c
.
replace
(
" "
+
this
.
args
[
0
]
+
" "
,
" "
).
trim
()},
"*"
:
function
(
a
,
b
){
return
b
?
a
.
setAttribute
(
this
.
type
,
b
):
a
.
removeAttribute
(
this
.
type
)}},
a
.
config
=
{
preloadData
:
!
0
},
a
.
formatters
=
{},
d
=
{
binders
:
a
.
binders
,
formatters
:
a
.
formatters
,
config
:
a
.
config
,
configure
:
function
(
b
){
var
c
,
d
;
b
==
null
&&
(
b
=
{});
for
(
c
in
b
)
d
=
b
[
c
],
a
.
config
[
c
]
=
d
},
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
=
d
:
this
.
rivets
=
d
}).
call
(
this
);
\ No newline at end of file
...
...
package.json
View file @
e0a4fdc
{
"name"
:
"rivets"
,
"description"
:
"Declarative data binding facility."
,
"version"
:
"0.
3.13
"
,
"version"
:
"0.
4.0
"
,
"author"
:
"Michael Richards"
,
"url"
:
"http://rivetsjs.com"
,
"main"
:
"./lib/rivets.js"
,
...
...
src/rivets.coffee
View file @
e0a4fdc
# rivets.js
# version : 0.
3.13
# version : 0.
4.0
# author : Michael Richards
# license : MIT
...
...
Please
register
or
sign in
to post a comment