toolkit/javascript/d3/src/core/selection-property.js
author Nicolas Sauret <nicolas.sauret@iri.centrepompidou.fr>
Tue, 15 Apr 2014 17:46:09 +0200
changeset 48 1b2dffb4ac2b
parent 47 c0b4a8b5a012
permissions -rw-r--r--
add wiki (wikimd) delete publication (bootstrap)

d3_selectionPrototype.property = function(name, value) {

  // If no value is specified, return the first value.
  if (arguments.length < 2) return this.node()[name];

  function propertyNull() {
    delete this[name];
  }

  function propertyConstant() {
    this[name] = value;
  }

  function propertyFunction() {
    var x = value.apply(this, arguments);
    if (x == null) delete this[name];
    else this[name] = x;
  }

  return this.each(value == null
      ? propertyNull : (typeof value === "function"
      ? propertyFunction : propertyConstant));
};