1 /*!
  2  * Raphael Blur Plugin 0.1
  3  *
  4  * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
  5  * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
  6  */
  7 
  8 (function () {
  9     if (Raphael.vml) {
 10         var reg = / progid:\S+Blur\([^\)]+\)/g;
 11         Raphael.el.blur = function (size) {
 12             var s = this.node.style,
 13                 f = s.filter;
 14             f = f.replace(reg, "");
 15             if (size != "none") {
 16                 s.filter = f + " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (+size || 1.5) + ")";
 17                 s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
 18             } else {
 19                 s.filter = f;
 20                 s.margin = 0;
 21             }
 22         };
 23     } else {
 24         var $ = function (el, attr) {
 25             if (attr) {
 26                 for (var key in attr) if (attr.hasOwnProperty(key)) {
 27                     el.setAttribute(key, attr[key]);
 28                 }
 29             } else {
 30                 return doc.createElementNS("http://www.w3.org/2000/svg", el);
 31             }
 32         };
 33         Raphael.el.blur = function (size) {
 34             // Experimental. No WebKit support.
 35             if (size != "none") {
 36                 var fltr = $("filter"),
 37                     blur = $("feGaussianBlur");
 38                 fltr.id = "r" + (Raphael.idGenerator++).toString(36);
 39                 $(blur, {stdDeviation: +size || 1.5});
 40                 fltr.appendChild(blur);
 41                 this.paper.defs.appendChild(fltr);
 42                 this._blur = fltr;
 43                 $(this.node, {filter: "url(#" + fltr.id + ")"});
 44             } else {
 45                 if (this._blur) {
 46                     this._blur.parentNode.removeChild(this._blur);
 47                     delete this._blur;
 48                 }
 49                 this.node.removeAttribute("filter");
 50             }
 51         };
 52     }
 53 })();