-
Notifications
You must be signed in to change notification settings - Fork 1
/
raphael.dropshadow.filter.js
57 lines (56 loc) · 2.22 KB
/
raphael.dropshadow.filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*!
* Raphael Drop Shadow Plugin 0.1
*
* by Daniel Hoffmann
*
* Based on Raphael Blur Plugin 0.1 by Dmitry Baranovskiy (http://raphaeljs.com)
* https://github.com/DmitryBaranovskiy/raphael/blob/master/plugins/raphael.blur.js
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*
*/
(function () {
if (!Raphael.vml) {
var $ = function (el, attr) {
if (attr) {
for (var key in attr) if (attr.hasOwnProperty(key)) {
el.setAttribute(key, attr[key]);
}
} else {
return document.createElementNS("http://www.w3.org/2000/svg", el);
}
};
Raphael.fn.addDropShadowFilter = function (size, offsetX, offsetY, opacity) {
opacity = opacity || 1;
if (size != "none") {
var fltr = $("filter"),
blur = $("feGaussianBlur"),
colorMatrix = $("feColorMatrix"),
offset = $("feOffset"),
merge = $("feMerge"),
mergeNodeShadow = $("feMergeNode"),
mergeNodeSource = $("feMergeNode");
fltr.id = "dropshadow";
$(fltr, {height: "130%", width: "130%"});
$(blur, {stdDeviation: +size});
$(blur, {in: "SourceAlpha"});
$(colorMatrix, {result: "bluralpha", type: "bluralpha", values: "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 "+opacity+" 0 "});
$(offset, {dx: offsetX, dy: offsetY, result: "offsetblur"});
$(mergeNodeShadow, {in: "offsetblur"});
$(mergeNodeSource, {in: "SourceGraphic"});
fltr.appendChild(blur);
fltr.appendChild(colorMatrix);
fltr.appendChild(offset);
fltr.appendChild(merge);
merge.appendChild(mergeNodeShadow);
merge.appendChild(mergeNodeSource);
this.defs.appendChild(fltr);
this._blur = fltr;
} else {
if (this._blur) {
this._blur.parentNode.removeChild(this._blur);
delete this._blur;
}
}
};
}
})();