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
05611929
authored
2013-11-22 17:51:03 +0100
by
Olle Bröms
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Improved the performance of bindEvent, unbindEvent, getInputValue on Rivets.Util.
1 parent
d6049891
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
31 deletions
src/util.coffee
src/util.coffee
View file @
0561192
# Rivets.Util
# -----------
# Houses common utility functions used internally by Rivets.js.
Rivets
.
Util
=
# Create a single DOM event binding.
bindEvent
:
(
el
,
event
,
handler
)
->
if
window
.
jQuery
?
el
=
jQuery
el
if
el
.
on
?
then
el
.
on
event
,
handler
else
el
.
bind
event
,
handler
else
if
window
.
addEventListener
?
if
'jQuery'
of
window
[
bindMethod
,
unbindMethod
]
=
if
'on'
of
jQuery
then
[
'on'
,
'off'
]
else
[
'bind'
,
'unbind'
]
Rivets
.
Util
=
bindEvent
:
(
el
,
event
,
handler
)
->
jQuery
(
el
)[
bindMethod
]
event
,
handler
unbindEvent
:
(
el
,
event
,
handler
)
->
jQuery
(
el
)[
unbindMethod
]
event
,
handler
getInputValue
:
(
el
)
->
$el
=
jQuery
el
if
$el
.
attr
(
'type'
)
is
'checkbox'
then
$el
.
is
':checked'
else
do
$el
.
val
else
Rivets
.
Util
=
bindEvent
:
do
->
if
'addEventListener'
of
window
then
return
(
el
,
event
,
handler
)
->
el
.
addEventListener
event
,
handler
,
false
else
event
=
'on'
+
event
el
.
attachEvent
event
,
handler
# Remove a single DOM event binding.
unbindEvent
:
(
el
,
event
,
handler
)
->
if
window
.
jQuery
?
el
=
jQuery
el
if
el
.
off
?
then
el
.
off
event
,
handler
else
el
.
unbind
event
,
handler
else
if
window
.
removeEventListener
?
(
el
,
event
,
handler
)
->
el
.
attachEvent
'on'
+
event
,
handler
unbindEvent
:
do
->
if
'removeEventListener'
of
window
then
return
(
el
,
event
,
handler
)
->
el
.
removeEventListener
event
,
handler
,
false
else
event
=
'on'
+
event
el
.
detachEvent
event
,
handler
# Get the current value of an input node.
(
el
,
event
,
handler
)
->
el
.
detachEvent
'on'
+
event
,
handler
getInputValue
:
(
el
)
->
if
window
.
jQuery
?
el
=
jQuery
el
switch
el
[
0
].
type
when
'checkbox'
then
el
.
is
':checked'
else
el
.
val
()
else
switch
el
.
type
when
'checkbox'
then
el
.
checked
when
'select-multiple'
then
o
.
value
for
o
in
el
when
o
.
selected
if
el
.
type
is
'checkbox'
then
el
.
checked
else
if
el
.
type
is
'select-multiple'
then
o
.
value
for
o
in
el
when
o
.
selected
else
el
.
value
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment