-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGui.Filter.js
executable file
·151 lines (143 loc) · 4.97 KB
/
Gui.Filter.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Gui.Filter = function(gui, name, items, nav, pos, data){
this.gui = gui;
this.name = name;
this.nav = nav;
this.createContainer(pos);
this.addHeader(name);
this.data = data;
for (var key in items) if (items.hasOwnProperty(key)) {
this.addItem(key, items[key]);
}
this.addCloseButton();
};
Gui.Filter.prototype = {
gui: null,
name: null,
nav: null,
data: null,
container: null,
dragStartMouse: null,
dragStartPos: null,
createContainer: function(pos){
this.container = document.createElement('div');
this.container.className = 'zeon-filter';
Gui.css(this.container, {position:'absolute', left:pos.x+'px', top:pos.y+'px', zIndex:500, backgroundColor:'white', color:'black',fontSize:'12px', padding: '5px', border:'1px solid green', WebkitBorderRadius:'5px', borderRadius:'5px'});
this.nav.gui.layerContainer.appendChild(this.container);
this.container.onclick = function(e){
var action = e.target.className;
if (action == 'prev' || action == 'next' || action == 'current') {
var name = e.target.parentElement.getAttribute('data-message');
var count = e.target.parentElement.getAttribute('data-count');
var pos = this.getAndUpdatePosForDesc(name, count, action);
var go = this.gui.navPos[name] + 1;
var found = 0;
for (var i=0; i<this.data.length; ++i) {
switch (this.name) {
case 'errors':
if (this.data[i].error && this.data[i].error.msg == name) ++found;
break;
case 'warnings':
if (this.data[i].warnings.indexOf(name) >= 0) ++found;
break;
case 'implicitGlobals':
if (this.data[i].value == name) ++found;
break;
case 'knownGlobals':
if (this.data[i].value == name) ++found;
break;
case 'todofix':
if (this.data[i].value == name) ++found;
break;
default:
console.warn('unknown filter type', this.name);
}
if (found == go) break;
}
if (found == go) {
this.gui.showCircleAtMatch(this.data[i], name);
}
e.target.parentNode.getElementsByClassName('current')[0].innerHTML = pos;
}
}.bind(this);
},
addHeader: function(name){
var top = document.createElement('div');
Gui.css(top, {height: '1px', backgroundColor: 'black', position: 'relative', top: '-2px', cursor: 'move', userSelect: 'none', WebkitUserSelect: 'none', MozUserSelect: 'none', border: '2px solid black', WebkitBorderRadius:'3px', borderRadius:'3px'});
this.container.appendChild(top);
top.onmousedown = this.dragStart.bind(this);
var head = document.createElement('div');
head.innerHTML = '<b>'+name+'</b><br/><br/>';
this.container.appendChild(head);
},
addItem: function(desc, count){
var e = document.createElement('div');
var pos = this.getAndUpdatePosForDesc(desc, count);
// there's a delegate to catch clicks on/in this element. the prev, current and next classes cause actions. the data-message of their parent is the warning being used.
e.innerHTML =
'<span style="white-space: pre; font-family: monospace;" data-message="'+desc+'" data-count="'+count+'">'+
(count>1?'<span class="prev" style="cursor:pointer;"><</span>':' ')+
' <span class="current" style="cursor:pointer;">'+pos+'</span> '+
(count>1?'<span class="next" style="cursor:pointer;">></span>':' ')+
' |</span> '+
desc+' '+
'<b>'+count+'x</b>'
;
this.container.appendChild(e);
},
addCloseButton: function(onClose){
this.container.appendChild(document.createElement('br'));
var e = document.createElement('div');
Gui.css(e, 'cursor', 'pointer');
e.innerHTML = 'close';
e.onclick = function(){
this.close();
if (onClose) onClose();
}.bind(this);
this.container.appendChild(e);
},
close: function(){
if (this.container.parentNode) {
this.container.parentNode.removeChild(this.container);
delete this.nav.openFilters[this.name]; // remove yourself from open containers...
this.nav = null;
}
},
getAndUpdatePosForDesc: function(desc, count, action){
var pos = this.gui.navPos[desc] || 0;
if (action == 'prev') --pos;
else if (action == 'next') ++pos;
if (pos >= count) pos = 0;
if (pos < 0) pos = count-1;
this.gui.navPos[desc] = pos;
if (count == 0) pos = ' 0';
else if (pos < 9) pos = ' '+(pos+1);
else pos = pos+1+'';
return pos;
},
dragStart: function(e){
this.dragStartMouse = {x:e.clientX, y:e.clientY};
this.dragStartPos = this.getPosition();
document.body.onmousemove = this.dragMove.bind(this);
document.body.onmouseup = this.dragStop.bind(this);
},
dragMove: function(e){
if (this.dragStartMouse) {
Gui.css(this.container, {
left: this.dragStartPos.x + (e.clientX - this.dragStartMouse.x) + 'px',
top: this.dragStartPos.y + (e.clientY - this.dragStartMouse.y) + 'px'
});
}
},
dragStop: function(){
document.body.onmousemove = null;
document.body.onmouseup = null;
this.dragStartMouse = null;
this.dragStartPos = null;
},
getPosition: function(){
return {
x:parseInt(Gui.css(this.container,'left'),10),
y:parseInt(Gui.css(this.container,'top'), 10)
};
},
0:0};