Bug fixes & docs update
[raphael] / raphael.svg.js
1 // ┌─────────────────────────────────────────────────────────────────────┐ \\
2 // │ Raphaël 2 - JavaScript Vector Library                               │ \\
3 // ├─────────────────────────────────────────────────────────────────────┤ \\
4 // │ SVG Module                                                          │ \\
5 // ├─────────────────────────────────────────────────────────────────────┤ \\
6 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
7 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
8 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
9 // └─────────────────────────────────────────────────────────────────────┘ \\
10 window.Raphael.svg && function (R) {
11     var has = "hasOwnProperty",
12         Str = String,
13         toFloat = parseFloat,
14         toInt = parseInt,
15         math = Math,
16         mmax = math.max,
17         abs = math.abs,
18         pow = math.pow,
19         separator = /[, ]+/,
20         eve = R.eve,
21         E = "",
22         S = " ";
23     // SVG
24     var xlink = "http://www.w3.org/1999/xlink",
25         markers = {
26             block: "M5,0 0,2.5 5,5z",
27             classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
28             diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
29             open: "M6,1 1,3.5 6,6",
30             oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
31         },
32         markerCounter = {};
33     R.toString = function () {
34         return  "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
35     };
36     var $ = function (el, attr) {
37         if (attr) {
38             if (typeof el == "string") {
39                 el = $(el);
40             }
41             for (var key in attr) if (attr[has](key)) {
42                 if (key.substring(0, 6) == "xlink:") {
43                     el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
44                 } else {
45                     el.setAttribute(key, Str(attr[key]));
46                 }
47             }
48         } else {
49             el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
50             el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
51         }
52         return el;
53     },
54     gradients = {},
55     rgGrad = /^url\(#(.*)\)$/,
56     removeGradientFill = function (node, paper) {
57         var oid = node.getAttribute("fill");
58         oid = oid && oid.match(rgGrad);
59         if (oid && !--gradients[oid[1]]) {
60             delete gradients[oid[1]];
61             paper.defs.removeChild(R._g.doc.getElementById(oid[1]));
62         }
63     },
64     addGradientFill = function (element, gradient) {
65         var type = "linear",
66             id = element.id + gradient,
67             fx = .5, fy = .5,
68             o = element.node,
69             SVG = element.paper,
70             s = o.style,
71             el = R._g.doc.getElementById(id);
72         if (!el) {
73             gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
74                 type = "radial";
75                 if (_fx && _fy) {
76                     fx = toFloat(_fx);
77                     fy = toFloat(_fy);
78                     var dir = ((fy > .5) * 2 - 1);
79                     pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
80                         (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
81                         fy != .5 &&
82                         (fy = fy.toFixed(5) - 1e-5 * dir);
83                 }
84                 return E;
85             });
86             gradient = gradient.split(/\s*\-\s*/);
87             if (type == "linear") {
88                 var angle = gradient.shift();
89                 angle = -toFloat(angle);
90                 if (isNaN(angle)) {
91                     return null;
92                 }
93                 var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
94                     max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
95                 vector[2] *= max;
96                 vector[3] *= max;
97                 if (vector[2] < 0) {
98                     vector[0] = -vector[2];
99                     vector[2] = 0;
100                 }
101                 if (vector[3] < 0) {
102                     vector[1] = -vector[3];
103                     vector[3] = 0;
104                 }
105             }
106             var dots = R._parseDots(gradient);
107             if (!dots) {
108                 return null;
109             }
110             if (element.gradient) {
111                 SVG.defs.removeChild(element.gradient);
112                 delete element.gradient;
113             }
114
115             id = id.replace(/[\(\)\s,\xb0#]/g, "-");
116             el = $(type + "Gradient", {id: id});
117             element.gradient = el;
118             $(el, type == "radial" ? {
119                 fx: fx,
120                 fy: fy
121             } : {
122                 x1: vector[0],
123                 y1: vector[1],
124                 x2: vector[2],
125                 y2: vector[3],
126                 gradientTransform: element.matrix.invert()
127             });
128             SVG.defs.appendChild(el);
129             for (var i = 0, ii = dots.length; i < ii; i++) {
130                 el.appendChild($("stop", {
131                     offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
132                     "stop-color": dots[i].color || "#fff"
133                 }));
134             }
135         }
136         $(o, {
137             fill: "url(#" + id + ")",
138             opacity: 1,
139             "fill-opacity": 1
140         });
141         s.fill = E;
142         s.opacity = 1;
143         s.fillOpacity = 1;
144         return 1;
145     },
146     updatePosition = function (o) {
147         var bbox = o.getBBox(1);
148         $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
149     },
150     addArrow = function (o, value, isEnd) {
151         if (o.type == "path") {
152             var values = Str(value).toLowerCase().split("-"),
153                 p = o.paper,
154                 se = isEnd ? "end" : "start",
155                 node = o.node,
156                 attrs = o.attrs,
157                 stroke = attrs["stroke-width"],
158                 i = values.length,
159                 type = "classic",
160                 from,
161                 to,
162                 dx,
163                 refX,
164                 attr,
165                 w = 3,
166                 h = 3,
167                 t = 5;
168             while (i--) {
169                 switch (values[i]) {
170                     case "block":
171                     case "classic":
172                     case "oval":
173                     case "diamond":
174                     case "open":
175                     case "none":
176                         type = values[i];
177                         break;
178                     case "wide": h = 5; break;
179                     case "narrow": h = 2; break;
180                     case "long": w = 5; break;
181                     case "short": w = 2; break;
182                 }
183             }
184             if (type == "open") {
185                 w += 2;
186                 h += 2;
187                 t += 2;
188                 dx = 1;
189                 refX = isEnd ? 4 : 1;
190                 attr = {
191                     fill: "none",
192                     stroke: attrs.stroke
193                 };
194             } else {
195                 refX = dx = w / 2;
196                 attr = {
197                     fill: attrs.stroke,
198                     stroke: "none"
199                 };
200             }
201             if (o._.arrows) {
202                 if (isEnd) {
203                     o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
204                     o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
205                 } else {
206                     o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
207                     o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
208                 }
209             } else {
210                 o._.arrows = {};
211             }
212             if (type != "none") {
213                 var pathId = "raphael-marker-" + type,
214                     markerId = "raphael-marker-" + se + type + w + h;
215                 if (!R._g.doc.getElementById(pathId)) {
216                     p.defs.appendChild($($("path"), {
217                         "stroke-linecap": "round",
218                         d: markers[type],
219                         id: pathId
220                     }));
221                     markerCounter[pathId] = 1;
222                 } else {
223                     markerCounter[pathId]++;
224                 }
225                 var marker = R._g.doc.getElementById(markerId),
226                     use;
227                 if (!marker) {
228                     marker = $($("marker"), {
229                         id: markerId,
230                         markerHeight: h,
231                         markerWidth: w,
232                         orient: "auto",
233                         refX: refX,
234                         refY: h / 2
235                     });
236                     use = $($("use"), {
237                         "xlink:href": "#" + pathId,
238                         transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
239                         "stroke-width": 1 / ((w / t + h / t) / 2)
240                     });
241                     marker.appendChild(use);
242                     p.defs.appendChild(marker);
243                     markerCounter[markerId] = 1;
244                 } else {
245                     markerCounter[markerId]++;
246                     use = marker.getElementsByTagName("use")[0];
247                 }
248                 $(use, attr);
249                 var delta = dx * (type != "diamond" && type != "oval");
250                 if (isEnd) {
251                     from = o._.arrows.startdx * stroke || 0;
252                     to = R.getTotalLength(attrs.path) - delta * stroke;
253                 } else {
254                     from = delta * stroke;
255                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
256                 }
257                 attr = {};
258                 attr["marker-" + se] = "url(#" + markerId + ")";
259                 if (to || from) {
260                     attr.d = Raphael.getSubpath(attrs.path, from, to);
261                 }
262                 $(node, attr);
263                 o._.arrows[se + "Path"] = pathId;
264                 o._.arrows[se + "Marker"] = markerId;
265                 o._.arrows[se + "dx"] = delta;
266                 o._.arrows[se + "Type"] = type;
267                 o._.arrows[se + "String"] = value;
268             } else {
269                 if (isEnd) {
270                     from = o._.arrows.startdx * stroke || 0;
271                     to = R.getTotalLength(attrs.path) - from;
272                 } else {
273                     from = 0;
274                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
275                 }
276                 o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
277                 delete o._.arrows[se + "Path"];
278                 delete o._.arrows[se + "Marker"];
279                 delete o._.arrows[se + "dx"];
280                 delete o._.arrows[se + "Type"];
281                 delete o._.arrows[se + "String"];
282             }
283             for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
284                 var item = R._g.doc.getElementById(attr);
285                 item && item.parentNode.removeChild(item);
286             }
287         }
288     },
289     dasharray = {
290         "": [0],
291         "none": [0],
292         "-": [3, 1],
293         ".": [1, 1],
294         "-.": [3, 1, 1, 1],
295         "-..": [3, 1, 1, 1, 1, 1],
296         ". ": [1, 3],
297         "- ": [4, 3],
298         "--": [8, 3],
299         "- .": [4, 3, 1, 3],
300         "--.": [8, 3, 1, 3],
301         "--..": [8, 3, 1, 3, 1, 3]
302     },
303     addDashes = function (o, value, params) {
304         value = dasharray[Str(value).toLowerCase()];
305         if (value) {
306             var width = o.attrs["stroke-width"] || "1",
307                 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
308                 dashes = [],
309                 i = value.length;
310             while (i--) {
311                 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
312             }
313             $(o.node, {"stroke-dasharray": dashes.join(",")});
314         }
315     },
316     setFillAndStroke = function (o, params) {
317         var node = o.node,
318             attrs = o.attrs,
319             vis = node.style.visibility;
320         node.style.visibility = "hidden";
321         for (var att in params) {
322             if (params[has](att)) {
323                 if (!R._availableAttrs[has](att)) {
324                     continue;
325                 }
326                 var value = params[att];
327                 attrs[att] = value;
328                 switch (att) {
329                     case "blur":
330                         o.blur(value);
331                         break;
332                     case "href":
333                     case "title":
334                     case "target":
335                         var pn = node.parentNode;
336                         if (pn.tagName.toLowerCase() != "a") {
337                             var hl = $("a");
338                             pn.insertBefore(hl, node);
339                             hl.appendChild(node);
340                             pn = hl;
341                         }
342                         if (att == "target" && value == "blank") {
343                             pn.setAttributeNS(xlink, "show", "new");
344                         } else {
345                             pn.setAttributeNS(xlink, att, value);
346                         }
347                         break;
348                     case "cursor":
349                         node.style.cursor = value;
350                         break;
351                     case "transform":
352                         o.transform(value);
353                         break;
354                     case "arrow-start":
355                         addArrow(o, value);
356                         break;
357                     case "arrow-end":
358                         addArrow(o, value, 1);
359                         break;
360                     case "clip-rect":
361                         var rect = Str(value).split(separator);
362                         if (rect.length == 4) {
363                             o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
364                             var el = $("clipPath"),
365                                 rc = $("rect");
366                             el.id = R._createUUID();
367                             $(rc, {
368                                 x: rect[0],
369                                 y: rect[1],
370                                 width: rect[2],
371                                 height: rect[3]
372                             });
373                             el.appendChild(rc);
374                             o.paper.defs.appendChild(el);
375                             $(node, {"clip-path": "url(#" + el.id + ")"});
376                             o.clip = rc;
377                         }
378                         if (!value) {
379                             var clip = R._g.doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, E));
380                             clip && clip.parentNode.removeChild(clip);
381                             $(node, {"clip-path": E});
382                             delete o.clip;
383                         }
384                     break;
385                     case "path":
386                         if (o.type == "path") {
387                             $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
388                             o._.dirty = 1;
389                             if (o._.arrows) {
390                                 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
391                                 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
392                             }
393                         }
394                         break;
395                     case "width":
396                         node.setAttribute(att, value);
397                         o._.dirty = 1;
398                         if (attrs.fx) {
399                             att = "x";
400                             value = attrs.x;
401                         } else {
402                             break;
403                         }
404                     case "x":
405                         if (attrs.fx) {
406                             value = -attrs.x - (attrs.width || 0);
407                         }
408                     case "rx":
409                         if (att == "rx" && o.type == "rect") {
410                             break;
411                         }
412                     case "cx":
413                         node.setAttribute(att, value);
414                         o.pattern && updatePosition(o);
415                         o._.dirty = 1;
416                         break;
417                     case "height":
418                         node.setAttribute(att, value);
419                         o._.dirty = 1;
420                         if (attrs.fy) {
421                             att = "y";
422                             value = attrs.y;
423                         } else {
424                             break;
425                         }
426                     case "y":
427                         if (attrs.fy) {
428                             value = -attrs.y - (attrs.height || 0);
429                         }
430                     case "ry":
431                         if (att == "ry" && o.type == "rect") {
432                             break;
433                         }
434                     case "cy":
435                         node.setAttribute(att, value);
436                         o.pattern && updatePosition(o);
437                         o._.dirty = 1;
438                         break;
439                     case "r":
440                         if (o.type == "rect") {
441                             $(node, {rx: value, ry: value});
442                         } else {
443                             node.setAttribute(att, value);
444                         }
445                         o._.dirty = 1;
446                         break;
447                     case "src":
448                         if (o.type == "image") {
449                             node.setAttributeNS(xlink, "href", value);
450                         }
451                         break;
452                     case "stroke-width":
453                         if (o._.sx != 1 || o._.sy != 1) {
454                             value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
455                         }
456                         if (o.paper._vbSize) {
457                             value *= o.paper._vbSize;
458                         }
459                         node.setAttribute(att, value);
460                         if (attrs["stroke-dasharray"]) {
461                             addDashes(o, attrs["stroke-dasharray"], params);
462                         }
463                         if (o._.arrows) {
464                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
465                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
466                         }
467                         break;
468                     case "stroke-dasharray":
469                         addDashes(o, value, params);
470                         break;
471                     case "fill":
472                         var isURL = Str(value).match(R._ISURL);
473                         if (isURL) {
474                             el = $("pattern");
475                             var ig = $("image");
476                             el.id = R._createUUID();
477                             $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
478                             $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
479                             el.appendChild(ig);
480
481                             (function (el) {
482                                 R._preload(isURL[1], function () {
483                                     var w = this.offsetWidth,
484                                         h = this.offsetHeight;
485                                     $(el, {width: w, height: h});
486                                     $(ig, {width: w, height: h});
487                                     o.paper.safari();
488                                 });
489                             })(el);
490                             o.paper.defs.appendChild(el);
491                             node.style.fill = "url(#" + el.id + ")";
492                             $(node, {fill: "url(#" + el.id + ")"});
493                             o.pattern = el;
494                             o.pattern && updatePosition(o);
495                             break;
496                         }
497                         var clr = R.getRGB(value);
498                         if (!clr.error) {
499                             delete params.gradient;
500                             delete attrs.gradient;
501                             !R.is(attrs.opacity, "undefined") &&
502                                 R.is(params.opacity, "undefined") &&
503                                 $(node, {opacity: attrs.opacity});
504                             !R.is(attrs["fill-opacity"], "undefined") &&
505                                 R.is(params["fill-opacity"], "undefined") &&
506                                 $(node, {"fill-opacity": attrs["fill-opacity"]});
507                         } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
508                             if ("opacity" in attrs || "fill-opacity" in attrs) {
509                                 var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
510                                 if (gradient) {
511                                     var stops = gradient.getElementsByTagName("stop");
512                                     $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
513                                 }
514                             }
515                             attrs.gradient = value;
516                             attrs.fill = "none";
517                             break;
518                         }
519                         clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
520                     case "stroke":
521                         clr = R.getRGB(value);
522                         node.setAttribute(att, clr.hex);
523                         att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
524                         if (att == "stroke" && o._.arrows) {
525                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
526                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
527                         }
528                         break;
529                     case "gradient":
530                         (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
531                         break;
532                     case "opacity":
533                         if (attrs.gradient && !attrs[has]("stroke-opacity")) {
534                             $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
535                         }
536                         // fall
537                     case "fill-opacity":
538                         if (attrs.gradient) {
539                             gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
540                             if (gradient) {
541                                 stops = gradient.getElementsByTagName("stop");
542                                 $(stops[stops.length - 1], {"stop-opacity": value});
543                             }
544                             break;
545                         }
546                     default:
547                         att == "font-size" && (value = toInt(value, 10) + "px");
548                         var cssrule = att.replace(/(\-.)/g, function (w) {
549                             return w.substring(1).toUpperCase();
550                         });
551                         node.style[cssrule] = value;
552                         o._.dirty = 1;
553                         node.setAttribute(att, value);
554                         break;
555                 }
556             }
557         }
558
559         tuneText(o, params);
560         node.style.visibility = vis;
561     },
562     leading = 1.2,
563     tuneText = function (el, params) {
564         if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
565             return;
566         }
567         var a = el.attrs,
568             node = el.node,
569             fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
570
571         if (params[has]("text")) {
572             a.text = params.text;
573             while (node.firstChild) {
574                 node.removeChild(node.firstChild);
575             }
576             var texts = Str(params.text).split("\n"),
577                 tspans = [],
578                 tspan;
579             for (var i = 0, ii = texts.length; i < ii; i++) {
580                 tspan = $("tspan");
581                 i && $(tspan, {dy: fontSize * leading, x: a.x});
582                 tspan.appendChild(R._g.doc.createTextNode(texts[i]));
583                 node.appendChild(tspan);
584                 tspans[i] = tspan;
585             }
586         } else {
587             tspans = node.getElementsByTagName("tspan");
588             for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
589                 $(tspans[i], {dy: fontSize * leading, x: a.x});
590             } else {
591                 $(tspans[0], {dy: 0});
592             }
593         }
594         $(node, {x: a.x, y: a.y});
595         el._.dirty = 1;
596         var bb = el._getBBox(),
597             dif = a.y - (bb.y + bb.height / 2);
598         dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
599     },
600     Element = function (node, svg) {
601         var X = 0,
602             Y = 0;
603         /*\
604          * Element.node
605          [ property (object) ]
606          **
607          * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
608          **
609          * Note: Don’t mess with it.
610          > Usage
611          | // draw a circle at coordinate 10,10 with radius of 10
612          | var c = paper.circle(10, 10, 10);
613          | c.node.onclick = function () {
614          |     c.attr("fill", "red");
615          | };
616         \*/
617         this[0] = this.node = node;
618         /*\
619          * Element.raphael
620          [ property (object) ]
621          **
622          * Internal reference to @Raphael object. In case it is not available.
623          > Usage
624          | Raphael.el.red = function () {
625          |     var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
626          |     hsb.h = 1;
627          |     this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
628          | }
629         \*/
630         node.raphael = true;
631         /*\
632          * Element.id
633          [ property (number) ]
634          **
635          * Unique id of the element. Especially usesful when you want to listen to events of the element, 
636          * because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
637         \*/
638         this.id = R._oid++;
639         node.raphaelid = this.id;
640         this.matrix = R.matrix();
641         this.realPath = null;
642         /*\
643          * Element.paper
644          [ property (object) ]
645          **
646          * Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
647          > Usage
648          | Raphael.el.cross = function () {
649          |     this.attr({fill: "red"});
650          |     this.paper.path("M10,10L50,50M50,10L10,50")
651          |         .attr({stroke: "red"});
652          | }
653         \*/
654         this.paper = svg;
655         this.attrs = this.attrs || {};
656         this._ = {
657             transform: [],
658             sx: 1,
659             sy: 1,
660             deg: 0,
661             dx: 0,
662             dy: 0,
663             dirty: 1
664         };
665         !svg.bottom && (svg.bottom = this);
666         /*\
667          * Element.prev
668          [ property (object) ]
669          **
670          * Reference to the previous element in the hierarchy.
671         \*/
672         this.prev = svg.top;
673         svg.top && (svg.top.next = this);
674         svg.top = this;
675         /*\
676          * Element.next
677          [ property (object) ]
678          **
679          * Reference to the next element in the hierarchy.
680         \*/
681         this.next = null;
682     },
683     elproto = R.el;
684
685     Element.prototype = elproto;
686     elproto.constructor = Element;
687
688     R._engine.path = function (pathString, SVG) {
689         var el = $("path");
690         SVG.canvas && SVG.canvas.appendChild(el);
691         var p = new Element(el, SVG);
692         p.type = "path";
693         setFillAndStroke(p, {
694             fill: "none",
695             stroke: "#000",
696             path: pathString
697         });
698         return p;
699     };
700     /*\
701      * Element.rotate
702      [ method ]
703      **
704      * Adds rotation by given angle around given point to the list of
705      * transformations of the element.
706      > Parameters
707      - deg (number) angle in degrees
708      - cx (number) #optional x coordinate of the centre of rotation
709      - cy (number) #optional y coordinate of the centre of rotation
710      * If cx & cy aren’t specified centre of the shape is used as a point of rotation.
711      = (object) @Element
712     \*/
713     elproto.rotate = function (deg, cx, cy) {
714         if (this.removed) {
715             return this;
716         }
717         deg = Str(deg).split(separator);
718         if (deg.length - 1) {
719             cx = toFloat(deg[1]);
720             cy = toFloat(deg[2]);
721         }
722         deg = toFloat(deg[0]);
723         (cy == null) && (cx = cy);
724         if (cx == null || cy == null) {
725             var bbox = this.getBBox(1);
726             cx = bbox.x + bbox.width / 2;
727             cy = bbox.y + bbox.height / 2;
728         }
729         this.transform(this._.transform.concat([["r", deg, cx, cy]]));
730         return this;
731     };
732     /*\
733      * Element.scale
734      [ method ]
735      **
736      * Adds scale by given amount relative to given point to the list of
737      * transformations of the element.
738      > Parameters
739      - sx (number) horisontal scale amount
740      - sy (number) vertical scale amount
741      - cx (number) #optional x coordinate of the centre of scale
742      - cy (number) #optional y coordinate of the centre of scale
743      * If cx & cy aren’t specified centre of the shape is used instead.
744      = (object) @Element
745     \*/
746     elproto.scale = function (sx, sy, cx, cy) {
747         if (this.removed) {
748             return this;
749         }
750         sx = Str(sx).split(separator);
751         if (sx.length - 1) {
752             sy = toFloat(sx[1]);
753             cx = toFloat(sx[2]);
754             cy = toFloat(sx[3]);
755         }
756         sx = toFloat(sx[0]);
757         (sy == null) && (sy = sx);
758         (cy == null) && (cx = cy);
759         if (cx == null || cy == null) {
760             var bbox = this.getBBox(1);
761         }
762         cx = cx == null ? bbox.x + bbox.width / 2 : cx;
763         cy = cy == null ? bbox.y + bbox.height / 2 : cy;
764         this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
765         return this;
766     };
767     /*\
768      * Element.translate
769      [ method ]
770      **
771      * Adds translation by given amount to the list of transformations of the element.
772      > Parameters
773      - dx (number) horisontal shift
774      - dy (number) vertical shift
775      = (object) @Element
776     \*/
777     elproto.translate = function (dx, dy) {
778         if (this.removed) {
779             return this;
780         }
781         dx = Str(dx).split(separator);
782         if (dx.length - 1) {
783             dy = toFloat(dx[1]);
784         }
785         dx = toFloat(dx[0]) || 0;
786         dy = +dy || 0;
787         this.transform(this._.transform.concat([["t", dx, dy]]));
788         return this;
789     };
790     /*\
791      * Element.transform
792      [ method ]
793      **
794      * Adds transformation to the element which is separate to other attributes,
795      * i.e. translation doesn’t change `x` or `y` of the rectange. The format
796      * of transformation string is similar to the path string syntax:
797      | "t100,100r30,100,100s2,2,100,100r45s1.5"
798      * Each letter is a command. There are four commands: `t` is for translate, `r` is for rotate, `s` is for
799      * scale and `m` is for matrix.
800      *
801      * So, the example line above could be read like “translate by 100, 100; rotate 30° around 100, 100; scale twice around 100, 100;
802      * rotate 45° around centre; scale 1.5 times relative to centre”. As you can see rotate and scale commands have origin
803      * coordinates as optional parameters, the default is the centre point of the element.
804      * Matrix accepts six parameters.
805      > Usage
806      | var el = paper.rect(10, 20, 300, 200);
807      | // translate 100, 100, rotate 45°, translate -100, 0
808      | el.transform("t100,100r45t-100,0");
809      | // if you want you can append or prepend transformations
810      | el.transform("...t50,50");
811      | el.transform("s2...");
812      | // or even wrap
813      | el.transform("t50,50...t-50-50");
814      | // to reset transformation call method with empty string
815      | el.transform("");
816      | // to get current value call it without parameters
817      | console.log(el.transform());
818      > Parameters
819      - tstr (string) #optional transformation string
820      * If tstr isn’t specified
821      = (string) current transformation string
822      * else
823      = (object) @Element
824     \*/
825     elproto.transform = function (tstr) {
826         var _ = this._;
827         if (tstr == null) {
828             return _.transform;
829         }
830         R._extractTransform(this, tstr);
831
832         this.clip && $(this.clip, {transform: this.matrix.invert()});
833         this.pattern && updatePosition(this);
834         this.node && $(this.node, {transform: this.matrix});
835     
836         if (_.sx != 1 || _.sy != 1) {
837             var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
838             this.attr({"stroke-width": sw});
839         }
840
841         return this;
842     };
843     /*\
844      * Element.hide
845      [ method ]
846      **
847      * Makes element invisible. See @Element.show.
848      = (object) @Element
849     \*/
850     elproto.hide = function () {
851         !this.removed && this.paper.safari(this.node.style.display = "none");
852         return this;
853     };
854     /*\
855      * Element.show
856      [ method ]
857      **
858      * Makes element visible. See @Element.hide.
859      = (object) @Element
860     \*/
861     elproto.show = function () {
862         !this.removed && this.paper.safari(this.node.style.display = "");
863         return this;
864     };
865     /*\
866      * Element.remove
867      [ method ]
868      **
869      * Removes element form the paper.
870     \*/
871     elproto.remove = function () {
872         if (this.removed) {
873             return;
874         }
875         eve.unbind("*.*." + this.id);
876         R._tear(this, this.paper);
877         this.node.parentNode.removeChild(this.node);
878         for (var i in this) {
879             delete this[i];
880         }
881         this.removed = true;
882     };
883     elproto._getBBox = function () {
884         if (this.node.style.display == "none") {
885             this.show();
886             var hide = true;
887         }
888         var bbox = {};
889         try {
890             bbox = this.node.getBBox();
891         } catch(e) {
892             // Firefox 3.0.x plays badly here
893         } finally {
894             bbox = bbox || {};
895         }
896         hide && this.hide();
897         return bbox;
898     };
899     /*\
900      * Element.attr
901      [ method ]
902      **
903      * Sets the attributes of the element.
904      > Parameters
905      - attrName (string) attribute’s name
906      - value (string) value
907      * or
908      - params (object) object of name/value pairs
909      * or
910      - attrName (string) attribute’s name
911      * or
912      - attrNames (array) in this case method returns array of current values for given attribute names
913      = (object) @Element if attrsName & value or params are passed in.
914      = (...) value of the attribute if only attrsName is passed in.
915      = (array) array of values of the attribute if attrsNames is passed in.
916      = (object) object of attributes if nothing is passed in.
917      > Possible parameters
918      # <p>Please refer to the <a href="http://www.w3.org/TR/SVG/" title="The W3C Recommendation for the SVG language describes these properties in detail.">SVG specification</a> for an explanation of these parameters.</p>
919      o arrow-end (string) arrowhead on the end of the path. The format for string is `<type>[-<width>[-<length>]]`. Possible types: `classic`, `block`, `open`, `oval`, `diamond`, `none`, width: `wide`, `narrow`, `midium`, length: `long`, `short`, `midium`.
920      o clip-rect (string) comma or space separated values: x, y, width and height
921      o cursor (string) CSS type of the cursor
922      o cx (number)
923      o cy (number)
924      o fill (string) colour, gradient or image
925      o fill-opacity (number)
926      o font (string)
927      o font-family (string)
928      o font-size (number) font size in pixels
929      o font-weight (string)
930      o height (number)
931      o href (string) URL, if specified element behaves as hyperlink
932      o opacity (number)
933      o path (string) SVG path string format
934      o r (number)
935      o rx (number)
936      o ry (number)
937      o src (string) image URL, only works for @Element.image element
938      o stroke (string) stroke colour
939      o stroke-dasharray (string) [“”, “`-`”, “`.`”, “`-.`”, “`-..`”, “`. `”, “`- `”, “`--`”, “`- .`”, “`--.`”, “`--..`”]
940      o stroke-linecap (string) [“`butt`”, “`square`”, “`round`”]
941      o stroke-linejoin (string) [“`bevel`”, “`round`”, “`miter`”]
942      o stroke-miterlimit (number)
943      o stroke-opacity (number)
944      o stroke-width (number) stroke width in pixels, default is '1'
945      o target (string) used with href
946      o text (string) contents of the text element. Use `\n` for multiline text
947      o text-anchor (string) [“`start`”, “`middle`”, “`end`”], default is “`middle`”
948      o title (string) will create tooltip with a given text
949      o transform (string) see @Element.transform
950      o width (number)
951      o x (number)
952      o y (number)
953      > Gradients
954      * Linear gradient format: “`‹angle›-‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`90-#fff-#000`” – 90°
955      * gradient from white to black or “`0-#fff-#f00:20-#000`” – 0° gradient from white via red (at 20%) to black.
956      *
957      * radial gradient: “`r[(‹fx›, ‹fy›)]‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`r#fff-#000`” –
958      * gradient from white to black or “`r(0.25, 0.75)#fff-#000`” – gradient from white to black with focus point
959      * at 0.25, 0.75. Focus point coordinates are in 0..1 range. Radial gradients can only be applied to circles and ellipses.
960      > Path String
961      # <p>Please refer to <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path’s data attribute’s format are described in the SVG specification.">SVG documentation regarding path string</a>. Raphaël fully supports it.</p>
962      > Colour Parsing
963      # <ul>
964      #     <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
965      #     <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
966      #     <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
967      #     <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
968      #     <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
969      #     <li>rgba(•••, •••, •••, •••) — red, green and blue channels’ values: (“<code>rgba(200,&nbsp;100,&nbsp;0, .5)</code>”)</li>
970      #     <li>rgba(•••%, •••%, •••%, •••%) — same as above, but in %: (“<code>rgba(100%,&nbsp;175%,&nbsp;0%, 50%)</code>”)</li>
971      #     <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
972      #     <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
973      #     <li>hsba(•••, •••, •••, •••) — same as above, but with opacity</li>
974      #     <li>hsl(•••, •••, •••) — almost the same as hsb, see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV" title="HSL and HSV - Wikipedia, the free encyclopedia">Wikipedia page</a></li>
975      #     <li>hsl(•••%, •••%, •••%) — same as above, but in %</li>
976      #     <li>hsla(•••, •••, •••, •••) — same as above, but with opacity</li>
977      #     <li>Optionally for hsb and hsl you could specify hue as a degree: “<code>hsl(240deg,&nbsp;1,&nbsp;.5)</code>” or, if you want to go fancy, “<code>hsl(240°,&nbsp;1,&nbsp;.5)</code>”</li>
978      # </ul>
979     \*/
980     elproto.attr = function (name, value) {
981         if (this.removed) {
982             return this;
983         }
984         if (name == null) {
985             var res = {};
986             for (var a in this.attrs) if (this.attrs[has](a)) {
987                 res[a] = this.attrs[a];
988             }
989             res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
990             res.transform = this._.transform;
991             return res;
992         }
993         if (value == null && R.is(name, "string")) {
994             if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
995                 return this.attrs.gradient;
996             }
997             if (name == "transform") {
998                 return this._.transform;
999             }
1000             var names = name.split(separator),
1001                 out = {};
1002             for (var i = 0, ii = names.length; i < ii; i++) {
1003                 name = names[i];
1004                 if (name in this.attrs) {
1005                     out[name] = this.attrs[name];
1006                 } else if (R.is(this.paper.customAttributes[name], "function")) {
1007                     out[name] = this.paper.customAttributes[name].def;
1008                 } else {
1009                     out[name] = R._availableAttrs[name];
1010                 }
1011             }
1012             return ii - 1 ? out : out[names[0]];
1013         }
1014         if (value == null && R.is(name, "array")) {
1015             out = {};
1016             for (i = 0, ii = name.length; i < ii; i++) {
1017                 out[name[i]] = this.attr(name[i]);
1018             }
1019             return out;
1020         }
1021         if (value != null) {
1022             var params = {};
1023             params[name] = value;
1024         } else if (name != null && R.is(name, "object")) {
1025             params = name;
1026         }
1027         for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1028             var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
1029             this.attrs[key] = params[key];
1030             for (var subkey in par) if (par[has](subkey)) {
1031                 params[subkey] = par[subkey];
1032             }
1033         }
1034         setFillAndStroke(this, params);
1035         return this;
1036     };
1037     /*\
1038      * Element.toFront
1039      [ method ]
1040      **
1041      * Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
1042      = (object) @Element
1043     \*/
1044     elproto.toFront = function () {
1045         if (this.removed) {
1046             return this;
1047         }
1048         this.node.parentNode.appendChild(this.node);
1049         var svg = this.paper;
1050         svg.top != this && R._tofront(this, svg);
1051         return this;
1052     };
1053     /*\
1054      * Element.toBack
1055      [ method ]
1056      **
1057      * Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
1058      = (object) @Element
1059     \*/
1060     elproto.toBack = function () {
1061         if (this.removed) {
1062             return this;
1063         }
1064         if (this.node.parentNode.firstChild != this.node) {
1065             this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1066             R._toback(this, this.paper);
1067             var svg = this.paper;
1068         }
1069         return this;
1070     };
1071     /*\
1072      * Element.insertAfter
1073      [ method ]
1074      **
1075      * Inserts current object after the given one.
1076      = (object) @Element
1077     \*/
1078     elproto.insertAfter = function (element) {
1079         if (this.removed) {
1080             return this;
1081         }
1082         var node = element.node || element[element.length - 1].node;
1083         if (node.nextSibling) {
1084             node.parentNode.insertBefore(this.node, node.nextSibling);
1085         } else {
1086             node.parentNode.appendChild(this.node);
1087         }
1088         R._insertafter(this, element, this.paper);
1089         return this;
1090     };
1091     /*\
1092      * Element.insertBefore
1093      [ method ]
1094      **
1095      * Inserts current object before the given one.
1096      = (object) @Element
1097     \*/
1098     elproto.insertBefore = function (element) {
1099         if (this.removed) {
1100             return this;
1101         }
1102         var node = element.node || element[0].node;
1103         node.parentNode.insertBefore(this.node, node);
1104         R._insertbefore(this, element, this.paper);
1105         return this;
1106     };
1107     elproto.blur = function (size) {
1108         // Experimental. No Safari support. Use it on your own risk.
1109         var t = this;
1110         if (+size !== 0) {
1111             var fltr = $("filter"),
1112                 blur = $("feGaussianBlur");
1113             t.attrs.blur = size;
1114             fltr.id = R._createUUID();
1115             $(blur, {stdDeviation: +size || 1.5});
1116             fltr.appendChild(blur);
1117             t.paper.defs.appendChild(fltr);
1118             t._blur = fltr;
1119             $(t.node, {filter: "url(#" + fltr.id + ")"});
1120         } else {
1121             if (t._blur) {
1122                 t._blur.parentNode.removeChild(t._blur);
1123                 delete t._blur;
1124                 delete t.attrs.blur;
1125             }
1126             t.node.removeAttribute("filter");
1127         }
1128     };
1129     R._engine.circle = function (svg, x, y, r) {
1130         var el = $("circle");
1131         svg.canvas && svg.canvas.appendChild(el);
1132         var res = new Element(el, svg);
1133         res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1134         res.type = "circle";
1135         $(el, res.attrs);
1136         return res;
1137     };
1138     R._engine.rect = function (svg, x, y, w, h, r) {
1139         var el = $("rect");
1140         svg.canvas && svg.canvas.appendChild(el);
1141         var res = new Element(el, svg);
1142         res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1143         res.type = "rect";
1144         $(el, res.attrs);
1145         return res;
1146     };
1147     R._engine.ellipse = function (svg, x, y, rx, ry) {
1148         var el = $("ellipse");
1149         svg.canvas && svg.canvas.appendChild(el);
1150         var res = new Element(el, svg);
1151         res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1152         res.type = "ellipse";
1153         $(el, res.attrs);
1154         return res;
1155     };
1156     R._engine.image = function (svg, src, x, y, w, h) {
1157         var el = $("image");
1158         $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1159         el.setAttributeNS(xlink, "href", src);
1160         svg.canvas && svg.canvas.appendChild(el);
1161         var res = new Element(el, svg);
1162         res.attrs = {x: x, y: y, width: w, height: h, src: src};
1163         res.type = "image";
1164         return res;
1165     };
1166     R._engine.text = function (svg, x, y, text) {
1167         var el = $("text");
1168         // $(el, {x: x, y: y, "text-anchor": "middle"});
1169         svg.canvas && svg.canvas.appendChild(el);
1170         var res = new Element(el, svg);
1171         res.attrs = {
1172             x: x,
1173             y: y,
1174             "text-anchor": "middle",
1175             text: text,
1176             font: R._availableAttrs.font,
1177             stroke: "none",
1178             fill: "#000"
1179         };
1180         res.type = "text";
1181         setFillAndStroke(res, res.attrs);
1182         return res;
1183     };
1184     R._engine.setSize = function (width, height) {
1185         this.width = width || this.width;
1186         this.height = height || this.height;
1187         this.canvas.setAttribute("width", this.width);
1188         this.canvas.setAttribute("height", this.height);
1189         if (this._viewBox) {
1190             this.setViewBox.apply(this, this._viewBox);
1191         }
1192         return this;
1193     };
1194     R._engine.create = function () {
1195         var con = R._getContainer.apply(0, arguments),
1196             container = con && con.container,
1197             x = con.x,
1198             y = con.y,
1199             width = con.width,
1200             height = con.height;
1201         if (!container) {
1202             throw new Error("SVG container not found.");
1203         }
1204         var cnvs = $("svg"),
1205             css = "overflow:hidden;",
1206             isFloating;
1207         x = x || 0;
1208         y = y || 0;
1209         width = width || 512;
1210         height = height || 342;
1211         $(cnvs, {
1212             height: height,
1213             version: 1.1,
1214             width: width,
1215             xmlns: "http://www.w3.org/2000/svg"
1216         });
1217         if (container == 1) {
1218             cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
1219             R._g.doc.body.appendChild(cnvs);
1220             isFloating = 1;
1221         } else {
1222             cnvs.style.cssText = css + "position:relative";
1223             if (container.firstChild) {
1224                 container.insertBefore(cnvs, container.firstChild);
1225             } else {
1226                 container.appendChild(cnvs);
1227             }
1228         }
1229         container = new R._Paper;
1230         container.width = width;
1231         container.height = height;
1232         container.canvas = cnvs;
1233         // plugins.call(container, container, R.fn);
1234         container.clear();
1235         container._left = container._top = 0;
1236         isFloating && (container.renderfix = function () {});
1237         container.renderfix();
1238         return container;
1239     };
1240     R._engine.setViewBox = function (x, y, w, h, fit) {
1241         eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
1242         var size = mmax(w / this.width, h / this.height),
1243             top = this.top,
1244             aspectRatio = fit ? "meet" : "xMinYMin",
1245             vb,
1246             sw;
1247         if (x == null) {
1248             if (this._vbSize) {
1249                 size = 1;
1250             }
1251             delete this._vbSize;
1252             vb = "0 0 " + this.width + S + this.height;
1253         } else {
1254             this._vbSize = size;
1255             vb = x + S + y + S + w + S + h;
1256         }
1257         $(this.canvas, {
1258             viewBox: vb,
1259             preserveAspectRatio: aspectRatio
1260         });
1261         while (size && top) {
1262             sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
1263             top.attr({"stroke-width": sw});
1264             top._.dirty = 1;
1265             top._.dirtyT = 1;
1266             top = top.prev;
1267         }
1268         this._viewBox = [x, y, w, h, !!fit];
1269         return this;
1270     };
1271     /*\
1272      * Paper.renderfix
1273      [ method ]
1274      **
1275      * Fixes the issue of Firefox and IE9 regarding subpixel rendering. If paper is dependant
1276      * on other elements after reflow it could shift half pixel which cause for lines to lost their crispness.
1277      * This method fixes the issue.
1278      **
1279        Special thanks to Mariusz Nowak (http://www.medikoo.com/) for this method.
1280     \*/
1281     R.prototype.renderfix = function () {
1282         var cnvs = this.canvas,
1283             s = cnvs.style,
1284             pos = cnvs.getScreenCTM(),
1285             left = -pos.e % 1,
1286             top = -pos.f % 1;
1287         if (left || top) {
1288             if (left) {
1289                 this._left = (this._left + left) % 1;
1290                 s.left = this._left + "px";
1291             }
1292             if (top) {
1293                 this._top = (this._top + top) % 1;
1294                 s.top = this._top + "px";
1295             }
1296         }
1297     };
1298     /*\
1299      * Paper.clear
1300      [ method ]
1301      **
1302      * Clears the paper, i.e. removes all the elements.
1303     \*/
1304     R.prototype.clear = function () {
1305         R.eve("clear", this);
1306         var c = this.canvas;
1307         while (c.firstChild) {
1308             c.removeChild(c.firstChild);
1309         }
1310         this.bottom = this.top = null;
1311         (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
1312         c.appendChild(this.desc);
1313         c.appendChild(this.defs = $("defs"));
1314     };
1315     /*\
1316      * Paper.remove
1317      [ method ]
1318      **
1319      * Removes the paper from the DOM.
1320     \*/
1321     R.prototype.remove = function () {
1322         eve("remove", this);
1323         this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1324         for (var i in this) {
1325             this[i] = removed(i);
1326         }
1327     };
1328     var setproto = R.st;
1329     for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
1330         setproto[method] = (function (methodname) {
1331             return function () {
1332                 var arg = arguments;
1333                 return this.forEach(function (el) {
1334                     el[methodname].apply(el, arg);
1335                 });
1336             };
1337         })(method);
1338     }
1339 }(window.Raphael);