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

document.querySelectorAll doesn't seem to work #17

Open
Dan503 opened this issue Jul 21, 2016 · 5 comments
Open

document.querySelectorAll doesn't seem to work #17

Dan503 opened this issue Jul 21, 2016 · 5 comments

Comments

@Dan503
Copy link

Dan503 commented Jul 21, 2016

I have this code

var _hoverTriggers = document.querySelectorAll('.JS-navigator__trigger--hover');

hoverintent(_hoverTriggers,
    function() {
        console.log('in');
    }, function() {
        console.log('out');
    }
);

And I am receiving this error:

Uncaught TypeError: e.addEventListener is not a function

The most common use for this plugin is triggering mega menus on navigation items. It doesn't make sense not supporting query selector all in this context.

@tristen
Copy link
Owner

tristen commented Jul 23, 2016

querySelectorAll returns a NodeList which isn't a type handled internally. You would need to iterate through the list and apply hoverintent to each element respectively. i.e

var _hoverTriggers = document.querySelectorAll('.JS-navigator__trigger--hover');

Array.prototype.forEach.call(_hoverTriggers, function(el) {
  hoverintent(el, hoverInFunc, hoverOutFunc);
});

@tristen
Copy link
Owner

tristen commented Jul 23, 2016

It might be a good idea to support NodeList though so I'll leave it open!

@Dan503
Copy link
Author

Dan503 commented Jul 23, 2016

Yuk! XP

This issue drove me back to the jQuery version of the plugin. You need to support node list if you want to be able to compete with it.

@lobenichou
Copy link

1+ On this. Would def make a difference 👍

@danielpost
Copy link

For what it's worth, it's not that hard to make hoverIntent work with querySelectorAll:

const toggles = document.querySelectorAll('[data-dropdown-open]');

if (!toggles) return;

for (const toggle of toggles) {
  hoverIntent(
    toggle,
    () => {
      toggle.setAttribute('data-dropdown-open', 'true');
    },
    () => {
      toggle.setAttribute('data-dropdown-open', 'false');
    }
  );
}

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

No branches or pull requests

4 participants