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 catch
return return
link = event.target link = $.eventTarget(event)
link = link.parentNode while link and link.tagName isnt 'A' link = link.parentNode while link and link.tagName isnt 'A'
if link and not link.target and isSameOrigin(link.href) if link and not link.target and isSameOrigin(link.href)

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

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

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

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

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

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

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

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

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

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

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

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

@ -164,10 +164,11 @@ class app.views.DocList extends app.View
return return
onClick: (event) => 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) $.stopEvent(event)
@toggleDisabled() @toggleDisabled()
else if slug = event.target.getAttribute('data-enable') else if slug = target.getAttribute('data-enable')
$.stopEvent(event) $.stopEvent(event)
doc = app.disabledDocs.findBy('slug', slug) doc = app.disabledDocs.findBy('slug', slug)
app.enableDoc(doc, @onEnabled, @onEnabled) if doc app.enableDoc(doc, @onEnabled, @onEnabled) if doc

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

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

Loading…
Cancel
Save