raphael-rails 1.5.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,212 +0,0 @@
1
- (function (Raphael) {
2
- Raphael.colorwheel = function (x, y, size, initcolor, element) {
3
- return new ColorWheel(x, y, size, initcolor, element);
4
- };
5
- var pi = Math.PI;
6
- function angle(x, y) {
7
- return (x < 0) * 180 + Math.atan(-y / -x) * 180 / pi;
8
- }
9
- var doc = document, win = window;
10
- var addEvent = (function () {
11
- if (doc.addEventListener) {
12
- return function (obj, type, fn, element) {
13
- var f = function (e) {
14
- return fn.call(element, e);
15
- };
16
- obj.addEventListener(type, f, false);
17
- return function () {
18
- obj.removeEventListener(type, f, false);
19
- return true;
20
- };
21
- };
22
- } else if (doc.attachEvent) {
23
- return function (obj, type, fn, element) {
24
- var f = function (e) {
25
- return fn.call(element, e || win.event);
26
- };
27
- obj.attachEvent("on" + type, f);
28
- var detacher = function () {
29
- obj.detachEvent("on" + type, f);
30
- return true;
31
- };
32
- return detacher;
33
- };
34
- }
35
- })();
36
- var ColorWheel = function (x, y, size, initcolor, element) {
37
- size = size || 200;
38
- var w3 = 3 * size / 200,
39
- w1 = size / 200,
40
- fi = 1.6180339887,
41
- segments = pi * size / 5,
42
- size20 = size / 20,
43
- size2 = size / 2,
44
- padding = 2 * size / 200,
45
- t = this;
46
-
47
- var H = 1, S = 1, B = 1, s = size - (size20 * 4);
48
- var r = element ? Raphael(element, size, size) : Raphael(x, y, size, size),
49
- xy = s / 6 + size20 * 2 + padding,
50
- wh = s * 2 / 3 - padding * 2;
51
- w1 < 1 && (w1 = 1);
52
- w3 < 1 && (w3 = 1);
53
-
54
-
55
- // ring drawing
56
- var a = pi / 2 - pi * 2 / segments * 1.3,
57
- R = size2 - padding,
58
- R2 = size2 - padding - size20 * 2,
59
- path = ["M", size2, padding, "A", R, R, 0, 0, 1, R * Math.cos(a) + R + padding, R - R * Math.sin(a) + padding, "L", R2 * Math.cos(a) + R + padding, R - R2 * Math.sin(a) + padding, "A", R2, R2, 0, 0, 0, size2, padding + size20 * 2, "z"].join();
60
- for (var i = 0; i < segments; i++) {
61
- r.path(path).attr({
62
- stroke: "none",
63
- fill: "hsb(" + i * (255 / segments) + ", 255, 200)",
64
- rotation: [(360 / segments) * i, size2, size2]
65
- });
66
- }
67
- r.path(["M", size2, padding, "A", R, R, 0, 1, 1, size2 - 1, padding, "l1,0", "M", size2, padding + size20 * 2, "A", R2, R2, 0, 1, 1, size2 - 1, padding + size20 * 2, "l1,0"]).attr({
68
- "stroke-width": w3,
69
- stroke: "#fff"
70
- });
71
- t.cursorhsb = r.set();
72
- var h = size20 * 2 + 2;
73
- t.cursorhsb.push(r.rect(size2 - h / fi / 2, padding - 1, h / fi, h, 3 * size / 200).attr({
74
- stroke: "#000",
75
- opacity: .5,
76
- "stroke-width": w3
77
- }));
78
- t.cursorhsb.push(t.cursorhsb[0].clone().attr({
79
- stroke: "#fff",
80
- opacity: 1,
81
- "stroke-width": w1
82
- }));
83
- t.ring = r.path(["M", size2, padding, "A", R, R, 0, 1, 1, size2 - 1, padding, "l1,0M", size2, padding + size20 * 2, "A", R2, R2, 0, 1, 1, size2 - 1, padding + size20 * 2, "l1,0"]).attr({
84
- fill: "#000",
85
- opacity: 0,
86
- stroke: "none"
87
- });
88
-
89
- // rect drawing
90
- t.main = r.rect(xy, xy, wh, wh).attr({
91
- stroke: "none",
92
- fill: "#f00",
93
- opacity: 1
94
- });
95
- t.main.clone().attr({
96
- stroke: "none",
97
- fill: "0-#fff-#fff",
98
- opacity: 0
99
- });
100
- t.square = r.rect(xy - 1, xy - 1, wh + 2, wh + 2).attr({
101
- r: 2,
102
- stroke: "#fff",
103
- "stroke-width": w3,
104
- fill: "90-#000-#000",
105
- opacity: 0,
106
- cursor: "crosshair"
107
- });
108
- t.cursor = r.set();
109
- t.cursor.push(r.circle(size2, size2, size20 / 2).attr({
110
- stroke: "#000",
111
- opacity: .5,
112
- "stroke-width": w3
113
- }));
114
- t.cursor.push(t.cursor[0].clone().attr({
115
- stroke: "#fff",
116
- opacity: 1,
117
- "stroke-width": w1
118
- }));
119
- t.H = t.S = t.B = 1;
120
- t.raphael = r;
121
- t.size2 = size2;
122
- t.wh = wh;
123
- t.x = x;
124
- t.xy = xy;
125
- t.y = y;
126
-
127
- // events
128
- t.hsbon = addEvent(t.ring.node, "mousedown", function (e) {
129
- this.hsbOnTheMove = true;
130
- this.setH(e.clientX - this.x - this.size2, e.clientY - this.y - this.size2);
131
- this.docmove = addEvent(doc, "mousemove", this.docOnMove, this);
132
- this.docup = addEvent(doc, "mouseup", this.docOnUp, this);
133
- }, t);
134
- t.clron = addEvent(t.square.node, "mousedown", function (e) {
135
- this.clrOnTheMove = true;
136
- this.setSB(e.clientX - this.x, e.clientY - this.y);
137
- this.docmove = addEvent(doc, "mousemove", this.docOnMove, this);
138
- this.docup = addEvent(doc, "mouseup", this.docOnUp, this);
139
- }, t);
140
- t.winunload = addEvent(win, "unload", function () {
141
- this.hsbon();
142
- this.clron();
143
- this.docmove && this.docmove();
144
- this.docup && this.docup();
145
- this.winunload();
146
- }, t);
147
-
148
- t.color(initcolor || "#f00");
149
- this.onchanged && this.onchanged(this.color());
150
- };
151
- ColorWheel.prototype.setH = function (x, y) {
152
- var d = angle(x, y),
153
- rd = d * pi / 180;
154
- this.cursorhsb.rotate(d + 90, this.size2, this.size2);
155
- this.H = (d + 90) / 360;
156
- this.main.attr({fill: "hsb(" + this.H + ",1,1)"});
157
- this.onchange && this.onchange(this.color());
158
- };
159
- ColorWheel.prototype.setSB = function (x, y) {
160
- x < this.size2 - this.wh / 2 && (x = this.size2 - this.wh / 2);
161
- x > this.size2 + this.wh / 2 && (x = this.size2 + this.wh / 2);
162
- y < this.size2 - this.wh / 2 && (y = this.size2 - this.wh / 2);
163
- y > this.size2 + this.wh / 2 && (y = this.size2 + this.wh / 2);
164
- this.cursor.attr({cx: x, cy: y});
165
- this.B = 1 - (y - this.xy) / this.wh;
166
- this.S = (x - this.xy) / this.wh;
167
- this.onchange && this.onchange(this.color());
168
- };
169
- ColorWheel.prototype.docOnMove = function (e) {
170
- if (this.hsbOnTheMove) {
171
- this.setH(e.clientX - this.x - this.size2, e.clientY - this.y - this.size2);
172
- }
173
- if (this.clrOnTheMove) {
174
- this.setSB(e.clientX - this.x, e.clientY - this.y);
175
- }
176
- e.preventDefault && e.preventDefault();
177
- e.returnValue = false;
178
- return false;
179
- };
180
- ColorWheel.prototype.docOnUp = function (e) {
181
- this.hsbOnTheMove = this.clrOnTheMove = false;
182
- this.docmove();
183
- delete this.docmove;
184
- this.docup();
185
- delete this.docup;
186
- this.onchanged && this.onchanged(this.color());
187
- };
188
- ColorWheel.prototype.remove = function () {
189
- this.raphael.remove();
190
- this.color = function () {
191
- return false;
192
- };
193
- };
194
- ColorWheel.prototype.color = function (color) {
195
- if (color) {
196
- color = Raphael.getRGB(color);
197
- color = Raphael.rgb2hsb(color.r, color.g, color.b);
198
- var d = color.h * 360;
199
- this.H = color.h;
200
- this.S = color.s;
201
- this.B = color.b;
202
- this.cursorhsb.rotate(d, this.size2, this.size2);
203
- this.main.attr({fill: "hsb(" + this.H + ",1,1)"});
204
- var x = this.S * this.wh + this.xy,
205
- y = (1 - this.B) * this.wh + this.xy;
206
- this.cursor.attr({cx: x, cy: y});
207
- return this;
208
- } else {
209
- return Raphael.hsb2rgb(this.H, this.S, this.B).hex;
210
- }
211
- };
212
- })(window.Raphael);
@@ -1,16 +0,0 @@
1
- /*!
2
- * Color Picker 0.1.0 - Raphael plugin
3
- *
4
- * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
5
- * Based on Color Wheel (http://jweir.github.com/colorwheel) by John Weir (http://famedriver.com)
6
- * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
7
- */
8
- (function ($, R) {
9
- $.fn.colorpicker = function (size, initcolor) {
10
- if (R) {
11
- var offset = this.offset();
12
- return R.colorpicker(offset.left, offset.top, size, initcolor, this[0]);
13
- }
14
- return null;
15
- };
16
- })(window.jQuery, window.Raphael);
@@ -1,9 +0,0 @@
1
- (function ($, R) {
2
- $.fn.colorwheel = function (size, initcolor) {
3
- if (R) {
4
- var offset = this.offset();
5
- return R.colorwheel(offset.left, offset.top, size, initcolor, this[0]);
6
- }
7
- return null;
8
- };
9
- })(window.jQuery, window.Raphael);
@@ -1,53 +0,0 @@
1
- /*!
2
- * Raphael Blur Plugin 0.1
3
- *
4
- * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5
- * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6
- */
7
-
8
- (function () {
9
- if (Raphael.vml) {
10
- var reg = / progid:\S+Blur\([^\)]+\)/g;
11
- Raphael.el.blur = function (size) {
12
- var s = this.node.style,
13
- f = s.filter;
14
- f = f.replace(reg, "");
15
- if (size != "none") {
16
- s.filter = f + " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (+size || 1.5) + ")";
17
- s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
18
- } else {
19
- s.filter = f;
20
- s.margin = 0;
21
- }
22
- };
23
- } else {
24
- var $ = function (el, attr) {
25
- if (attr) {
26
- for (var key in attr) if (attr.hasOwnProperty(key)) {
27
- el.setAttribute(key, attr[key]);
28
- }
29
- } else {
30
- return doc.createElementNS("http://www.w3.org/2000/svg", el);
31
- }
32
- };
33
- Raphael.el.blur = function (size) {
34
- // Experimental. No WebKit support.
35
- if (size != "none") {
36
- var fltr = $("filter"),
37
- blur = $("feGaussianBlur");
38
- fltr.id = "r" + (Raphael.idGenerator++).toString(36);
39
- $(blur, {stdDeviation: +size || 1.5});
40
- fltr.appendChild(blur);
41
- this.paper.defs.appendChild(fltr);
42
- this._blur = fltr;
43
- $(this.node, {filter: "url(#" + fltr.id + ")"});
44
- } else {
45
- if (this._blur) {
46
- this._blur.parentNode.removeChild(this._blur);
47
- delete this._blur;
48
- }
49
- this.node.removeAttribute("filter");
50
- }
51
- };
52
- }
53
- })();
@@ -1,60 +0,0 @@
1
- /*!
2
- * Raphael Path Methods Plugin 0.2
3
- *
4
- * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5
- * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6
- */
7
-
8
- Raphael.el.isAbsolute = true;
9
- Raphael.el.absolutely = function () {
10
- this.isAbsolute = 1;
11
- return this;
12
- };
13
- Raphael.el.relatively = function () {
14
- this.isAbsolute = 0;
15
- return this;
16
- };
17
- Raphael.el.moveTo = function (x, y) {
18
- this._last = {x: x, y: y};
19
- return this.attr({path: this.attrs.path + ["m", "M"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
20
- };
21
- Raphael.el.lineTo = function (x, y) {
22
- this._last = {x: x, y: y};
23
- return this.attr({path: this.attrs.path + ["l", "L"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
24
- };
25
- Raphael.el.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y, angle) {
26
- this._last = {x: x, y: y};
27
- return this.attr({path: this.attrs.path + ["a", "A"][+this.isAbsolute] + [parseFloat(rx), parseFloat(ry), +angle, large_arc_flag, sweep_flag, parseFloat(x), parseFloat(y)].join(" ")});
28
- };
29
- Raphael.el.curveTo = function () {
30
- var args = Array.prototype.splice.call(arguments, 0, arguments.length),
31
- d = [0, 0, 0, 0, "s", 0, "c"][args.length] || "";
32
- this.isAbsolute && (d = d.toUpperCase());
33
- this._last = {x: args[args.length - 2], y: args[args.length - 1]};
34
- return this.attr({path: this.attrs.path + d + args});
35
- };
36
- Raphael.el.cplineTo = function (x, y, w) {
37
- this.attr({path: this.attrs.path + ["C", this._last.x + w, this._last.y, x - w, y, x, y]});
38
- this._last = {x: x, y: y};
39
- return this;
40
- };
41
- Raphael.el.qcurveTo = function () {
42
- var d = [0, 1, "t", 3, "q"][arguments.length],
43
- args = Array.prototype.splice.call(arguments, 0, arguments.length);
44
- if (this.isAbsolute) {
45
- d = d.toUpperCase();
46
- }
47
- this._last = {x: args[args.length - 2], y: args[args.length - 1]};
48
- return this.attr({path: this.attrs.path + d + args});
49
- };
50
- Raphael.el.addRoundedCorner = function (r, dir) {
51
- var rollback = this.isAbsolute;
52
- rollback && this.relatively();
53
- this._last = {x: r * (!!(dir.indexOf("r") + 1) * 2 - 1), y: r * (!!(dir.indexOf("d") + 1) * 2 - 1)};
54
- this.arcTo(r, r, 0, {"lu": 1, "rd": 1, "ur": 1, "dl": 1}[dir] || 0, this._last.x, this._last.y);
55
- rollback && this.absolutely();
56
- return this;
57
- };
58
- Raphael.el.andClose = function () {
59
- return this.attr({path: this.attrs.path + "z"});
60
- };
@@ -1,99 +0,0 @@
1
- /*!
2
- * Raphael Primitives Plugin 0.2
3
- *
4
- * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5
- * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6
- */
7
-
8
- Raphael.fn.star = function (cx, cy, r, r2, rays) {
9
- r2 = r2 || r * .382;
10
- rays = rays || 5;
11
- var points = ["M", cx, cy + r2, "L"],
12
- R;
13
- for (var i = 1; i < rays * 2; i++) {
14
- R = i % 2 ? r : r2;
15
- points = points.concat([(cx + R * Math.sin(i * Math.PI / rays)), (cy + R * Math.cos(i * Math.PI / rays))]);
16
- }
17
- points.push("z");
18
- return this.path(points.join());
19
- };
20
- Raphael.fn.flower = function (cx, cy, rout, rin, n) {
21
- rin = rin || rout * .5;
22
- n = +n < 3 || !n ? 5 : n;
23
- var points = ["M", cx, cy + rin, "Q"],
24
- R;
25
- for (var i = 1; i < n * 2 + 1; i++) {
26
- R = i % 2 ? rout : rin;
27
- points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
28
- }
29
- points.push("z");
30
- return this.path(points);
31
- };
32
- Raphael.fn.spike = function (cx, cy, rout, rin, n) {
33
- rin = rin || rout * .5;
34
- n = +n < 3 || !n ? 5 : n;
35
- var points = ["M", cx, cy - rout, "Q"],
36
- R;
37
- for (var i = 1; i < n * 2 + 1; i++) {
38
- R = i % 2 ? rin : rout;
39
- points = points.concat([cx + R * Math.sin(i * Math.PI / n - Math.PI), cy + R * Math.cos(i * Math.PI / n - Math.PI)]);
40
- }
41
- points.push("z");
42
- return this.path(points);
43
- };
44
- Raphael.fn.polyline = function () {
45
- var points = "M".concat(arguments[0] || 0, ",", arguments[1] || 0, "L");
46
- for (var i = 2, ii = arguments.length - 1; i < ii; i++) {
47
- points += arguments[i] + "," + arguments[++i];
48
- }
49
- arguments[ii].toLowerCase() == "z" && (points += "z");
50
- return this.path(points);
51
- };
52
- Raphael.fn.polygon = function (cx, cy, r, n) {
53
- n = +n < 3 || !n ? 5 : n;
54
- var points = ["M", cx, cy - r, "L"],
55
- R;
56
- for (var i = 1; i < n; i++) {
57
- points = points.concat([cx + r * Math.sin(i * Math.PI * 2 / n - Math.PI), cy + r * Math.cos(i * Math.PI * 2 / n - Math.PI)]);
58
- }
59
- points.push("z");
60
- return this.path(points);
61
- };
62
- Raphael.fn.line = function (x1, y1, x2, y2) {
63
- return this.path(["M", x1, y1, "L", x2, y2]);
64
- };
65
- Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) {
66
- color = color || "#000";
67
- var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
68
- rowHeight = h / hv,
69
- columnWidth = w / wv;
70
- for (var i = 1; i < hv; i++) {
71
- path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
72
- }
73
- for (var i = 1; i < wv; i++) {
74
- path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
75
- }
76
- return this.path(path.join(",")).attr({stroke: color});
77
- };
78
- Raphael.fn.square = function (cx, cy, r) {
79
- r = r * .7;
80
- return this.rect(cx - r, cy - r, 2 * r, 2 * r);
81
- };
82
- Raphael.fn.triangle = function (cx, cy, r) {
83
- r *= 1.75;
84
- return this.path("M".concat(cx, ",", cy, "m0-", r * .58, "l", r * .5, ",", r * .87, "-", r, ",0z"));
85
- };
86
- Raphael.fn.diamond = function (cx, cy, r) {
87
- return this.path(["M", cx, cy - r, "l", r, r, -r, r, -r, -r, r, -r, "z"]);
88
- };
89
- Raphael.fn.cross = function (cx, cy, r) {
90
- r = r / 2.5;
91
- return this.path("M".concat(cx - r, ",", cy, "l", [-r, -r, r, -r, r, r, r, -r, r, r, -r, r, r, r, -r, r, -r, -r, -r, r, -r, -r, "z"]));
92
- };
93
- Raphael.fn.plus = function (cx, cy, r) {
94
- r = r / 2;
95
- return this.path("M".concat(cx - r / 2, ",", cy - r / 2, "l", [0, -r, r, 0, 0, r, r, 0, 0, r, -r, 0, 0, r, -r, 0, 0, -r, -r, 0, 0, -r, "z"]));
96
- };
97
- Raphael.fn.arrow = function (cx, cy, r) {
98
- return this.path("M".concat(cx - r * .7, ",", cy - r * .4, "l", [r * .6, 0, 0, -r * .4, r, r * .8, -r, r * .8, 0, -r * .4, -r * .6, 0], "z"));
99
- };