/
Copy pathhelpers.js
98 lines (89 loc) · 2.61 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
varTAU=//////|//////
///// | /////
/// tau ///
/// ...--> | <--... ///
/// -' one | turn '- ///
// .' | '. //
// / | \ //
// | | <-.. | //
// | .->| \ | //
// | / | | | //
------Math.PI+Math.PI-----0
// | \ | | | //
// | '->| / | //
// | | <-'' | //
// \ | / //
// '. | .' //
/// -. | .- ///
/// '''----|----''' ///
/// | ///
////// | /////
//////|////// C/r;
var$G=$(window);
functionCursor(cursor_def){
return"url(images/cursors/"+cursor_def[0]+".png) "+
cursor_def[1].join(" ")+
", "+cursor_def[2]
}
functionE(t){
returndocument.createElement(t);
}
varDESKTOP_ICON_SIZE=32;
varTASKBAR_ICON_SIZE=16;
varTITLEBAR_ICON_SIZE=16;
// For Wayback Machine, match URLs like https://web.archive.org/web/20191213113214/https://98.js.org/
// (also match URLs like https://98.js.org/ because why not)
constweb_server_root_for_icons=
location.href.match(/98.js.org/) ?
location.href.match(/.*98.js.org/)[0]+"/" :
"/";
functiongetIconPath(iconID,size){
returnweb_server_root_for_icons+"images/icons/"+iconID+"-"+size+"x"+size+".png";
}
functionCanvas(width,height){
varnew_canvas=E("canvas");
varnew_ctx=new_canvas.getContext("2d");
new_ctx.imageSmoothingEnabled=false;
new_ctx.mozImageSmoothingEnabled=false;
new_ctx.webkitImageSmoothingEnabled=false;
if(width&&height){
// new Canvas(width, height)
new_canvas.width=width;
new_canvas.height=height;
}else{
// new Canvas(image)
varcopy_of=width;
if(copy_of){
new_canvas.width=copy_of.width;
new_canvas.height=copy_of.height;
new_ctx.drawImage(copy_of,0,0);
}
}
new_canvas.ctx=new_ctx;
returnnew_canvas;
}
functionmustHaveMethods(obj,methodNames){
for(constmethodNameofmethodNames){
if(typeofobj[methodName]!='function'){
console.error("Missing method",methodName,"on object",obj);
thrownewTypeError("missing method "+methodName);
}
}
returntrue;
}
constwindowInterfaceMethods=[
"close",
"minimize",
"unminimize",
// "maximize",
// "unmaximize",
"bringToFront",// TODO: maybe setZIndex instead
"getTitle",
// "getIconName",
"getIconAtSize",
"focus",
"blur",
"onFocus",
"onBlur",
"onClosed",
];