-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglyph.js
113 lines (100 loc) · 2.38 KB
/
glyph.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var gestsGlyph = function() {
var wrapper;
var glyphContainer;
var opacity;
var nameContainer;
var nameBox;
var nameIsOnPage;
var settings;
var fontColor = "#ffffff";
var backgroundColor = "#bdbdbd";
function createContext() {
if(!wrapper) {
wrapper = document.createElement("div");
wrapper.id = "gestsGlyphWrapper";
glyphContainer = document.createElement("div");
glyphContainer.id = "gestsGlyphContainer";
wrapper.appendChild(glyphContainer);
document.body.appendChild(wrapper);
} else {
document.body.appendChild(wrapper);
}
}
function deleteContext() {
if(wrapper) {
document.body.removeChild(wrapper);
glyphContainer.innerHTML = "";
}
}
function createGlyph(letter) {
if(glyphContainer) {
var glyph = document.createElement("div");
glyph.className = "gestsGlyph";
glyph.style.opacity = settings.glyph.opacity;
var symbol;
if(settings.glyph.arrowMode) {
switch(letter) {
case "U":
symbol = "↑";
break;
case "R":
symbol = "→";
break;
case "D":
symbol = "↓";
break;
case "L":
symbol = "←";
break;
default:
symbol = letter;
}
} else {
symbol = letter;
}
glyph.style.color = fontColor;
glyph.style["background-color"] = backgroundColor;
glyph.innerHTML = symbol;
glyphContainer.appendChild(glyph);
}
}
function drawName(name) {
if(wrapper) {
if(!nameContainer) {
nameContainer = document.createElement("div");
nameContainer.id = "gestsGlyphNameContainer";
nameBox = document.createElement("span");
nameBox.innerHTML = name;
nameBox.style.color = settings.glyph.fontColor;
nameBox.style["background-color"] = settings.glyph.backgroundColor;
nameBox.id = "gestsGlyphName";
nameContainer.appendChild(nameBox);
wrapper.appendChild(nameContainer);
nameIsOnPage = true;
} else {
nameIsOnPage = true;
nameBox.innerHTML = name;
wrapper.appendChild(nameContainer);
}
}
}
function deleteName() {
if(wrapper) {
if(nameContainer && nameIsOnPage) {
nameIsOnPage = false;
wrapper.removeChild(nameContainer);
}
}
}
function loadSettings(newSettings) {
settings = newSettings;
}
return {
createContext: createContext,
deleteContext: deleteContext,
push: createGlyph,
drawName: drawName,
deleteName: deleteName,
loadSettings: loadSettings
}
};