Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
108 lines (95 loc) · 2.97 KB
/
Copy pathutils.js
File metadata and controls
108 lines (95 loc) · 2.97 KB
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
99
100
101
102
103
104
105
106
107
exports.validRegex = function (str, modif) {
try {
var re = new RegExp(str, modif);
return re;
}
catch (e) {
return null;
}
};
exports.hashFile = function () {
var str = document.location.hash || "";
var lst = str.split(":");
var res = lst[0].length > 0 ? lst[0].substring(1) : "";
// console.log("Hash: " + res);
return res;
};
exports.htmlEntities = function (str) {
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/\n/g, '<br>').replace(/( |\u00a0)/g, ' ').replace(/\t/g, ' ');
};
function Selector() {
this.list = [[]];
this.x = 0;
this.y = 0;
this.current = null;
}
exports.Selector = Selector;
Selector.prototype.clear = function () {
this.clearCurrent();
this.list = [[]];
this.x = 0;
// this.x = this.y = -1;
};
Selector.prototype.clearCurrent = function () {
if (this.list.length == 0) return;
if (this.current) {
// this.current.style["background-color"] = null;
// this.current.style["text-shadow"] = null;
$(this.current).removeClass("selector");
this.current = null;
}
};
Selector.prototype.setCurrent = function (x,y) {
y = y || 0;
if (this.list.length == 0) return;
this.x = x%this.list.length;
this.y = y%this.list[this.x].length;
if (this.list[this.x].length == 0) return;
this.clearCurrent();
while (this.x > 0 && (!this.list[this.x][this.y] || !this.list[this.x][this.y].elem)) this.x--;
var item = this.list[this.x][this.y];
if (item.activated) item.activated();
this.current = document.getElementById(item.elem);
if (this.current) {
$(this.current).addClass("selector");
// this.current.style["background-color"] = "yellow";
}
};
Selector.prototype.resetCurrent = function () {
this.setCurrent(this.x, this.y);
};
Selector.prototype.add = function (x, y, elem, command, act) {
if (!this.list[x]) this.list[x] = [];
this.list[x][y] = {elem:elem, command:command, activated: act};
if (this.x == -1) this.setCurrent(x,y);
};
Selector.prototype.handleKey = function (ev) {
if (this.x == -1) return true;
if (ev.keyIdentifier == "Up") {
this.setCurrent(this.x, (this.y - 1 + this.list[this.x].length) % this.list[this.x].length);
return false;
}
else if (ev.keyIdentifier == "Down") {
this.setCurrent(this.x, (this.y + 1) % this.list[this.x].length);
return false;
}
else if (ev.keyIdentifier == "Left") {
this.setCurrent((this.x - 1 + this.list.length) % this.list.length, this.y);
return false;
}
else if (ev.keyIdentifier == "Right") {
this.setCurrent((this.x + 1) % this.list.length, this.y);
return false;
}
else if (ev.keyIdentifier == "Enter") {
this.list[this.x][this.y].command();
return false;
}
return true;
};
exports.timed = function (f) {
var t1 = new Date().getTime();
f();
var t2 = new Date().getTime();
console.log(t2-t1);
};