Exemplo n.º 1
0
 hasParent(...$p) {
   let $tests = $p.map(p => p._el);
   let parent = this._el.parentNode;
   while (parent) {
     if (isOneOf(parent, ...$tests)) return true;
     parent = parent.parentNode;
   }
   return false;
 }
Exemplo n.º 2
0
export function $(query, context=null) {
  if (!query) return null;
  const c = context ? context._el : document.documentElement;
  const el = (typeof query === 'string') ? c.querySelector(query) : query;

  if (!el) return null;
  if (el.$el) return el.$el;

  if (isOneOf(el, window, document.body, document.documentElement))
    return new WindowElement(el);

  const tagName = (el.tagName || '').toLowerCase();
  if (svgTags.indexOf(tagName) >= 0) return new SVGElement(el);
  if (formTags.indexOf(tagName) >= 0) return new FormElement(el);
  if (tagName === 'canvas') return new CanvasElement(el);
  if (isOneOf(tagName, 'video', 'audio')) return new MediaElement(el);

  return new Element(el);
}