<commit_before>/**
 * A collection of helper functions for general use.
 */
goog.provide('annotorious.dom');

/**
 * Computes the absolute top/left offset of a DOM element relative to the document.
 * @param {element} el the DOM element
 * @returns {object} an object containing the offset { top, left }
 */
annotorious.dom.getOffset = function(el) {
  var _x = 0;
  var _y = 0;
  
  while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
    _x += el.offsetLeft - el.scrollLeft;
    _y += el.offsetTop - el.scrollTop;
    el = el.offsetParent;
  }
  return { top: _y, left: _x };
}

/**
 * Checks whether a certain DOM element is (partly) within the current viewport.
 * Cf. http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
 * @param {element} el the DOM element to check for visibility
 * @returns {boolean} true if the element is within the current viewport
 */
annotorious.dom.isInViewport = function(el) {
  var top = el.offsetTop;
  var left = el.offsetLeft;
  var width = el.offsetWidth;
  var height = el.offsetHeight;

  while (el.offsetParent) {
    el = el.offsetParent;
    top += el.offsetTop;
    left += el.offsetLeft;
  }

  return (
    top < (window.pageYOffset + window.innerHeight) &&
    left < (window.pageXOffset + window.innerWidth) &&
    (top + height) > window.pageYOffset &&
    (left + width) > window.pageXOffset
  ); 
}

/**
 * Adds an additional handler function to window.onload, without overwriting existing ones.
 * @param {function} fn the handler function to add
 */
annotorious.dom.addOnLoadHandler = function(fn) {
  if (typeof window.onload == 'function') {
    var current = window.onload;
    window.onload = function() {
      current();
      fn();
    }
  } else {
    window.onload = fn;
  }   
}

/*
annotorious.dom.cancelBubble = function(event) {
 var e = event ? event : window.event;
 if (e.stopPropagation) e.stopPropagation();
 if (e.cancelBubble != null) e.cancelBubble = true;
}
*/
<commit_msg>Cleanup<commit_after>/**
 * A collection of helper functions for general use.
 */
goog.provide('annotorious.dom');

/**
 * Computes the absolute top/left offset of a DOM element relative to the document.
 * @param {element} el the DOM element
 * @returns {object} an object containing the offset { top, left }
 */
annotorious.dom.getOffset = function(el) {
  var _x = 0;
  var _y = 0;
  
  while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
    _x += el.offsetLeft - el.scrollLeft;
    _y += el.offsetTop - el.scrollTop;
    el = el.offsetParent;
  }
  return { top: _y, left: _x };
}

/**
 * Checks whether a certain DOM element is (partly) within the current viewport.
 * Cf. http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
 * @param {element} el the DOM element to check for visibility
 * @returns {boolean} true if the element is within the current viewport
 */
annotorious.dom.isInViewport = function(el) {
  var top = el.offsetTop;
  var left = el.offsetLeft;
  var width = el.offsetWidth;
  var height = el.offsetHeight;

  while (el.offsetParent) {
    el = el.offsetParent;
    top += el.offsetTop;
    left += el.offsetLeft;
  }

  return (
    top < (window.pageYOffset + window.innerHeight) &&
    left < (window.pageXOffset + window.innerWidth) &&
    (top + height) > window.pageYOffset &&
    (left + width) > window.pageXOffset
  ); 
}

/**
 * Adds an additional handler function to window.onload, without overwriting existing ones.
 * @param {function} fn the handler function to add
 */
annotorious.dom.addOnLoadHandler = function(fn) {
  if (typeof window.onload == 'function') {
    var current = window.onload;
    window.onload = function() {
      current();
      fn();
    }
  } else {
    window.onload = fn;
  }   
}

{'fraction_non_alphanumeric': 0.1319916361735494, 'fraction_numerical': 0.004181913225300575, 'mean_word_length': 3.2101210121012103, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3977847', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1243, 'n_words': 351}