Yep, as @Paul_Wilkins said, the $.hook
function makes it not so ugly.
Side note, I also considered a jQuery selector extension that would let you write code like this:
$(':hook(nav-menu-toggle)')
It was nice because you could mix it into selectors, making it much more versatile. Sadly, performance was attrocious. About 100x slower in my tests. Here’s the code, if you’re curious:
$.extend($.expr[':'], {
hook: function(el, index, meta) {
return el.getAttribute('data-hook') && $(el).is('[data-hook~="' + meta[3] + '"]');
}
});
If someone can find a way to make the performance not suck, I’ll buy them a beer.