X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=raphael.js;h=75728ffa68c12948c7e5604b015880bae8ee41f1;hb=61f72045caa90d2a7dc79bba26181705dcada2aa;hp=3daae30cd7ded779db3431e2c1b71712086acd47;hpb=b69b846b00c615f411826b983c338e78f9e49c8b;p=raphael diff --git a/raphael.js b/raphael.js index 3daae30..75728ff 100644 --- a/raphael.js +++ b/raphael.js @@ -1,5 +1,5 @@ // ┌─────────────────────────────────────────────────────────────────────┐ \\ -// │ Raphaël 2.0 - JavaScript Vector Library │ \\ +// │ Raphaël 2.0.1 - JavaScript Vector Library │ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\ // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\ // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ @@ -7,14 +7,14 @@ // └─────────────────────────────────────────────────────────────────────┘ \\ // ┌──────────────────────────────────────────────────────────────────────────────────────┐ \\ -// │ Eve 0.3.0 - JavaScript Events Library │ \\ +// │ Eve 0.4.0 - JavaScript Events Library │ \\ // ├──────────────────────────────────────────────────────────────────────────────────────┤ \\ // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\ // │ Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. │ \\ // └──────────────────────────────────────────────────────────────────────────────────────┘ \\ (function (glob) { - var version = "0.3.0", + var version = "0.4.0", has = "hasOwnProperty", separator = /[\.\/]/, wildcard = "*", @@ -28,6 +28,7 @@ eve = function (name, scope) { var e = events, + oldstop = stop, args = Array.prototype.slice.call(arguments, 2), listeners = eve.listeners(name), z = 0, @@ -50,6 +51,7 @@ l = queue[indexed[z++]]; out.push(l.apply(scope, args)); if (stop) { + stop = oldstop; return out; } } @@ -59,6 +61,7 @@ if (l.zIndex == indexed[z]) { out.push(l.apply(scope, args)); if (stop) { + stop = oldstop; return out; } do { @@ -66,6 +69,7 @@ l = queue[indexed[z]]; l && out.push(l.apply(scope, args)); if (stop) { + stop = oldstop; return out; } } while (l) @@ -75,10 +79,12 @@ } else { out.push(l.apply(scope, args)); if (stop) { + stop = oldstop; return out; } } } + stop = oldstop; return out.length ? out : null; }; @@ -151,9 +157,10 @@ e, key, splice, + i, ii, j, jj, cur = [events]; - for (var i = 0, ii = names.length; i < ii; i++) { - for (var j = 0; j < cur.length; j += splice.length - 2) { + for (i = 0, ii = names.length; i < ii; i++) { + for (j = 0; j < cur.length; j += splice.length - 2) { splice = [j, 1]; e = cur[j].n; if (names[i] != wildcard) { @@ -173,16 +180,16 @@ while (e.n) { if (f) { if (e.f) { - for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) { - e.f.splice(i, 1); + for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) { + e.f.splice(j, 1); break; } !e.f.length && delete e.f; } for (key in e.n) if (e.n[has](key) && e.n[key].f) { var funcs = e.n[key].f; - for (i = 0, ii = funcs.length; i < ii; i++) if (funcs[i] == f) { - funcs.splice(i, 1); + for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) { + funcs.splice(j, 1); break; } !funcs.length && delete e.n[key].f; @@ -198,6 +205,14 @@ } }; + eve.once = function (name, f) { + var f2 = function () { + f.apply(this, arguments); + eve.unbind(name, f2); + }; + return eve.on(name, f2); + }; + eve.version = version; eve.toString = function () { return "You are running Eve " + version; @@ -206,29 +221,20 @@ })(this); // ┌─────────────────────────────────────────────────────────────────────┐ \\ -// │ "Raphaël 2.0" - JavaScript Vector Library │ \\ +// │ "Raphaël 2.0.1" - JavaScript Vector Library │ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\ // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\ // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // └─────────────────────────────────────────────────────────────────────┘ \\ + (function () { function R(first) { if (R.is(first, "function")) { return loaded ? first() : eve.on("DOMload", first); } else if (R.is(first, array)) { - var a = first, - cnv = R._engine.create[apply](R, a.splice(0, 3 + R.is(a[0], nu))), - res = cnv.set(), - i = 0, - ii = a.length, - j; - for (; i < ii; i++) { - j = a[i] || {}; - elements[has](j.type) && res.push(cnv[j.type]().attr(j)); - } - return res; + return R._engine.create[apply](R, first.splice(0, 3 + R.is(first[0], nu))).add(first); } else { var args = Array.prototype.slice.call(arguments, 0); if (R.is(args[args.length - 1], "function")) { @@ -241,7 +247,7 @@ } } } - R.version = "2.0.0"; + R.version = "2.0.1"; R.eve = eve; var loaded, separator = /[, ]+/, @@ -259,7 +265,8 @@ }, Paper = function () { - this.customAttributes = {}; + + this.ca = this.customAttributes = {}; }, paperproto, appendChild = "appendChild", @@ -270,7 +277,7 @@ S = " ", Str = String, split = "split", - events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel".split(S), + events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S), touchMap = { mousedown: "touchstart", mousemove: "touchmove", @@ -318,6 +325,7 @@ gradient: 0, height: 0, href: "http://raphaeljs.com/", + "letter-spacing": 0, opacity: 1, path: "M0,0", r: 0, @@ -416,11 +424,11 @@ return rectPath(bbox.x, bbox.y, bbox.width, bbox.height); } }, - mapPath = function (path, matrix) { + mapPath = R.mapPath = function (path, matrix) { if (!matrix) { return path; } - var x, y, i, j, pathi; + var x, y, i, j, ii, jj, pathi; path = path2curve(path); for (i = 0, ii = path.length; i < ii; i++) { pathi = path[i]; @@ -466,7 +474,7 @@ return o instanceof Array; } return (type == "null" && o === null) || - (type == typeof o) || + (type == typeof o && o !== null) || (type == "object" && o === Object(o)) || (type == "array" && Array.isArray && Array.isArray(o)) || objectToString.call(o).slice(8, -1).toLowerCase() == type; @@ -513,7 +521,8 @@ return value; }; - var createUUID = R._createUUID = (function (uuidRegEx, uuidReplacer) { + + var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) { return function () { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase(); }; @@ -528,8 +537,8 @@ eve("setWindow", R, g.win, newwin); g.win = newwin; g.doc = g.win.document; - if (initWin) { - initWin(g.win); + if (R._engine.initWin) { + R._engine.initWin(g.win); } }; var toHex = function (color) { @@ -640,7 +649,7 @@ clr.v = rgb.b; } else { clr = {hex: "none"}; - crl.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1; + clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1; } } clr.toString = rgbtoString; @@ -761,7 +770,7 @@ var preload = R._preload = function (src, f) { var img = g.doc.createElement("img"); - img.style.cssText = "position:absolute;left:-9999em;top-9999em"; + img.style.cssText = "position:absolute;left:-9999em;top:-9999em"; img.onload = function () { f.call(this); this.onload = null; @@ -807,7 +816,7 @@ red = toInt((t = rgb[3].charAt(1)) + t, 16); } if (rgb[4]) { - values = rgb[4].split(commaSpaces); + values = rgb[4][split](commaSpaces); red = toFloat(values[0]); values[0].slice(-1) == "%" && (red *= 2.55); green = toFloat(values[1]); @@ -818,7 +827,7 @@ values[3] && values[3].slice(-1) == "%" && (opacity /= 100); } if (rgb[5]) { - values = rgb[5].split(commaSpaces); + values = rgb[5][split](commaSpaces); red = toFloat(values[0]); values[0].slice(-1) == "%" && (red *= 2.55); green = toFloat(values[1]); @@ -831,7 +840,7 @@ return R.hsb2rgb(red, green, blue, opacity); } if (rgb[6]) { - values = rgb[6].split(commaSpaces); + values = rgb[6][split](commaSpaces); red = toFloat(values[0]); values[0].slice(-1) == "%" && (red *= 2.55); green = toFloat(values[1]); @@ -957,7 +966,7 @@ c.replace(pathValues, function (a, b) { b && params.push(+b); }); - data.push([name][concat](params)); + data.push([b][concat](params)); }); } data.toString = R._path2string; @@ -992,6 +1001,11 @@ alpha: alpha }; }; + R._removedFactory = function (methodname) { + return function () { + throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object"); + }; + }; var pathDimensions = cacher(function (path) { if (!path) { return {x: 0, y: 0, width: 0, height: 0}; @@ -1308,7 +1322,7 @@ if (recursive) { return [m2, m3, m4][concat](res); } else { - res = [m2, m3, m4][concat](res).join().split(","); + res = [m2, m3, m4][concat](res).join()[split](","); var newres = []; for (var i = 0, ii = res.length; i < ii; i++) { newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; @@ -1537,11 +1551,6 @@ el2.prev = el; el.next = el2; }, - removed = function (methodname) { - return function () { - throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object"); - }; - }, extractTransform = R._extractTransform = function (el, tstr) { if (tstr == null) { return el._.transform; @@ -1560,31 +1569,57 @@ for (var i = 0, ii = tdata.length; i < ii; i++) { var t = tdata[i], tlen = t.length, + command = Str(t[0]).toLowerCase(), + absolute = t[0] != command, + inver = absolute ? m.invert() : 0, + x1, + y1, + x2, + y2, bb; - t[0] = Str(t[0]).toLowerCase(); - if (t[0] == "t" && tlen == 3) { - m.translate(t[1], t[2]); - } else if (t[0] == "r") { + if (command == "t" && tlen == 3) { + if (absolute) { + x1 = inver.x(0, 0); + y1 = inver.y(0, 0); + x2 = inver.x(t[1], t[2]); + y2 = inver.y(t[1], t[2]); + m.translate(x2 - x1, y2 - y1); + } else { + m.translate(t[1], t[2]); + } + } else if (command == "r") { if (tlen == 2) { bb = bb || el.getBBox(1); m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2); deg += t[1]; } else if (tlen == 4) { - m.rotate(t[1], t[2], t[3]); + if (absolute) { + x2 = inver.x(t[2], t[3]); + y2 = inver.y(t[2], t[3]); + m.rotate(t[1], x2, y2); + } else { + m.rotate(t[1], t[2], t[3]); + } deg += t[1]; } - } else if (t[0] == "s") { + } else if (command == "s") { if (tlen == 2 || tlen == 3) { bb = bb || el.getBBox(1); m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2); sx *= t[1]; sy *= t[tlen - 1]; } else if (tlen == 5) { - m.scale(t[1], t[2], t[3], t[4]); + if (absolute) { + x2 = inver.x(t[3], t[4]); + y2 = inver.y(t[3], t[4]); + m.scale(t[1], t[2], x2, y2); + } else { + m.scale(t[1], t[2], t[3], t[4]); + } sx *= t[1]; sy *= t[2]; } - } else if (t[0] == "m" && tlen == 7) { + } else if (command == "m" && tlen == 7) { m.add(t[1], t[2], t[3], t[4], t[5], t[6]); } _.dirtyT = 1; @@ -1608,20 +1643,21 @@ } }, getEmpty = function (item) { - switch (item[0]) { - case "t": return ["t", 0, 0]; - case "m": return ["m", 1, 0, 0, 1, 0, 0]; + var l = item[0]; + switch (l.toLowerCase()) { + case "t": return [l, 0, 0]; + case "m": return [l, 1, 0, 0, 1, 0, 0]; case "r": if (item.length == 4) { - return ["r", 0, item[2], item[3]]; + return [l, 0, item[2], item[3]]; } else { - return ["r", 0]; + return [l, 0]; } case "s": if (item.length == 5) { - return ["s", 1, 1, item[3], item[4]]; + return [l, 1, 1, item[3], item[4]]; } else if (item.length == 3) { - return ["s", 1, 1]; + return [l, 1, 1]; } else { - return ["s", 1]; + return [l, 1]; } } }, @@ -1638,8 +1674,8 @@ tt1 = t1[i] || getEmpty(t2[i]); tt2 = t2[i] || getEmpty(tt1); if ((tt1[0] != tt2[0]) || - (tt1[0] == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) || - (tt1[0] == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4])) + (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) || + (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4])) ) { return; } @@ -1838,10 +1874,15 @@ return out; }; - matrixproto.toTransformString = function () { - var s = this.split(); + matrixproto.toTransformString = function (shorter) { + var s = shorter || this[split](); if (s.isSimple) { - return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0]; + s.scalex = +s.scalex.toFixed(4); + s.scaley = +s.scaley.toFixed(4); + s.rotate = +s.rotate.toFixed(4); + return (s.dx && s.dy ? "t" + [s.dx, s.dy] : E) + + (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) + + (s.rotate ? "r" + [s.rotate, 0, 0] : E); } else { return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)]; } @@ -1978,37 +2019,7 @@ elproto = R.el = {}; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + for (var i = events.length; i--;) { (function (eventName) { R[eventName] = elproto[eventName] = function (fn, scope) { @@ -2066,6 +2077,7 @@ elproto.unhover = function (f_in, f_out) { return this.unmouseover(f_in).unmouseout(f_out); }; + var draggable = []; elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) { function start(e) { @@ -2083,6 +2095,7 @@ eve("drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e); } this._drag = {}; + draggable.push({el: this, start: start}); this.mousedown(start); return this; }; @@ -2092,13 +2105,13 @@ }; elproto.undrag = function () { - var i = drag.length; - while (i--) if (drag[i].el == this) { - R.unmousedown(drag[i].start); - drag.splice(i++, 1); + var i = draggable.length; + while (i--) if (draggable[i].el == this) { + this.unmousedown(draggable[i].start); + draggable.splice(i, 1); eve.unbind("drag.*." + this.id); } - !drag.length && R.unmousemove(dragMove).unmouseup(dragUp); + !draggable.length && R.unmousemove(dragMove).unmouseup(dragUp); }; paperproto.circle = function (x, y, r) { @@ -2265,7 +2278,9 @@ if (this.removed) { return null; } - return this.paper[this.type]().attr(this.attr()); + var out = this.paper[this.type]().attr(this.attr()); + this.__set__ && this.__set__.push(out); + return out; }; elproto.glow = function (glow) { @@ -2496,7 +2511,9 @@ t = e.t, that = e.el, set = {}, - now; + now, + init = {}, + key; if (e.initstatus) { time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms; e.status = e.initstatus; @@ -2560,7 +2577,7 @@ } break; default: - var from2 = [].concat(from[attr]); + var from2 = [][concat](from[attr]); now = []; i = that.paper.customAttributes[attr].length; while (i--) { @@ -2587,6 +2604,10 @@ that.attr(to); animationElements.splice(l--, 1); if (e.repeat > 1 && !e.next) { + for (key in to) if (to[has](key)) { + init[key] = e.totalOrigin[key]; + } + e.el.attr(init); runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1); } if (e.next && !e.stop) { @@ -2602,7 +2623,7 @@ }; elproto.animateWith = function (element, anim, params, ms, easing, callback) { - var a = params ? R.animation(params, ms, easing, callback) : anim; + var a = params ? R.animation(params, ms, easing, callback) : anim, status = element.status(anim); return this.animate(a).status(a, status * anim.ms / a.ms); }; @@ -2738,7 +2759,7 @@ return; } if (!isInAnim) { - for (attr in params) if (params[has](attr)) { + for (var attr in params) if (params[has](attr)) { if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) { from[attr] = element.attr(attr); (from[attr] == null) && (from[attr] = availableAttrs[attr]); @@ -2821,8 +2842,8 @@ } break; case "csv": - var values = Str(params[attr]).split(separator), - from2 = Str(from[attr]).split(separator); + var values = Str(params[attr])[split](separator), + from2 = Str(from[attr])[split](separator); if (attr == "clip-rect") { from[attr] = from2; diff[attr] = []; @@ -2834,8 +2855,8 @@ to[attr] = values; break; default: - values = [].concat(params[attr]); - from2 = [].concat(from[attr]); + values = [][concat](params[attr]); + from2 = [][concat](from[attr]); diff[attr] = []; i = element.paper.customAttributes[attr].length; while (i--) { @@ -3041,7 +3062,7 @@ setproto.forEach = function (callback, thisArg) { for (var i = 0, ii = this.items.length; i < ii; i++) { - if (callback.call(thisArg, this.items[i]) === false) { + if (callback.call(thisArg, this.items[i], i) === false) { return this; } } @@ -3104,13 +3125,8 @@ }; setproto.exclude = function (el) { - for (var i = 0, ii = this.length, found; i < ii; i++) if (found || this[i] == el) { - this[i] = this[i + 1]; - found = 1; - } - if (found) { - this.length--; - delete this[i]; + for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) { + this.splice(i, 1); return true; } }; @@ -3248,14 +3264,14 @@ origin = origin || "middle"; // baseline|middle letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1); var out = this.set(), - letters = Str(string).split(E), + letters = Str(string)[split](E), shift = 0, path = E, scale; R.is(font, string) && (font = this.getFont(font)); if (font) { scale = (size || 16) / font.face["units-per-em"]; - var bb = font.face.bbox.split(separator), + var bb = font.face.bbox[split](separator), top = +bb[0], height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2); for (var i = 0, ii = letters.length; i < ii; i++) { @@ -3274,6 +3290,21 @@ }; + paperproto.add = function (json) { + if (R.is(json, "array")) { + var res = this.set(), + i = 0, + ii = json.length, + j; + for (; i < ii; i++) { + j = json[i] || {}; + elements[has](j.type) && res.push(this[j.type]().attr(j)); + } + } + return res; + }; + + R.format = function (token, params) { var args = R.is(params, array) ? [0][concat](params) : arguments; token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) { @@ -3334,8 +3365,9 @@ }); })(); + // ┌─────────────────────────────────────────────────────────────────────┐ \\ -// │ Raphaël 2 - JavaScript Vector Library │ \\ +// │ Raphaël - JavaScript Vector Library │ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\ // │ SVG Module │ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\ @@ -3386,16 +3418,6 @@ window.Raphael.svg && function (R) { } return el; }, - gradients = {}, - rgGrad = /^url\(#(.*)\)$/, - removeGradientFill = function (node, paper) { - var oid = node.getAttribute("fill"); - oid = oid && oid.match(rgGrad); - if (oid && !--gradients[oid[1]]) { - delete gradients[oid[1]]; - paper.defs.removeChild(R._g.doc.getElementById(oid[1])); - } - }, addGradientFill = function (element, gradient) { var type = "linear", id = element.id + gradient, @@ -3442,30 +3464,33 @@ window.Raphael.svg && function (R) { if (!dots) { return null; } - if (element.gradient) { + id = id.replace(/[\(\)\s,\xb0#]/g, "_"); + + if (element.gradient && id != element.gradient.id) { SVG.defs.removeChild(element.gradient); delete element.gradient; } - id = id.replace(/[\(\)\s,\xb0#]/g, "-"); - el = $(type + "Gradient", {id: id}); - element.gradient = el; - $(el, type == "radial" ? { - fx: fx, - fy: fy - } : { - x1: vector[0], - y1: vector[1], - x2: vector[2], - y2: vector[3], - gradientTransform: element.matrix.invert() - }); - SVG.defs.appendChild(el); - for (var i = 0, ii = dots.length; i < ii; i++) { - el.appendChild($("stop", { - offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%", - "stop-color": dots[i].color || "#fff" - })); + if (!element.gradient) { + el = $(type + "Gradient", {id: id}); + element.gradient = el; + $(el, type == "radial" ? { + fx: fx, + fy: fy + } : { + x1: vector[0], + y1: vector[1], + x2: vector[2], + y2: vector[3], + gradientTransform: element.matrix.invert() + }); + SVG.defs.appendChild(el); + for (var i = 0, ii = dots.length; i < ii; i++) { + el.appendChild($("stop", { + offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%", + "stop-color": dots[i].color || "#fff" + })); + } } } $(o, { @@ -3698,7 +3723,7 @@ window.Raphael.svg && function (R) { o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode); var el = $("clipPath"), rc = $("rect"); - el.id = R._createUUID(); + el.id = R.createUUID(); $(rc, { x: rect[0], y: rect[1], @@ -3711,10 +3736,13 @@ window.Raphael.svg && function (R) { o.clip = rc; } if (!value) { - var clip = R._g.doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, E)); - clip && clip.parentNode.removeChild(clip); - $(node, {"clip-path": E}); - delete o.clip; + var path = node.getAttribute("clip-path"); + if (path) { + var clip = R._g.doc.getElementById(path.replace(/(^url\(#|\)$)/g, E)); + clip && clip.parentNode.removeChild(clip); + $(node, {"clip-path": E}); + delete o.clip; + } } break; case "path": @@ -3808,7 +3836,7 @@ window.Raphael.svg && function (R) { if (isURL) { el = $("pattern"); var ig = $("image"); - el.id = R._createUUID(); + el.id = R.createUUID(); $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1}); $(ig, {x: 0, y: 0, "xlink:href": isURL[1]}); el.appendChild(ig); @@ -3852,6 +3880,9 @@ window.Raphael.svg && function (R) { break; } clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity}); + // falls through (this is where setting is done...) + + case "stroke": clr = R.getRGB(value); node.setAttribute(att, clr.hex); @@ -4071,11 +4102,16 @@ window.Raphael.svg && function (R) { if (this.removed) { return; } + var paper = this.paper; + paper.__set__ && paper.__set__.exclude(this); eve.unbind("*.*." + this.id); - R._tear(this, this.paper); + if (this.gradient) { + paper.defs.removeChild(this.gradient); + } + R._tear(this, paper); this.node.parentNode.removeChild(this.node); for (var i in this) { - delete this[i]; + this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null; } this.removed = true; }; @@ -4143,11 +4179,16 @@ window.Raphael.svg && function (R) { } else if (name != null && R.is(name, "object")) { params = name; } - for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) { - var par = this.paper.customAttributes[key].apply(this, [].concat(params[key])); - this.attrs[key] = params[key]; - for (var subkey in par) if (par[has](subkey)) { - params[subkey] = par[subkey]; + for (var key in params) { + eve("attr." + key + "." + this.id, this, params[key]); + } + for (key in this.paper.customAttributes) { + if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) { + var par = this.paper.customAttributes[key].apply(this, [].concat(params[key])); + this.attrs[key] = params[key]; + for (var subkey in par) if (par[has](subkey)) { + params[subkey] = par[subkey]; + } } } setFillAndStroke(this, params); @@ -4158,7 +4199,11 @@ window.Raphael.svg && function (R) { if (this.removed) { return this; } - this.node.parentNode.appendChild(this.node); + if (this.node.parentNode.tagName.toLowerCase() == "a") { + this.node.parentNode.parentNode.appendChild(this.node.parentNode); + } else { + this.node.parentNode.appendChild(this.node); + } var svg = this.paper; svg.top != this && R._tofront(this, svg); return this; @@ -4168,11 +4213,14 @@ window.Raphael.svg && function (R) { if (this.removed) { return this; } - if (this.node.parentNode.firstChild != this.node) { - this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild); - R._toback(this, this.paper); - var svg = this.paper; + var parent = this.node.parentNode; + if (parent.tagName.toLowerCase() == "a") { + parent.parentNode.insertBefore(this.node.parentNode, this.node.parentNode.parentNode.firstChild); + } else if (parent.firstChild != this.node) { + parent.insertBefore(this.node, this.node.parentNode.firstChild); } + R._toback(this, this.paper); + var svg = this.paper; return this; }; @@ -4206,7 +4254,7 @@ window.Raphael.svg && function (R) { var fltr = $("filter"), blur = $("feGaussianBlur"); t.attrs.blur = size; - fltr.id = R._createUUID(); + fltr.id = R.createUUID(); $(blur, {stdDeviation: +size || 1.5}); fltr.appendChild(blur); t.paper.defs.appendChild(fltr); @@ -4367,7 +4415,7 @@ window.Raphael.svg && function (R) { R.prototype.renderfix = function () { var cnvs = this.canvas, s = cnvs.style, - pos = cnvs.getScreenCTM(), + pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix(), left = -pos.e % 1, top = -pos.f % 1; if (left || top) { @@ -4398,7 +4446,7 @@ window.Raphael.svg && function (R) { eve("remove", this); this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas); for (var i in this) { - this[i] = removed(i); + this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null; } }; var setproto = R.st; @@ -4415,7 +4463,7 @@ window.Raphael.svg && function (R) { }(window.Raphael); // ┌─────────────────────────────────────────────────────────────────────┐ \\ -// │ Raphaël 2 - JavaScript Vector Library │ \\ +// │ Raphaël - JavaScript Vector Library │ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\ // │ VML Module │ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\ @@ -4423,6 +4471,8 @@ window.Raphael.svg && function (R) { // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // └─────────────────────────────────────────────────────────────────────┘ \\ + + window.Raphael.vml && function (R) { var has = "hasOwnProperty", Str = String, @@ -4532,7 +4582,7 @@ window.Raphael.vml && function (R) { R.toString = function () { return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version; }; - addArrow = function (o, value, isEnd) { + var addArrow = function (o, value, isEnd) { var values = Str(value).toLowerCase().split("-"), se = isEnd ? "end" : "start", i = values.length, @@ -4559,8 +4609,9 @@ window.Raphael.vml && function (R) { stroke[se + "arrow"] = type; stroke[se + "arrowlength"] = w; stroke[se + "arrowwidth"] = h; - }; + }, setFillAndStroke = function (o, params) { + //Roo.log( ['setFillAndStroke' , o, params]); // o.paper.canvas.style.display = "none"; o.attrs = o.attrs || {}; var node = o.node, @@ -4620,7 +4671,7 @@ window.Raphael.vml && function (R) { } } if (!params["clip-rect"]) { - node.clipRect && (node.clipRect.style.clip = E); + node.clipRect && (node.clipRect.style.clip = "auto"); } } if (o.textpath) { @@ -4747,7 +4798,7 @@ window.Raphael.vml && function (R) { a["font-family"] && (s.fontFamily = a["font-family"]); a["font-weight"] && (s.fontWeight = a["font-weight"]); a["font-style"] && (s.fontStyle = a["font-style"]); - fontSize = toFloat(fontSize ? fontSize[0] : a["font-size"]); + fontSize = toFloat(a["font-size"] || fontSize && fontSize[0]) || 10; s.fontSize = fontSize * m + "px"; res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/")); var brect = span.getBoundingClientRect(); @@ -4782,10 +4833,11 @@ window.Raphael.vml && function (R) { res.textpath.style["v-text-kern"] = true; } // res.paper.canvas.style.display = E; - }; + }, addGradientFill = function (o, gradient, fill) { o.attrs = o.attrs || {}; var attrs = o.attrs, + pow = Math.pow, opacity, oindex, type = "linear", @@ -4839,7 +4891,7 @@ window.Raphael.vml && function (R) { o.appendChild(fill); } return 1; - }; + }, Element = function (node, vml) { this[0] = this.node = node; node.raphael = true; @@ -4989,27 +5041,24 @@ window.Raphael.vml && function (R) { if (this.removed) { return {}; } - if (this.type == "text") { - return { - x: this.X + (this.bbx || 0) - this.W / 2, - y: this.Y - this.H, - width: this.W, - height: this.H - }; - } else { - return pathDimensions(this.attrs.path); - } + return { + x: this.X + (this.bbx || 0) - this.W / 2, + y: this.Y - this.H, + width: this.W, + height: this.H + }; }; elproto.remove = function () { if (this.removed) { return; } + this.paper.__set__ && this.paper.__set__.exclude(this); R.eve.unbind("*.*." + this.id); R._tear(this, this.paper); this.node.parentNode.removeChild(this.node); this.shape && this.shape.parentNode.removeChild(this.shape); for (var i in this) { - delete this[i]; + this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null; } this.removed = true; }; @@ -5058,11 +5107,11 @@ window.Raphael.vml && function (R) { } value == null && R.is(name, "object") && (params = name); for (var key in params) { - R.eve("attr." + key + "." + this.id, this, params[key]); + eve("attr." + key + "." + this.id, this, params[key]); } if (params) { for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) { - var par = this.paper.customAttributes[key].apply(this, [][concat](params[key])); + var par = this.paper.customAttributes[key].apply(this, [].concat(params[key])); this.attrs[key] = params[key]; for (var subkey in par) if (par[has](subkey)) { params[subkey] = par[subkey]; @@ -5230,7 +5279,7 @@ window.Raphael.vml && function (R) { path.textpathok = true; o.string = Str(text); o.on = true; - el.style.cssText = "position:absolute;left:0;top:0;width:1px;height:1px"; + el.style.cssText = cssDot; el.coordsize = zoom + S + zoom; el.coordorigin = "0 0"; var p = new Element(el, vml), @@ -5270,7 +5319,7 @@ window.Raphael.vml && function (R) { cs.height = height; cs.clip = "rect(0 " + width + " " + height + " 0)"; if (this._viewBox) { - setViewBox.apply(this, this._viewBox); + R._engine.setViewBox.apply(this, this._viewBox); } return this; }; @@ -5301,8 +5350,8 @@ window.Raphael.vml && function (R) { }); return this; }; - var createNode, - initWin = function (win) { + var createNode; + R._engine.initWin = function (win) { var doc = win.document; doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)"); try { @@ -5316,7 +5365,7 @@ window.Raphael.vml && function (R) { }; } }; - initWin(R._g.win); + R._engine.initWin(R._g.win); R._engine.create = function () { var con = R._getContainer.apply(0, arguments), container = con.container, @@ -5373,8 +5422,20 @@ window.Raphael.vml && function (R) { R.eve("remove", this); this.canvas.parentNode.removeChild(this.canvas); for (var i in this) { - this[i] = removed(i); + this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null; } return true; }; + + var setproto = R.st; + for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) { + setproto[method] = (function (methodname) { + return function () { + var arg = arguments; + return this.forEach(function (el) { + el[methodname].apply(el, arg); + }); + }; + })(method); + } }(window.Raphael); \ No newline at end of file