Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
a3398fff
Commit
a3398fff
authored
7 years ago
by
Johann-S
Committed by
XhmikosR
6 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Add event delegation + fix EventHandler.one
parent
00ca7811
5 merge requests
!31948
Examples/Floating-labels: fix bad behavior with autofill
,
!30064
test
,
!29779
Responsive sizing
,
!28882
fix custom-select-indicator in IE10
,
!28721
Hot test
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/src/alert.js
+1
-6
js/src/alert.js
js/src/dom/eventHandler.js
+18
-7
js/src/dom/eventHandler.js
with
19 additions
and
13 deletions
+19
-13
js/src/alert.js
+
1
-
6
View file @
a3398fff
...
...
@@ -153,12 +153,7 @@ class Alert {
* Data Api implementation
* ------------------------------------------------------------------------
*/
$
(
document
).
on
(
Event
.
CLICK_DATA_API
,
Selector
.
DISMISS
,
Alert
.
_handleDismiss
(
new
Alert
())
)
EventHandler
.
on
(
document
,
Event
.
CLICK_DATA_API
,
Selector
.
DISMISS
,
Alert
.
_handleDismiss
(
new
Alert
()))
/**
* ------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
js/src/dom/eventHandler.js
+
18
-
7
View file @
a3398fff
...
...
@@ -91,13 +91,27 @@ function bootstrapHandler(element, fn) {
}
}
function
bootstrapDelegationHandler
(
selector
,
fn
)
{
return
function
(
event
)
{
const
domElements
=
document
.
querySelectorAll
(
selector
)
for
(
let
target
=
event
.
target
;
target
&&
target
!==
this
;
target
=
target
.
parentNode
)
{
for
(
let
i
=
domElements
.
length
;
i
--
;)
{
if
(
domElements
[
i
]
===
target
)
{
return
fn
.
apply
(
target
,
[
event
])
}
}
}
}
}
const
EventHandler
=
{
on
(
element
,
originalTypeEvent
,
handler
)
{
on
(
element
,
originalTypeEvent
,
handler
,
delegationFn
)
{
if
(
typeof
originalTypeEvent
!==
'
string
'
||
(
typeof
element
===
'
undefined
'
||
element
===
null
))
{
return
}
const
delegation
=
typeof
handler
===
'
string
'
// allow to get the native events from namespaced events ('click.bs.button' --> 'click')
let
typeEvent
=
originalTypeEvent
.
replace
(
stripNameRegex
,
''
)
const
isNative
=
nativeEvents
.
indexOf
(
typeEvent
)
>
-
1
...
...
@@ -107,12 +121,11 @@ const EventHandler = {
const
events
=
getEvent
(
element
)
const
handlers
=
events
[
typeEvent
]
||
(
events
[
typeEvent
]
=
{})
const
uid
=
getUidEvent
(
handler
,
originalTypeEvent
.
replace
(
namespaceRegex
,
''
))
// TODO : Handle multi events on one element
if
(
handlers
[
uid
])
{
return
}
const
fn
=
bootstrapHandler
(
element
,
handler
)
const
fn
=
!
delegation
?
bootstrapHandler
(
element
,
handler
)
:
bootstrapDelegationHandler
(
handler
,
delegationFn
)
handlers
[
uid
]
=
fn
handler
.
uidEvent
=
uid
element
.
addEventListener
(
typeEvent
,
fn
,
false
)
...
...
@@ -125,10 +138,8 @@ const EventHandler = {
if
(
!
events
||
!
events
[
typeEvent
])
{
return
}
const
uidEvent
=
handler
.
uidEvent
const
fn
=
events
[
typeEvent
][
uidEvent
]
fn
.
apply
(
element
,
[
e
])
EventHandler
.
off
(
element
,
event
,
handler
)
handler
.
apply
(
element
,
[
e
])
EventHandler
.
off
(
element
,
event
,
complete
)
}
EventHandler
.
on
(
element
,
event
,
complete
)
},
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets