Plugins
[raphael] / plugins / raphael.blur.js
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 if (Raphael.vml) {
9     Raphael.el.blur = function (size) {
10         var s = this.node.style,
11             f = s.filter;
12         f = f.replace(/ progid:\S+Blur\([^\)]+\)/g, "");
13         if (size != "none") {
14             s.filter = f + " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (+size || 1.5) + ")";
15             s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
16         } else {
17             s.filter = f;
18             s.margin = 0;
19         }
20     };
21 } else {
22     Raphael.el.blur = function (size) {
23         // Experimental. No WebKit support.
24         if (size != "none") {
25             var fltr = $("filter"),
26                 blur = $("feGaussianBlur");
27             fltr.id = "r" + (Raphael.idGenerator++).toString(36);
28             $(blur, {stdDeviation: +size || 1.5});
29             fltr.appendChild(blur);
30             this.paper.defs.appendChild(fltr);
31             this._blur = fltr;
32             $(this.node, {filter: "url(#" + fltr.id + ")"});
33         } else {
34             if (this._blur) {
35                 this._blur.parentNode.removeChild(this._blur);
36                 delete this._blur;
37             }
38             this.node.removeAttribute("filter");
39         }
40     };
41 }