-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Readium shared issue #386, added helper function for node.parentElement #387
base: develop
Are you sure you want to change the base?
Conversation
…ntElement because of IE
* | ||
* @returns { node } parentElement | ||
*/ | ||
function getParentElement(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, rangy-core
's implementation is:
function parentElement(node) {
var parent = node.parentNode;
return (parent.nodeType == 1) ? parent : null;
}
*/ | ||
function getParentElement(node) { | ||
if (node.parentElement) { | ||
return node.parentElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: node.parentElement
!== textRange.parentElement()
(the latter is a function).
@@ -1299,7 +1321,7 @@ var CfiNavigationLogic = function(options) { | |||
_.each($elements, function ($node) { | |||
var node = $node[0]; | |||
var isTextNode = (node.nodeType === Node.TEXT_NODE); | |||
var element = isTextNode ? node.parentElement : node; | |||
var element = isTextNode ? getParentElement(node) : node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other uses of node.parentElement
, notably plugins/highlights/manager.js
getAnnotationMidpoints()
https://github.com/readium/readium-shared-js/blob/develop/plugins/highlights/manager.js#L304
I also note the use of jQuery's $node.parent()
in many places in ReadiumJS, notably:
//figure out a better way to get the html parent from an element..
var $html = $element.parent();
https://github.com/readium/readium-shared-js/blob/develop/plugins/highlights/manager.js#L322
Because IE returns null for text nodes
Related issue
#386
Additional information
Added function getParentElement which return node.parentElement if it is defined (chrome/firefox/safari/etc) or searches for the closest element in internet explorer 10 & 11