Fixed bug with path parsing and blur in IE v1.4.4
authorDmitry Baranovskiy <Dmitry@Baranovskiy.com>
Fri, 2 Jul 2010 12:36:45 +0000 (22:36 +1000)
committerDmitry Baranovskiy <Dmitry@Baranovskiy.com>
Fri, 2 Jul 2010 12:36:45 +0000 (22:36 +1000)
plugins/raphael.blur.js [new file with mode: 0644]
plugins/raphael.primitives.js

diff --git a/plugins/raphael.blur.js b/plugins/raphael.blur.js
new file mode 100644 (file)
index 0000000..2484641
--- /dev/null
@@ -0,0 +1,53 @@
+/*!
+ * Raphael Blur Plugin 0.1
+ *
+ * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
+ */
+
+(function () {
+    if (Raphael.vml) {
+        var reg = / progid:\S+Blur\([^\)]+\)/g;
+        Raphael.el.blur = function (size) {
+            var s = this.node.style,
+                f = s.filter;
+            f = f.replace(reg, "");
+            if (size != "none") {
+                s.filter = f + " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (+size || 1.5) + ")";
+                s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
+            } else {
+                s.filter = f;
+                s.margin = 0;
+            }
+        };
+    } else {
+        var $ = function (el, attr) {
+            if (attr) {
+                for (var key in attr) if (attr.hasOwnProperty(key)) {
+                    el.setAttribute(key, attr[key]);
+                }
+            } else {
+                return doc.createElementNS("http://www.w3.org/2000/svg", el);
+            }
+        };
+        Raphael.el.blur = function (size) {
+            // Experimental. No WebKit support.
+            if (size != "none") {
+                var fltr = $("filter"),
+                    blur = $("feGaussianBlur");
+                fltr.id = "r" + (Raphael.idGenerator++).toString(36);
+                $(blur, {stdDeviation: +size || 1.5});
+                fltr.appendChild(blur);
+                this.paper.defs.appendChild(fltr);
+                this._blur = fltr;
+                $(this.node, {filter: "url(#" + fltr.id + ")"});
+            } else {
+                if (this._blur) {
+                    this._blur.parentNode.removeChild(this._blur);
+                    delete this._blur;
+                }
+                this.node.removeAttribute("filter");
+            }
+        };
+    }
+})();
\ No newline at end of file
index af752cf..7104f79 100644 (file)
@@ -5,7 +5,7 @@
  * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
  */
 
-Raphael.fn.g.star = function (cx, cy, r, r2, rays) {
+Raphael.fn.star = function (cx, cy, r, r2, rays) {
     r2 = r2 || r * .382;
     rays = rays || 5;
     var points = ["M", cx, cy + r2, "L"],
@@ -41,6 +41,14 @@ Raphael.fn.spike = function (cx, cy, rout, rin, n) {
     points.push("z");
     return this.path(points);
 };
+Raphael.fn.polyline = function () {
+    var points = "M".concat(arguments[0] || 0, ",", arguments[1] || 0, "L");
+    for (var i = 2, ii = arguments.length - 1; i < ii; i++) {
+        points += arguments[i] + "," + arguments[++i];
+    }
+    arguments[ii].toLowerCase() == "z" && (points += "z");
+    return this.path(points);
+};
 Raphael.fn.polygon = function (cx, cy, r, n) {
     n = +n < 3 || !n ? 5 : n;
     var points = ["M", cx, cy - r, "L"],
@@ -86,6 +94,6 @@ Raphael.fn.plus = function (cx, cy, r) {
     r = r / 2;
     return this.path("M".concat(cx - r / 2, ",", cy - r / 2, "l", [0, -r, r, 0, 0, r, r, 0, 0, r, -r, 0, 0, r, -r, 0, 0, -r, -r, 0, 0, -r, "z"]));
 };
-Raphael.fn.g.arrow = function (cx, cy, r) {
+Raphael.fn.arrow = function (cx, cy, r) {
     return this.path("M".concat(cx - r * .7, ",", cy - r * .4, "l", [r * .6, 0, 0, -r * .4, r, r * .8, -r, r * .8, 0, -r * .4, -r * .6, 0], "z"));
 };