toolkit/javascript/d3/src/core/selection-style.js
changeset 47 c0b4a8b5a012
equal deleted inserted replaced
46:efd9c589177a 47:c0b4a8b5a012
       
     1 d3_selectionPrototype.style = function(name, value, priority) {
       
     2   if (arguments.length < 3) priority = "";
       
     3 
       
     4   // If no value is specified, return the first value.
       
     5   if (arguments.length < 2) return window
       
     6       .getComputedStyle(this.node(), null)
       
     7       .getPropertyValue(name);
       
     8 
       
     9   function styleNull() {
       
    10     this.style.removeProperty(name);
       
    11   }
       
    12 
       
    13   function styleConstant() {
       
    14     this.style.setProperty(name, value, priority);
       
    15   }
       
    16 
       
    17   function styleFunction() {
       
    18     var x = value.apply(this, arguments);
       
    19     if (x == null) this.style.removeProperty(name);
       
    20     else this.style.setProperty(name, x, priority);
       
    21   }
       
    22 
       
    23   return this.each(value == null
       
    24       ? styleNull : (typeof value === "function"
       
    25       ? styleFunction : styleConstant));
       
    26 };