Allows Element.data() to be called with 0 params to get all associated data. By @AdamTReineke

This commit is contained in:
Tomas Alabes 2013-05-19 19:13:02 -03:00
parent 5423c26bf8
commit 95ebe5a23b
3 changed files with 52 additions and 42 deletions

4
raphael-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -503,7 +503,7 @@
} }
return value; return value;
}; };
/*\ /*\
* Raphael.createUUID * Raphael.createUUID
[ method ] [ method ]
@ -598,7 +598,7 @@
g /= 255; g /= 255;
b /= 255; b /= 255;
} }
return [r, g, b]; return [r, g, b];
}, },
packageRGB = function (r, g, b, o) { packageRGB = function (r, g, b, o) {
@ -615,7 +615,7 @@
R.is(o, "finite") && (rgb.opacity = o); R.is(o, "finite") && (rgb.opacity = o);
return rgb; return rgb;
}; };
/*\ /*\
* Raphael.color * Raphael.color
[ method ] [ method ]
@ -858,7 +858,7 @@
g.doc.body.appendChild(img); g.doc.body.appendChild(img);
img.src = src; img.src = src;
}; };
function clrToString() { function clrToString() {
return this.hex; return this.hex;
} }
@ -1090,7 +1090,7 @@
if (pth.arr) { if (pth.arr) {
return pathClone(pth.arr); return pathClone(pth.arr);
} }
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0}, var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
data = []; data = [];
if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
@ -1598,7 +1598,7 @@
return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0}; return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0};
} }
path = path2curve(path); path = path2curve(path);
var x = 0, var x = 0,
y = 0, y = 0,
X = [], X = [],
Y = [], Y = [],
@ -2650,7 +2650,7 @@
s.scalex = +s.scalex.toFixed(4); s.scalex = +s.scalex.toFixed(4);
s.scaley = +s.scaley.toFixed(4); s.scaley = +s.scaley.toFixed(4);
s.rotate = +s.rotate.toFixed(4); s.rotate = +s.rotate.toFixed(4);
return (s.dx || s.dy ? "t" + [s.dx, s.dy] : E) + 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.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
(s.rotate ? "r" + [s.rotate, 0, 0] : E); (s.rotate ? "r" + [s.rotate, 0, 0] : E);
} else { } else {
@ -2678,7 +2678,7 @@
} else { } else {
paperproto.safari = fun; paperproto.safari = fun;
} }
var preventDefault = function () { var preventDefault = function () {
this.returnValue = false; this.returnValue = false;
}, },
@ -2826,7 +2826,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.dblclick * Element.dblclick
[ method ] [ method ]
@ -2845,7 +2845,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mousedown * Element.mousedown
[ method ] [ method ]
@ -2864,7 +2864,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mousemove * Element.mousemove
[ method ] [ method ]
@ -2883,7 +2883,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mouseout * Element.mouseout
[ method ] [ method ]
@ -2902,7 +2902,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mouseover * Element.mouseover
[ method ] [ method ]
@ -2921,7 +2921,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mouseup * Element.mouseup
[ method ] [ method ]
@ -2940,7 +2940,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchstart * Element.touchstart
[ method ] [ method ]
@ -2959,7 +2959,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchmove * Element.touchmove
[ method ] [ method ]
@ -2978,7 +2978,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchend * Element.touchend
[ method ] [ method ]
@ -2997,7 +2997,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchcancel * Element.touchcancel
[ method ] [ method ]
@ -3039,7 +3039,7 @@
}; };
})(events[i]); })(events[i]);
} }
/*\ /*\
* Element.data * Element.data
[ method ] [ method ]
@ -3053,6 +3053,8 @@
= (object) @Element = (object) @Element
* or, if value is not specified: * or, if value is not specified:
= (any) value = (any) value
* or, if key and value are not specified:
= (object) Key/value pairs for all the data associated with the element.
> Usage > Usage
| for (var i = 0, i < 5, i++) { | for (var i = 0, i < 5, i++) {
| paper.circle(10 + 15 * i, 10, 10) | paper.circle(10 + 15 * i, 10, 10)
@ -3065,6 +3067,9 @@
\*/ \*/
elproto.data = function (key, value) { elproto.data = function (key, value) {
var data = eldata[this.id] = eldata[this.id] || {}; var data = eldata[this.id] = eldata[this.id] || {};
if (arguments.length == 0) {
return data;
}
if (arguments.length == 1) { if (arguments.length == 1) {
if (R.is(key, "object")) { if (R.is(key, "object")) {
for (var i in key) if (key[has](i)) { for (var i in key) if (key[has](i)) {
@ -4269,7 +4274,7 @@
** **
= (object) new altered Animation object = (object) new altered Animation object
\*/ \*/
Animation.prototype.repeat = function (times) { Animation.prototype.repeat = function (times) {
var a = new Animation(this.anim, this.ms); var a = new Animation(this.anim, this.ms);
a.del = this.del; a.del = this.del;
a.times = math.floor(mmax(times, 0)) || 1; a.times = math.floor(mmax(times, 0)) || 1;

View File

@ -882,7 +882,7 @@
} }
return value; return value;
}; };
/*\ /*\
* Raphael.createUUID * Raphael.createUUID
[ method ] [ method ]
@ -977,7 +977,7 @@
g /= 255; g /= 255;
b /= 255; b /= 255;
} }
return [r, g, b]; return [r, g, b];
}, },
packageRGB = function (r, g, b, o) { packageRGB = function (r, g, b, o) {
@ -994,7 +994,7 @@
R.is(o, "finite") && (rgb.opacity = o); R.is(o, "finite") && (rgb.opacity = o);
return rgb; return rgb;
}; };
/*\ /*\
* Raphael.color * Raphael.color
[ method ] [ method ]
@ -1237,7 +1237,7 @@
g.doc.body.appendChild(img); g.doc.body.appendChild(img);
img.src = src; img.src = src;
}; };
function clrToString() { function clrToString() {
return this.hex; return this.hex;
} }
@ -1469,7 +1469,7 @@
if (pth.arr) { if (pth.arr) {
return pathClone(pth.arr); return pathClone(pth.arr);
} }
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0}, var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
data = []; data = [];
if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
@ -1977,7 +1977,7 @@
return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0}; return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0};
} }
path = path2curve(path); path = path2curve(path);
var x = 0, var x = 0,
y = 0, y = 0,
X = [], X = [],
Y = [], Y = [],
@ -3029,7 +3029,7 @@
s.scalex = +s.scalex.toFixed(4); s.scalex = +s.scalex.toFixed(4);
s.scaley = +s.scaley.toFixed(4); s.scaley = +s.scaley.toFixed(4);
s.rotate = +s.rotate.toFixed(4); s.rotate = +s.rotate.toFixed(4);
return (s.dx || s.dy ? "t" + [s.dx, s.dy] : E) + 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.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
(s.rotate ? "r" + [s.rotate, 0, 0] : E); (s.rotate ? "r" + [s.rotate, 0, 0] : E);
} else { } else {
@ -3057,7 +3057,7 @@
} else { } else {
paperproto.safari = fun; paperproto.safari = fun;
} }
var preventDefault = function () { var preventDefault = function () {
this.returnValue = false; this.returnValue = false;
}, },
@ -3205,7 +3205,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.dblclick * Element.dblclick
[ method ] [ method ]
@ -3224,7 +3224,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mousedown * Element.mousedown
[ method ] [ method ]
@ -3243,7 +3243,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mousemove * Element.mousemove
[ method ] [ method ]
@ -3262,7 +3262,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mouseout * Element.mouseout
[ method ] [ method ]
@ -3281,7 +3281,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mouseover * Element.mouseover
[ method ] [ method ]
@ -3300,7 +3300,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.mouseup * Element.mouseup
[ method ] [ method ]
@ -3319,7 +3319,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchstart * Element.touchstart
[ method ] [ method ]
@ -3338,7 +3338,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchmove * Element.touchmove
[ method ] [ method ]
@ -3357,7 +3357,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchend * Element.touchend
[ method ] [ method ]
@ -3376,7 +3376,7 @@
- handler (function) #optional handler for the event - handler (function) #optional handler for the event
= (object) @Element = (object) @Element
\*/ \*/
/*\ /*\
* Element.touchcancel * Element.touchcancel
[ method ] [ method ]
@ -3418,7 +3418,7 @@
}; };
})(events[i]); })(events[i]);
} }
/*\ /*\
* Element.data * Element.data
[ method ] [ method ]
@ -3432,6 +3432,8 @@
= (object) @Element = (object) @Element
* or, if value is not specified: * or, if value is not specified:
= (any) value = (any) value
* or, if key and value are not specified:
= (object) Key/value pairs for all the data associated with the element.
> Usage > Usage
| for (var i = 0, i < 5, i++) { | for (var i = 0, i < 5, i++) {
| paper.circle(10 + 15 * i, 10, 10) | paper.circle(10 + 15 * i, 10, 10)
@ -3444,6 +3446,9 @@
\*/ \*/
elproto.data = function (key, value) { elproto.data = function (key, value) {
var data = eldata[this.id] = eldata[this.id] || {}; var data = eldata[this.id] = eldata[this.id] || {};
if (arguments.length == 0) {
return data;
}
if (arguments.length == 1) { if (arguments.length == 1) {
if (R.is(key, "object")) { if (R.is(key, "object")) {
for (var i in key) if (key[has](i)) { for (var i in key) if (key[has](i)) {
@ -4648,7 +4653,7 @@
** **
= (object) new altered Animation object = (object) new altered Animation object
\*/ \*/
Animation.prototype.repeat = function (times) { Animation.prototype.repeat = function (times) {
var a = new Animation(this.anim, this.ms); var a = new Animation(this.anim, this.ms);
a.del = this.del; a.del = this.del;
a.times = math.floor(mmax(times, 0)) || 1; a.times = math.floor(mmax(times, 0)) || 1;