Browse Source

Use parentNode instead of parentElement as the latter doesn't work on SVG elements in some browsers

Thibaut Courouble 8 years ago
parent
commit
53f666a742

+ 1 - 1
assets/javascripts/lib/page.coffee

@@ -171,7 +171,7 @@ onclick = (event) ->
     return
 
   link = event.target
-  link = link.parentElement 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)
     event.preventDefault()

+ 8 - 8
assets/javascripts/lib/util.coffee

@@ -16,13 +16,13 @@ $.hasChild = (parent, el) ->
   while el
     return true if el is parent
     return if el is document.body
-    el = el.parentElement
+    el = el.parentNode
 
 $.closestLink = (el, parent = document.body) ->
   while el
     return el if el.tagName is 'A'
     return if el is parent
-    el = el.parentElement
+    el = el.parentNode
 
 #
 # Events
@@ -96,7 +96,7 @@ $.before = (el, value) ->
   if typeof value is 'string' or $.isCollection(value)
     value = buildFragment(value)
 
-  el.parentElement.insertBefore(value, el)
+  el.parentNode.insertBefore(value, el)
   return
 
 $.after = (el, value) ->
@@ -104,16 +104,16 @@ $.after = (el, value) ->
     value = buildFragment(value)
 
   if el.nextSibling
-    el.parentElement.insertBefore(value, el.nextSibling)
+    el.parentNode.insertBefore(value, el.nextSibling)
   else
-    el.parentElement.appendChild(value)
+    el.parentNode.appendChild(value)
   return
 
 $.remove = (value) ->
   if $.isCollection(value)
-    el.parentElement?.removeChild(el) for el in $.makeArray(value)
+    el.parentNode?.removeChild(el) for el in $.makeArray(value)
   else
-    value.parentElement?.removeChild(value)
+    value.parentNode?.removeChild(value)
   return
 
 $.empty = (el) ->
@@ -155,7 +155,7 @@ $.offset = (el, container = document.body) ->
   left: left
 
 $.scrollParent = (el) ->
-  while el = el.parentElement
+  while el = el.parentNode
     break if el.scrollTop > 0
     break if getComputedStyle(el)?.overflowY in ['auto', 'scroll']
   el

+ 6 - 6
assets/javascripts/views/list/list_focus.coffee

@@ -46,8 +46,8 @@ class app.views.ListFocus extends app.View
           @findNext(next)
       else if next.tagName is 'H6' # title
         @findNext(next)
-    else if cursor.parentElement isnt @el
-      @findNext cursor.parentElement
+    else if cursor.parentNode isnt @el
+      @findNext cursor.parentNode
 
   findFirst: (cursor) ->
     return unless first = cursor.firstChild
@@ -72,8 +72,8 @@ class app.views.ListFocus extends app.View
           @findPrev(prev)
       else if prev.tagName is 'H6' # title
         @findPrev(prev)
-    else if cursor.parentElement isnt @el
-      @findPrev cursor.parentElement
+    else if cursor.parentNode isnt @el
+      @findPrev cursor.parentNode
 
   findLast: (cursor) ->
     return unless last = cursor.lastChild
@@ -101,8 +101,8 @@ class app.views.ListFocus extends app.View
 
   onLeft: =>
     cursor = @getCursor()
-    if cursor and not cursor.classList.contains(app.views.ListFold.activeClass) and cursor.parentElement isnt @el
-      @focusOnNextFrame cursor.parentElement.previousSibling
+    if cursor and not cursor.classList.contains(app.views.ListFold.activeClass) and cursor.parentNode isnt @el
+      @focusOnNextFrame cursor.parentNode.previousSibling
     return
 
   onEnter: =>

+ 2 - 2
assets/javascripts/views/list/list_fold.coffee

@@ -55,11 +55,11 @@ class app.views.ListFold extends app.View
     return if event.which isnt 1 or event.metaKey or event.ctrlKey
     return unless event.pageY # ignore fabricated clicks
     el = event.target
-    el = el.parentElement if el.parentElement.tagName.toUpperCase() is 'SVG'
+    el = el.parentNode if el.parentNode.tagName.toUpperCase() is 'SVG'
 
     if el.classList.contains @constructor.handleClass
       $.stopEvent(event)
-      @toggle el.parentElement
+      @toggle el.parentNode
     else if el.classList.contains @constructor.targetClass
       if el.hasAttribute('href')
         if el.classList.contains(@constructor.activeClass)