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

Android - document.contains #686

Merged
merged 2 commits into from
Jan 22, 2014
Merged

Android - document.contains #686

merged 2 commits into from
Jan 22, 2014

Conversation

andykant
Copy link
Contributor

util/inserted/inserted.js provide can.inserted which checks if the given elements belong to the document DOM tree.

This rely on can.has which itself rely on the DOM library (zepto, jquery....) which rely on browser contains native method (at least for zepto).

document.contains isn't provided by android stock browser and so, can.inserted fails and so can.view can't render.

I assume it would be better to check on document.body instead of document.
It's possible to use contains from document.childNodes, so this contains check will also works over HTML (document.childNodes[1]), even if I don't see much interest to check in full HTML fragment.

@justinbmeyer
Copy link
Contributor

document.contains isn't provided by android stock browser and so, can.inserted fails and so can.view can't render.

Does this mean your patch doesn't fix the issue, it's just something you think might be better?

@justinbmeyer
Copy link
Contributor

Oh, you are saying document.contains doesn't exist, but document.body.contain does.

Ah, why not use document.documentElement? That way anything inserted works (even something in the head).

@jbguerraz
Copy link
Contributor Author

Yep, why not; document.documentElement is document.childNodes[1]. As I said, I'm not sure it has some interest to check in the full HTML fragment (document.documentElement / document.childNodes[1]) as the HTML Head may reference quite lot of nodes (even more when we use an AMD loader like Require). But if some people may have interest to use can.inserted in order to check if an element is in the Head, then why not :)

@andykant
Copy link
Contributor

This seems to specifically occur when using Zepto (not if you run the tests without a library).

@andykant
Copy link
Contributor

I'm going to be adding a little tweak to your commit, then I'll merge it.

andykant added a commit that referenced this pull request Jan 22, 2014
@andykant andykant merged commit 32fc3c4 into master Jan 22, 2014
@andykant andykant deleted the 686_android_document_contains branch January 22, 2014 18:59
@jbguerraz
Copy link
Contributor Author

"This seems to specifically occur when using Zepto (not if you run the tests without a library)."
As far as Weinre tell me, there is no document.contains even without any library => It's not related to Zepto, but to Android browser which provide contains only on HTMLElement (document is an HTMLDocument object and not an HTMLElement one, that's why it fails).

Also, you added a condition in order to continue to use contains on document; that's not right, if you want to check on the full document, then use document.documentElement, if you prefer to check only on body, then use document.body : then there is no need to add a condition as both works over all browsers.

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.

None yet

3 participants