      1 (function () {
      2
      3   function setStyle(element, styles) {
      4     var elementStyle = element.style, match;
      5     if (typeof styles === 'string') {
      6       element.style.cssText += ';' + styles;
      7       return styles.indexOf('opacity') > -1
      8         ? setOpacity(element, styles.match(/opacity:\s*(\d?\.?\d*)/)[1])
      9         : element;
     10     }
     11     for (var property in styles) {
     12       if (property === 'opacity') {
     13         setOpacity(element, styles[property]);
     14       }
     15       else {
     16         var normalizedProperty = (property === 'float' || property === 'cssFloat')
     17           ? (typeof elementStyle.styleFloat === 'undefined' ? 'cssFloat' : 'styleFloat')
     18           : property;
     19         elementStyle[normalizedProperty] = styles[property];
     20       }
     21     }
     22     return element;
     23   }
     24
     25   var parseEl = document.createElement('div'),
     26       supportsOpacity = typeof parseEl.style.opacity === 'string',
     27       supportsFilters = typeof parseEl.style.filter === 'string',
     28       view = document.defaultView,
     29       supportsGCS = view && typeof view.getComputedStyle !== 'undefined',
     30       reOpacity = /alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,
     31       setOpacity = function (element) { return element; };
     32
     33   if (supportsOpacity) {
     34     /** @ignore */
     35     setOpacity = function(element, value) {
     36       element.style.opacity = value;
     37       return element;
     38     };
     39   }
     40   else if (supportsFilters) {
     41     /** @ignore */
     42     setOpacity = function(element, value) {
     43       var es = element.style;
     44       if (element.currentStyle && !element.currentStyle.hasLayout) {
     45         es.zoom = 1;
     46       }
     47       if (reOpacity.test(es.filter)) {
     48         value = value >= 0.9999 ? '' : ('alpha(opacity=' + (value * 100) + ')');
     49         es.filter = es.filter.replace(reOpacity, value);
     50       }
     51       else {
     52         es.filter += ' alpha(opacity=' + (value * 100) + ')';
     53       }
     54       return element;
     55     };
     56   }
     57
     58   fabric.util.setStyle = setStyle;
     59
     60 })();