Sha256: aed8fb3d7735dc75c72a20944f198b91de8af2232a7b6724342f7291227d92ed

Contents?: true

Size: 1.65 KB

Versions: 25

Compression:

Stored size: 1.65 KB

Contents

d3_selectionPrototype.classed = function(name, value) {
  var names = name.split(d3_selection_classedWhitespace),
      n = names.length,
      i = -1;
  if (arguments.length > 1) {
    while (++i < n) d3_selection_classed.call(this, names[i], value);
    return this;
  } else {
    while (++i < n) if (!d3_selection_classed.call(this, names[i])) return false;
    return true;
  }
};

var d3_selection_classedWhitespace = /\s+/g;

function d3_selection_classed(name, value) {
  var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");

  // If no value is specified, return the first value.
  if (arguments.length < 2) {
    var node = this.node();
    if (c = node.classList) return c.contains(name);
    var c = node.className;
    re.lastIndex = 0;
    return re.test(c.baseVal != null ? c.baseVal : c);
  }

  function classedAdd() {
    if (c = this.classList) return c.add(name);
    var c = this.className,
        cb = c.baseVal != null,
        cv = cb ? c.baseVal : c;
    re.lastIndex = 0;
    if (!re.test(cv)) {
      cv = d3_collapse(cv + " " + name);
      if (cb) c.baseVal = cv;
      else this.className = cv;
    }
  }

  function classedRemove() {
    if (c = this.classList) return c.remove(name);
    var c = this.className,
        cb = c.baseVal != null,
        cv = cb ? c.baseVal : c;
    cv = d3_collapse(cv.replace(re, " "));
    if (cb) c.baseVal = cv;
    else this.className = cv;
  }

  function classedFunction() {
    (value.apply(this, arguments)
        ? classedAdd
        : classedRemove).call(this);
  }

  return this.each(typeof value === "function"
      ? classedFunction : value
      ? classedAdd
      : classedRemove);
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
picky-statistics-4.5.0 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.4.2 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.4.1 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.4.0 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.3.2 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.3.1 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.3.0 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.2.4 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.2.3 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.2.2 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.2.1 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.2.0 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.1.0 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.0.9 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.0.8 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.0.7 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.0.6 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.0.5 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.0.4 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js
picky-statistics-4.0.3 lib/picky-statistics/application/javascripts/d3/src/core/selection-classed.js