Sha256: 2b3271c0c302a49069b24341af45207c499d9303b00d6eb8764ada6fb9ff3014

Contents?: true

Size: 940 Bytes

Versions: 2

Compression:

Stored size: 940 Bytes

Contents

var Plotline = Plotline || {};
Plotline.Utils = {
  ready: function(callback) {
    if (document.readyState != 'loading'){
      callback();
    } else {
      document.addEventListener('DOMContentLoaded', callback);
    }
  },

  // Source: https://remysharp.com/2010/07/21/throttling-function-calls
  debounce: function(fn, delay) {
    var timer = null;
    return function () {
      var context = this, args = arguments;
      clearTimeout(timer);
      timer = setTimeout(function () {
        fn.apply(context, args);
      }, delay);
    };
  },

  toggleClass: function(el, className) {
    if (el.classList) {
      el.classList.toggle(className);
    } else {
      var classes = el.className.split(' ');
      var existingIndex = classes.indexOf(className);

      if (existingIndex >= 0)
        classes.splice(existingIndex, 1);
      else
        classes.push(className);

      el.className = classes.join(' ');
    }
  }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plotline-0.1.1 app/assets/javascripts/plotline/plotline-utils.js
plotline-0.1.0 app/assets/javascripts/plotline/plotline-utils.js