import DefaultDOMElement from './DefaultDOMElement'

export function findParentDOMElement(nativeEl) {
  while(nativeEl) {
    let el = DefaultDOMElement.unwrap(nativeEl)
    if (el) return el
    nativeEl = nativeEl.parentNode
  }
}

export function findParent(el, selector) {
  while(el) {
    if (el.is(selector)) return el
    el = el.getParent()
  }
}

export function stop(event) {
  event.stopPropagation()
}

export function stopAndPrevent(event) {
  event.stopPropagation()
  event.preventDefault()
}

export function walk(el, cb) {
  _walk(el, cb, 0)
}

function _walk(el, cb, level) {
  cb(el, level)
  if (el.getChildCount() > 0) {
    let it = el.getChildNodeIterator()
    while(it.hasNext()) {
      _walk(it.next(), cb, level+1)
    }
  }
}

export function isRightButton(event) {
  let isRightButton = false
  if (event.hasOwnProperty("which")) {
    isRightButton = (event.which === 3)
  } else if (event.hasOwnProperty("button")) {
    isRightButton = (event.button === 2)
  }
  return isRightButton
}

@@ -1013,8 +1013,400 @@
 utton%0A%7D%0A
+%0Aexport function getBoundingRect(el) %7B%0A  let _rect = el.getNativeElement().getBoundingClientRect()%0A  return %7B%0A    top: _rect.top,%0A    left: _rect.left,%0A    height: _rect.height,%0A    width: _rect.width%0A  %7D%0A%7D%0A%0Aexport function isXInside(x, rect) %7B%0A  return x %3E= rect.left && x %3C= rect.left+rect.width%0A%7D%0A%0Aexport function isYInside(y, rect) %7B%0A  return y %3E= rect.top && y %3C= rect.top+rect.height%0A%7D%0A

Introduce more domHelpers.