<commit_before>
// original code from:
// http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/

let isIE = navigator.userAgent.match(/Trident/)
let requestFrame = (function () {
  let raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
    function (fn) { return window.setTimeout(fn, 20) }
  return function (fn) { return raf(fn) }
})()

let cancelFrame = (function () {
  let cancel = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame ||
    window.clearTimeout
  return function (id) { return cancel(id) }
})()

function resizeListener (e) {
  let win = e.target || e.srcElement
  if (win._raf) cancelFrame(win._raf)
  win._raf = requestFrame(function () {
    let trigger = win._trigger
    trigger._listeners.forEach(function (fn) {
      fn.call(trigger, e)
    })
  })
}

function addResizeListener(element, fn) {
  if (!element._listeners || element._listeners.length) {
    element._listeners = []
    if (getComputedStyle(element).position == 'static') element.style.position = 'relative'
    let obj = element._trigger = document.createElement('object')
    obj.setAttribute('style', 'display:block;position:absolute;top:0;left:0;height:100%;width:100%;overflow:hidden;pointer-events:none;z-index:-1;')
    obj._el = element
    obj.onload = function () {
      this.contentDocument.defaultView._trigger = this._el
      this.contentDocument.defaultView.addEventListener('resize', resizeListener)
    }

    obj.type = 'text/html'
    if (isIE) element.appendChild(obj)
    obj.data = 'about:blank'
    if (!isIE) element.appendChild(obj)
  }
  element._listeners.push(fn)
}

function removeResizeListener(element, fn) {
  element._listeners.splice(element._listeners.indexOf(fn), 1)
  if (!element._listeners.length) {
    if (element._trigger.contentDocument)
      element._trigger.contentDocument.defaultView.removeEventListener('resize', resizeListener)
    // element._trigger = !element.removeChild(element._trigger)
    element.removeChild(element._trigger)
  }
}

export default {
  addResizeListener,
  removeResizeListener
}
<commit_msg>fix resize listener<commit_after>
// original code from:
// http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/

let isIE = navigator.userAgent.match(/Trident/)
let requestFrame = (function () {
  let raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
    function (fn) { return window.setTimeout(fn, 20) }
  return function (fn) { return raf(fn) }
})()

let cancelFrame = (function () {
  let cancel = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame ||
    window.clearTimeout
  return function (id) { return cancel(id) }
})()

function resizeListener (e) {
  let win = e.target || e.srcElement
  if (win._raf) cancelFrame(win._raf)
  win._raf = requestFrame(function () {
    let trigger = win._trigger
    trigger._listeners.forEach(function (fn) {
      fn.call(trigger, e)
    })
  })
}

function addResizeListener(element, fn) {
  if (!element._listeners || element._listeners.length) {
    element._listeners = []
    if (getComputedStyle(element).position == 'static') element.style.position = 'relative'
    let obj = element._trigger = document.createElement('object')
    obj.setAttribute('style', 'display:block;position:absolute;top:0;left:0;height:100%;width:100%;overflow:hidden;pointer-events:none;z-index:-1;')
    obj._el = element
    obj.onload = function () {
      this.contentDocument.defaultView._trigger = this._el
      this.contentDocument.defaultView.addEventListener('resize', resizeListener)
    }

    obj.type = 'text/html'
    if (isIE) element.appendChild(obj)
    obj.data = 'about:blank'
    if (!isIE) element.appendChild(obj)
  }
  element._listeners.push(fn)
}

function removeResizeListener(element, fn) {
  if (!element._listeners) return
  element._listeners.splice(element._listeners.indexOf(fn), 1)
  if (!element._listeners.length) {
    if (element._trigger.contentDocument)
      element._trigger.contentDocument.defaultView.removeEventListener('resize', resizeListener)
    // element._trigger = !element.removeChild(element._trigger)
    element.removeChild(element._trigger)
  }
}

export default {
  addResizeListener,
  removeResizeListener
}

{'fraction_non_alphanumeric': 0.13336326897171083, 'fraction_numerical': 0.00898069151324652, 'mean_word_length': 4.452876376988984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2952960', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1330, 'n_words': 233}