1 /*! 2 * Raphael Shadow Plugin 0.2 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 Raphael.shadow = function (x, y, w, h, options) { 9 // options format: { 10 // size: 0..1, shadow size 11 // color: "#000", placeholder colour 12 // stroke: "#000", placeholder stroke colour 13 // shadow: "#000", shadow colour 14 // r: 5, radius of placeholder rounded corners 15 // } 16 options = options || {}; 17 var t = ~~(size * .3 + .5), 18 size = (options.size || 1) * 10, 19 color = options.color || "#fff", 20 stroke = options.stroke || color, 21 shadowColor = options.shadow || "#000", 22 R = options.r || 3, 23 s = size, 24 b = size * 2, 25 r = b + s, 26 rg = this.format("r{0}-{0}", shadowColor), 27 rect = "rect", 28 circ = "circle", 29 none = "none"; 30 var res = this([ 31 x - s, y - t, w + (x = s) * 2, h + (y = t) + b, 32 {type: rect, x: x - s, y: y - t, width: b + s, height: h + y + b, stroke: none, fill: this.format("180-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x - s + 1, y - t + r, b, h + y + b - r * 2 + .9]}, 33 {type: rect, x: x + w - b, y: y - t, width: b + s, height: h + y + b, stroke: none, fill: this.format("0-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x + w - s + 1, y - t + r, b, h + y + b - r * 2]}, 34 {type: rect, x: x + b - 1, y: y + h - s, width: w + b, height: b + s, stroke: none, fill: this.format("270-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x + b, y + h - s, w + b - r * 2, b + s]}, 35 {type: rect, x: x + s - 1, y: y - t, width: w + b, height: b + s, stroke: none, fill: this.format("90-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x + b, y - t, w + b - r * 2, s + t + 1]}, 36 {type: circ, cx: x + b, cy: y + h - s, r: r, stroke: none, fill: rg, opacity: 0, "clip-rect": [x - s, y + h - s + .999, r, r]}, 37 {type: circ, cx: x + w - b, cy: y + h - s, r: r, stroke: none, fill: rg, opacity: 0, "clip-rect": [x + w - b, y + h - s, r, r]}, 38 {type: circ, cx: x + b, cy: y - t + r, r: r, stroke: none, fill: rg, opacity: 0, "clip-rect": [x - s, y - t, r, r]}, 39 {type: circ, cx: x + w - b, cy: y - t + r, r: r , stroke: none, fill: rg, opacity: 0, "clip-rect": [x + w - b, y - t, r, r]}, 40 {type: rect, x: x, y: y, width: w, height: h, r: R, fill: color, stroke: stroke} 41 ]); 42 return res[0].paper; 43 };