Skip to content

Commit 73e51eb

Browse files
author
Chris K
committed
Code cleanup.
1 parent ea88384 commit 73e51eb

11 files changed

+302
-319
lines changed

src/client-en.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ window.load_screen_timeout = window.setTimeout(function()
210210
<!-- command concat_js "./script/dragonfly.js" -->
211211

212212
<script src="./scripts/ini.js"/>
213-
<script src="./scripts/dom.js"/>
213+
<script src="./lib/elementprototype.js"/>
214214

215215

216216
<script src="./scripts/Timeouts.js"/>

src/lib/arrayprototype.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Return the sum of all the values in the array. If selectorfun is given,
3+
* it will be called to retrieve the relevant value for each item in the
4+
* array.
5+
*/
6+
Array.prototype.sum = function(selectorfun)
7+
{
8+
if (selectorfun)
9+
{
10+
return this.map(selectorfun).sum();
11+
}
12+
else
13+
{
14+
var ret = 0;
15+
this.forEach(function(e) { ret += e });
16+
return ret
17+
}
18+
};
19+
20+
Array.prototype.unique = function()
21+
{
22+
return this.reduce(function(list, e)
23+
{
24+
if (list.indexOf(e) == -1)
25+
list.push(e);
26+
27+
return list;
28+
}, []);
29+
}
30+
31+
Array.prototype.__defineGetter__("last", function()
32+
{
33+
return this[this.length - 1];
34+
});
35+
36+
Array.prototype.__defineSetter__("last", function() {});
37+
38+
Array.prototype.extend = function(list)
39+
{
40+
this.push.apply(this, list);
41+
return this;
42+
};
43+
44+
Array.prototype.insert = function(index, list, replace_count)
45+
{
46+
this.splice.apply(this, [index, replace_count || 0].extend(list));
47+
return this;
48+
};
49+
50+
Array.prototype.contains = function(str)
51+
{
52+
return this.indexOf(str) != -1;
53+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
CanvasRenderingContext2D.prototype.draw_2d_gradient = function(top_color_list,
2+
bottom_color_list,
3+
flip)
4+
{
5+
if (typeof bottom_color_list == "boolean")
6+
{
7+
flip = bottom_color_list;
8+
bottom_color_list = null;
9+
}
10+
11+
if (!this._src_canvas)
12+
{
13+
this._src_canvas = document.createElement("canvas");
14+
this._src_ctx = this._src_canvas.getContext("2d");
15+
}
16+
var width = this._src_canvas.width = this.canvas.width;
17+
var height = this._src_canvas.height = this.canvas.height;
18+
var set_stop = function(color, index, list)
19+
{
20+
this.addColorStop((1 / (list.length - 1 || 1)) * index, color);
21+
};
22+
var lg = flip
23+
? this._src_ctx.createLinearGradient(0, 0, 0, height)
24+
: this._src_ctx.createLinearGradient(0, 0, width, 0);
25+
this._src_ctx.clearRect(0, 0, width, height);
26+
top_color_list.forEach(set_stop, lg);
27+
this._src_ctx.fillStyle = lg;
28+
this._src_ctx.globalCompositeOperation = "source-over";
29+
this._src_ctx.fillRect(0, 0, width, height);
30+
this.drawImage(this._src_canvas, 0, 0);
31+
if (bottom_color_list)
32+
{
33+
this._src_ctx.clearRect(0, 0, width, height);
34+
lg = flip
35+
? this._src_ctx.createLinearGradient(0, 0, width, 0)
36+
: this._src_ctx.createLinearGradient(0, 0, 0, height);
37+
lg.addColorStop(0, "hsla(0, 0%, 0%, 0)");
38+
lg.addColorStop(1, "hsla(0, 0%, 0%, 1)");
39+
this._src_ctx.fillStyle = lg;
40+
this._src_ctx.fillRect(0, 0, width, height);
41+
this._src_ctx.globalCompositeOperation = "source-in";
42+
lg = flip
43+
? this._src_ctx.createLinearGradient(0, 0, 0, height)
44+
: this._src_ctx.createLinearGradient(0, 0, width, 0);
45+
bottom_color_list.forEach(set_stop, lg);
46+
this._src_ctx.fillStyle = lg;
47+
this._src_ctx.fillRect(0, 0, width, height);
48+
this.drawImage(this._src_canvas, 0, 0);
49+
}
50+
};

src/lib/dateprototype.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Local ISO strings, currently needed as datetime-local input values
3+
* http://dev.w3.org/html5/markup/input.datetime-local.html#input.datetime-local.attrs.value
4+
*/
5+
Date.prototype.toLocaleISOString = function()
6+
{
7+
return new Date(this.getTime() - this.getTimezoneOffset() * 1000 * 60).toISOString().replace('Z','');
8+
};

0 commit comments

Comments
 (0)