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