'contains' method's error #135

Closed
opened 2018-03-05 21:44:24 -05:00 by venzersiz · 4 comments
venzersiz commented 2018-03-05 21:44:24 -05:00 (Migrated from github.com)

CODE

function contains(doc, selectors, el) { for (var i = 0; i < selectors.length; i++) { var selectedEls = doc.querySelectorAll(selectors[i]) for (var j = 0; j < selectedEls.length; j++) { if (selectedEls[j].contains(el)) { return true } } }

Situations

I coded that invoke manual pjax call on <select> element's change event. And then doc.querySelectorAll line in code above, occurred error.

Error message

Uncaught TypeError: doc.querySelectorAll is not a function

Parameters in debug

doc = ["pjax-container"]
selectors = select#category_sel
el = undefined

Did I mistake?
Thank you!

# CODE `function contains(doc, selectors, el) { for (var i = 0; i < selectors.length; i++) { var selectedEls = doc.querySelectorAll(selectors[i]) for (var j = 0; j < selectedEls.length; j++) { if (selectedEls[j].contains(el)) { return true } } }` # Situations I coded that invoke manual pjax call on `<select>` element's change event. And then doc.querySelectorAll line in code above, occurred error. # Error message Uncaught TypeError: doc.querySelectorAll is not a function # Parameters in debug doc = ["pjax-container"] selectors = select#category_sel el = undefined Did I mistake? Thank you!
BehindTheMath commented 2018-03-05 21:51:34 -05:00 (Migrated from github.com)

@venzersiz Can you post the complete stack trace?

@venzersiz Can you post the complete stack trace?
venzersiz commented 2018-03-05 21:52:14 -05:00 (Migrated from github.com)

pjax.js:981 Uncaught TypeError: doc.querySelectorAll is not a function
at contains (pjax.js:981)
at Pjax.loadContent (pjax.js:133)
at Pjax. (pjax.js:202)
at XMLHttpRequest.request.onreadystatechange (pjax.js:780)

pjax.js:981 Uncaught TypeError: doc.querySelectorAll is not a function at contains (pjax.js:981) at Pjax.loadContent (pjax.js:133) at Pjax.<anonymous> (pjax.js:202) at XMLHttpRequest.request.onreadystatechange (pjax.js:780)
BehindTheMath commented 2018-03-05 21:57:32 -05:00 (Migrated from github.com)

You're right, that's a bug.

This line:

if (document.activeElement && contains(this.options.selectors, document.activeElement)) {

should be:

if (document.activeElement && contains(document, this.options.selectors, document.activeElement)) {
You're right, that's a bug. [This line](https://github.com/MoOx/pjax/blob/f98f2dd63b48113ff91b6bd8808257bfc723ef6b/index.js#L131): ``` if (document.activeElement && contains(this.options.selectors, document.activeElement)) { ``` should be: ``` if (document.activeElement && contains(document, this.options.selectors, document.activeElement)) { ```
venzersiz commented 2018-03-06 03:43:56 -05:00 (Migrated from github.com)

Thank you for your guide line.

Thank you for your guide line.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#135