Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

einarstubhaug
Copy link

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

*
* @returns { node } parentElement
*/
function getParentElement(node) {
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

@danielweck danielweck May 21, 2017

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

@jccr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants