Normalize event.target for old browsers incorrectly handling SVG elements

pull/669/head
Thibaut Courouble 7 years ago
parent 53f666a742
commit 30dd32c1b5

@ -170,7 +170,7 @@ onclick = (event) ->
catch
return
link = event.target
link = $.eventTarget(event)
link = link.parentNode while link and link.tagName isnt 'A'
if link and not link.target and isSameOrigin(link.href)

@ -60,6 +60,9 @@ $.stopEvent = (event) ->
event.stopImmediatePropagation()
return
$.eventTarget = (event) ->
event.target.correspondingUseElement || event.target
#
# Manipulation
#

@ -169,7 +169,7 @@ class app.views.Content extends app.View
return
onClick: (event) =>
link = $.closestLink event.target, @el
link = $.closestLink $.eventTarget(event), @el
if link and @isExternalUrl link.getAttribute('href')
$.stopEvent(event)
$.popup(link)

@ -140,7 +140,7 @@ class app.views.EntryPage extends app.View
true
onClick: (event) =>
target = event.target
target = $.eventTarget(event)
if target.hasAttribute 'data-retry'
$.stopEvent(event)
@load()

@ -50,7 +50,7 @@ class app.views.OfflinePage extends app.View
return
onClick: (event) =>
el = event.target
el = $.eventTarget(event)
if action = el.getAttribute('data-action')
doc = @docByEl(el)
action = 'install' if action is 'update'

@ -30,7 +30,7 @@ class app.views.RootPage extends app.View
onRoute: ->
onClick: (event) =>
if event.target.hasAttribute 'data-hide-intro'
if $.eventTarget(event).hasAttribute 'data-hide-intro'
$.stopEvent(event)
@hideIntro()
return

@ -71,9 +71,10 @@ class app.views.Document extends app.View
return
onClick: (event) ->
return unless event.target.hasAttribute('data-behavior')
target = $.eventTarget(event)
return unless target.hasAttribute('data-behavior')
$.stopEvent(event)
switch event.target.getAttribute('data-behavior')
switch target.getAttribute('data-behavior')
when 'back' then history.back()
when 'reload' then window.location.reload()
when 'reboot' then window.location = '/'

@ -10,7 +10,8 @@ class app.views.Menu extends app.View
return
onClick: (event) ->
event.target.blur() if event.target.tagName is 'A'
target = $.eventTarget(event)
target.blur() if target.tagName is 'A'
return
onGlobalClick: (event) =>

@ -117,6 +117,7 @@ class app.views.ListFocus extends app.View
onClick: (event) =>
return if event.which isnt 1 or event.metaKey or event.ctrlKey
if event.target.tagName is 'A'
@focus event.target, silent: true
target = $.eventTarget(event)
if target.tagName is 'A'
@focus target, silent: true
return

@ -54,7 +54,7 @@ class app.views.ListFold extends app.View
onClick: (event) =>
return if event.which isnt 1 or event.metaKey or event.ctrlKey
return unless event.pageY # ignore fabricated clicks
el = event.target
el = $.eventTarget(event)
el = el.parentNode if el.parentNode.tagName.toUpperCase() is 'SVG'
if el.classList.contains @constructor.handleClass

@ -37,6 +37,7 @@ class app.views.ListSelect extends app.View
onClick: (event) =>
return if event.which isnt 1 or event.metaKey or event.ctrlKey
if event.target.tagName is 'A'
@select event.target
target = $.eventTarget(event)
if target.tagName is 'A'
@select target
return

@ -83,7 +83,8 @@ class app.views.PaginatedList extends app.View
return
onClick: (event) =>
if event.target.tagName is 'SPAN' # link
target = $.eventTarget(event)
if target.tagName is 'SPAN' # link
$.stopEvent(event)
@paginate event.target
@paginate target
return

@ -51,8 +51,9 @@ class app.views.Notif extends app.View
onClick: (event) =>
return if event.which isnt 1
return if event.target.hasAttribute('data-behavior')
if event.target.tagName isnt 'A' or event.target.classList.contains('_notif-close')
target = $.eventTarget(event)
return if target.hasAttribute('data-behavior')
if target.tagName isnt 'A' or target.classList.contains('_notif-close')
$.stopEvent(event)
@hide()
return

@ -164,10 +164,11 @@ class app.views.DocList extends app.View
return
onClick: (event) =>
if @disabledTitle and $.hasChild(@disabledTitle, event.target) and event.target.tagName isnt 'A'
target = $.eventTarget(event)
if @disabledTitle and $.hasChild(@disabledTitle, target) and target.tagName isnt 'A'
$.stopEvent(event)
@toggleDisabled()
else if slug = event.target.getAttribute('data-enable')
else if slug = target.getAttribute('data-enable')
$.stopEvent(event)
doc = app.disabledDocs.findBy('slug', slug)
app.enableDoc(doc, @onEnabled, @onEnabled) if doc

@ -62,7 +62,7 @@ class app.views.Results extends app.View
onClick: (event) =>
return if event.which isnt 1
if slug = event.target.getAttribute('data-enable')
if slug = $.eventTarget(event).getAttribute('data-enable')
$.stopEvent(event)
doc = app.disabledDocs.findBy('slug', slug)
app.enableDoc(doc, @onDocEnabled.bind(@, doc), $.noop) if doc

@ -131,7 +131,7 @@ class app.views.Sidebar extends app.View
onClick: (event) =>
return if event.which isnt 1
if event.target.hasAttribute? 'data-reset-list'
if $.eventTarget(event).hasAttribute? 'data-reset-list'
$.stopEvent(event)
@onAltR()
return

Loading…
Cancel
Save