-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphical-position.js
251 lines (214 loc) · 8.92 KB
/
graphical-position.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* NEW BSD LICENSE {{{
Copyright (c) 2014, Jagua.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
###################################################################################
# http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license #
# に参考になる日本語訳がありますが、有効なのは上記英文となります。 #
###################################################################################
}}} */
var INFO = xml`
<plugin name="GPosition"
version="0.5"
href="https://github.com/Jagua/vimperator-plugins-sample/blob/master/graphical-position.js"
summary="Graphical Position"
lang="en-US"
xmlns="http://vimperator.org/namespaces/liberator">
<author homepage="https://github.com/Jagua">Jagua</author>
<license>New BSD License</license>
<project name="Vimperator" minVersion="3.8"/>
<item>
<tags>'gposition'</tags>
<spec>'gposition'</spec>
<description>
<p>Show the graphical position of vertical scroll in the status bar.</p>
</description>
</item>
</plugin>`;
(function () {
var e = document.createElement('toolbaritem');
e.setAttribute('id', 'liberator-status-gposition');
document.getElementById('liberator-status').appendChild(e);
drawGPosition_init();
statusline.addField(
'gposition',
'The graphical position of vertical scroll',
'liberator-status-gposition',
function updateGPosition (node, percent) {
if (!percent || typeof percent != 'number') {
let win = document.commandDispatcher.focusedWindow;
if (win && win.scrollMaxY != 0) {
percent = win.scrollY / win.scrollMaxY * 100;
} else if (win && win.scrollY == 0 && win.scrollMaxY == 0) {
percent = -2;
} else {
return;
}
}
node.value = '';
drawGPosition_update(percent);
}
);
function drawGPosition_init() {
var e = document.getElementById('liberator-status-gposition');
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
svg.setAttribute('id', 'liberator-status-gposition-svg');
svg.setAttribute('width', '16px');
svg.setAttribute('height', '16px');
svg.setAttribute('version', '1.1');
var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttribute('id', 'liberator-status-gposition-svg-path');
svg.appendChild(path);
path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttribute('id', 'liberator-status-gposition-border');
svg.appendChild(path);
e.appendChild(svg);
}
function drawGPosition_update(percent) {
function d_(per, cx, cy, r) {
let d = ``;
let deg = per * 360 / 100 - 90;
if (deg > 269)
deg = 270 - 0.1;
if (deg <= -90)
deg = -90 + 0.1;
let x1 = cx + r * Math.cos(-90 * Math.PI / 180);
let y1 = cy + r * Math.sin(-90 * Math.PI / 180);
let x2 = cx + r * Math.cos(deg * Math.PI / 180);
let y2 = cy + r * Math.sin(deg * Math.PI / 180);
let dx = x2 - x1;
let dy = y2 - y1;
let flag = 0;
if (per > 50)
flag = 1;
if (per == 100) {
d = `M ${cx},${cy - r} a ${r} ${r} -90 ${flag} 1 ${dx},${dy}`;
} else {
d = `M ${cx},${cy} L ${cx},${cy - r} a ${r} ${r} -90 `
+ `${flag} 1 ${dx},${dy} L ${cx},${cy} Z`;
}
return d;
}
let path = document.getElementById('liberator-status-gposition-svg-path');
if (percent == -1) {
let e = document.getElementById('liberator-status-gposition-loading');
if (!e) {
let svg = document.getElementById('liberator-status-gposition-svg');
let circle = document.createElementNS('http://www.w3.org/2000/svg',
'circle');
circle.setAttribute('id', 'liberator-status-gposition-loading');
circle.setAttribute('cx', '8px');
circle.setAttribute('cy', '8px');
circle.setAttribute('r', '4px');
circle.setAttribute('fill', 'transparent');
circle.setAttribute('stroke', 'black');
circle.setAttribute('stroke-width', '5px');
circle.setAttribute('stroke-dasharray', '1.2,3');
let a = document.createElementNS('http://www.w3.org/2000/svg',
'animateTransform');
a.setAttribute('attributeType', 'auto');
a.setAttribute('attributeName', 'transform');
a.setAttribute('type', 'rotate');
a.setAttribute('from', '0 8 8');
a.setAttribute('to', '360 8 8');
a.setAttribute('dur', '3s');
a.setAttribute('stroke', 'freeze');
a.setAttribute('repeatCount', 'indefinite');
circle.appendChild(a);
svg.appendChild(circle);
path.setAttribute('style', 'visibility: hidden');
}
} else {
let e = document.getElementById('liberator-status-gposition-loading');
if (e) {
let svg = document.getElementById('liberator-status-gposition-svg');
svg.removeChild(e);
}
path.setAttribute('style', 'visibility:visible');
}
let d = d_(percent, 7 + 1, 1 + 7, 7); // radius=7, padding=1
if (percent == -1) {
path.setAttribute('class', 'position_phase_loading');
path.setAttribute('style', 'visibility:hidden');
} else if (percent == -2) {
d = d_(100, 7 + 1, 1 + 7, 4);
path.setAttribute('class', 'position_phase_whole');
path.setAttribute('style', 'fill:DimGray');
} else if (percent == 0) {
path.setAttribute('class', 'position_phase_top');
path.setAttribute('style', 'fill:white');
} else if (percent == 100) {
path.setAttribute('class', 'position_phase_bottom');
path.setAttribute('style', 'fill:DimGray');
} else {
path.setAttribute('class', 'position_phase_interlude');
path.setAttribute('style', 'fill:gray');
}
path.setAttribute('d', d);
path = document.getElementById('liberator-status-gposition-border');
d = d_(100, 7 + 1, 1 + 7, 7); // radius=7, padding=1
path.setAttribute('d', d);
if (percent == -1) {
path.setAttribute('style',
'stroke:silver; stroke-dasharray:2.5,2.5,0.5,2.5;'
+ ' stroke-width:2; fill:transparent');
} else if (percent == -2) {
path.setAttribute('style',
'stroke:Black; stroke-width:1px; fill:transparent');
} else if (percent == 0) {
path.setAttribute('style',
'stroke:black; stroke-dasharray:2.5,2.5,0.5,2.5;'
+ ' stroke-width:2; fill:transparent');
} else if (percent == 100) {
path.setAttribute('style',
'stroke:Black; stroke-width:1.2px; fill:transparent');
} else {
path.setAttribute('style',
'stroke:DarkSlateGray; stroke-width:1px; fill:transparent');
}
}
autocommands.add(
'LocationChange',
'.*',
function () {
statusline.updateField('gposition', -1);
if (document.readyState == 'complete') {
setTimeout(function () {
statusline.updateField('gposition');}, 250);
} else {
document.onreadystatechange = function () {
if (document.readyState == 'complete') {
statusline.updateField('gposition');
}
};
}
}
);
gBrowser.addEventListener('scroll', function (e) {
statusline.updateField('gposition');
}, false);
gBrowser.addEventListener('DOMContentLoaded', function (e) {
statusline.updateField('gposition');
}, false);
options.status += ',gposition';
})();
// vim: set et fdm=marker ft=javascript sts=2 sw=2 ts=2 :