thednp / kute.js

KUTE.js is a JavaScript animation engine for modern browsers.

Home Page:http://thednp.github.io/kute.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Accept plain old Array of Elements for allTo and allFromTo

mistergibson opened this issue · comments

I notice that you only accept a Nodelist for processing multiple element targets. This data type is excruciatingly difficult to work with -- as opposed to the humble Array. I'd really like more flexibility on gathering a list of targets and sending them into a KUTE. I can easily construct an Array of Elements about a dozen ways, which makes the entire thing much more fun.

What would it take to support this additional way of accepting multiple elements?

Thanks

Sounds interesting enough for me. It would take some time to queue this up into main focus.

@mistergibson

I'm now working on the next version of KUTE.js, is this OK to you?

function selector(el, multi) {
  try{
    let requestedElem;
    if (multi){
      requestedElem = el instanceof HTMLCollection 
                               || el instanceof NodeList 
                               || el instanceof Array && el[0] instanceof Element 
                               ? el : document.querySelectorAll(el);
    } else {
      requestedElem = el instanceof Element ? el : document.querySelector(el);
    }
    return requestedElem;
  } catch(e){
    console.error(`${e}: Element(s) not found or incorrect selector: ${el}`)
  }

}