All files helpers.js

54.76% Statements 23/42
18.18% Branches 4/22
65% Functions 13/20
54.76% Lines 23/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131      2x 12x   2x       2x 2x       20x 20x       20x 20x                                                                               119x 119x               96x               129x 129x       60x       4x         129x         8x 1x   7x 7x         10x       10x                                        
import * as R from "ramda";
 
export function setCSSes(el, csses) {
  Object.keys(csses).forEach((k) => {
    el.style[k] = csses[k];
  });
  return el;
}
 
export function addClass(ele, className) {
  ele.classList.add(className)
  return ele
}
 
export function removeClass(ele, className) {
  ele.classList.remove(className)
  return ele
}
 
export function removeAttrs(ele, attrs) {
  R.forEach(ele.removeAttribute.bind(ele))(attrs)
  return ele
}
 
export function isLeftButton(e) {
  if ('touches' in e) {
    return e.touches.length === 1;
  }
  if ('buttons' in e) {
    return e.buttons === 1;
  }
  if ('button' in e) {
    return e.button === 0;
  }
  return false;
}
 
export function checkIsTable(ele) {
  return ele
    &&
    typeof ele === 'object'
    &&
    'nodeType' in ele
    &&
    ele.nodeType === 1
    &&
    ele.cloneNode
    &&
    ele.nodeName === 'TABLE';
}
 
export function emptyContent(ele) {
  ele.innerHTML = ''
  return ele
}
 
export function isNodeCol(node) {
  return node.nodeName === 'COL' && node.nodeName === 'COLGROUP'
}
 
export function appendDOMChild(parentNode, childNode) {
  parentNode.appendChild(childNode);
  return parentNode;
}
 
export function removeDom(node) {
  return node.parentNode.removeChild(node)
}
 
export function prop(obj, name) {
  return obj[name]
}
 
export function rect(node) {
  return node.getBoundingClientRect()
}
 
export function setStyle(node, prop, value) {
  node.style[prop] = value
  return node
}
 
export function getCellByIndexInRow(index, row) {
  return row.children[index]
}
 
export function createArrByNumber(num) {
  return [...Array(num).keys()]
}
 
 
export function addPx(str) {
  return str + 'px'
}
 
// insert target before origin
export function insertBeforeSibling(toEle, fromEle) {
  if (!fromEle) {
    return;
  }
  toEle.parentNode.insertBefore(fromEle, toEle);
  return fromEle
}
 
// insert target after origin
export function appendSibling(toEle, fromEle) {
  Iif (!fromEle) {
    return;
  }
  // if row length is different
  toEle.parentNode.insertBefore(fromEle, toEle ? toEle.nextElementSibling : null);
};
 
export function getMouseDownEvent() {
  let event;
  if (document.createEvent) {
    event = document.createEvent("MouseEvent");
    event.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  } else {
    event = new MouseEvent('mousedown', {
      'view': window,
      'bubbles': true,
      'cancelable': true
    });
  }
  return event;
};