<commit_before>import { listenOpts } from '../../utils/event.js'
import { getVmOfNode, isVmChildOf } from '../../utils/vm.js'

let timer

const
  { notPassiveCapture, passiveCapture } = listenOpts,
  handlers = {
    click: [],
    focus: []
  }

function execHandlers (list, evt) {
  for (let i = list.length - 1; i >= 0; i--) {
    if (list[i](evt) === void 0) {
      return
    }
  }
}

function globalHandler (evt) {
  clearTimeout(timer)

  if (evt.type === 'focusin') {
    timer = setTimeout(() => {
      execHandlers(handlers.focus, evt)
    }, 200)
  }
  else {
    execHandlers(handlers.click, evt)
  }
}

export default {
  name: 'click-outside',

  bind (el, { value, arg }, vnode) {
    const vmEl = vnode.componentInstance || vnode.context

    const ctx = {
      trigger: value,
      toggleEl: arg,

      handler (evt) {
        const target = evt.target

        if (
          target !== void 0 &&
          target.nodeType !== 8 &&
          (
            ctx.toggleEl === void 0 ||
            ctx.toggleEl.contains(target) === false
          ) &&
          (
            target === document.body ||
            isVmChildOf(getVmOfNode(target), vmEl) === false
          )
        ) {
          // mark the event as beeing processed by clickOutside
          // used to prevent refocus after menu close
          evt.qClickOutside = true

          return ctx.trigger(evt)<commit_msg>fix(ClickOutside): Disregard events emitted on html elements (#5322)<commit_after>import { listenOpts } from '../../utils/event.js'
import { getVmOfNode, isVmChildOf } from '../../utils/vm.js'

let timer

const
  { notPassiveCapture, passiveCapture } = listenOpts,
  handlers = {
    click: [],
    focus: []
  }

function execHandlers (list, evt) {
  for (let i = list.length - 1; i >= 0; i--) {
    if (list[i](evt) === void 0) {
      return
    }
  }
}

function globalHandler (evt) {
  clearTimeout(timer)

  if (evt.type === 'focusin') {
    timer = setTimeout(() => {
      execHandlers(handlers.focus, evt)
    }, 200)
  }
  else {
    execHandlers(handlers.click, evt)
  }
}

export default {
  name: 'click-outside',

  bind (el, { value, arg }, vnode) {
    const vmEl = vnode.componentInstance || vnode.context

    const ctx = {
      trigger: value,
      toggleEl: arg,

      handler (evt) {
        const target = evt.target

        if (
          target !== void 0 &&
          target.nodeType !== 8 &&
          // directives that prevent click by using pointer-events none generate click on html element
          target !== document.documentElement &&
          (
            ctx.toggleEl === void 0 ||
            ctx.toggleEl.contains(target) === false
          ) &&
          (
            target === document.body ||
            isVmChildOf(getVmOfNode(target), vmEl) === false
          )
        ) {
          // mark the event as beeing processed by clickOutside
          // used to prevent refocus after menu close
          evt.qClickOutside = true

          return ctx.trigger(evt)
{'fraction_non_alphanumeric': 0.13322314049586778, 'fraction_numerical': 0.007272727272727273, 'mean_word_length': 1.9783464566929134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2124235', 'n_tokens_mistral': 952, 'n_tokens_neox': 939, 'n_words': 239}