All files / services common-functions.js

0% Statements 0/17
0% Branches 0/4
0% Functions 0/8
0% Lines 0/17
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                                                                                       
import $ from 'jquery';
 
export function findClosestElement(box, className) {
  const regex = new RegExp(`(^|\\s)${className}(\\s|$)`, 'gi');
  while (!regex.test(box.className)) {
    box = box.parentNode;
    if (!box) {
      return null;
    }
  }
  return box;
}
 
export function toggleBoxCollapse(box, boxBody, icon) {
  if (box.className.indexOf('collapsed-box') !== -1) {
    icon.className = icon.className.replace(/fa-plus/g, 'fa-minus');
    $(boxBody).slideDown(500, 'swing', () => {
        box.classList.remove('collapsed-box');
      }
    );
  } else {
    icon.className = icon.className.replace(/fa-minus/g, 'fa-plus');
    $(boxBody).slideUp(500, 'swing', () => {
        box.classList.add('collapsed-box');
      }
    );
  }
}
 
export function removeBox(box) {
  $(box).slideUp(500, 'swing');
}
 
export function initialate() {
  function bootstrapTooltips(selector) {
    $('body').tooltip({ selector });
  }
  return { bootstrapTooltips };
}
 
export function toggleDropdown(selector, classes) {
  selector.classList.toggle(classes);
}