提交 | 用户 | 时间
|
1ac2bc
|
1 |
/* Copyright 2012 Mozilla Foundation |
懒 |
2 |
* |
|
3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 |
* you may not use this file except in compliance with the License. |
|
5 |
* You may obtain a copy of the License at |
|
6 |
* |
|
7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
8 |
* |
|
9 |
* Unless required by applicable law or agreed to in writing, software |
|
10 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
11 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 |
* See the License for the specific language governing permissions and |
|
13 |
* limitations under the License. |
|
14 |
*/ |
|
15 |
/* eslint-disable no-var */ |
|
16 |
|
|
17 |
'use strict'; |
|
18 |
|
|
19 |
var FontInspector = (function FontInspectorClosure() { |
|
20 |
var fonts, createObjectURL; |
|
21 |
var active = false; |
|
22 |
var fontAttribute = 'data-font-name'; |
|
23 |
function removeSelection() { |
|
24 |
var divs = document.querySelectorAll('div[' + fontAttribute + ']'); |
|
25 |
for (var i = 0, ii = divs.length; i < ii; ++i) { |
|
26 |
var div = divs[i]; |
|
27 |
div.className = ''; |
|
28 |
} |
|
29 |
} |
|
30 |
function resetSelection() { |
|
31 |
var divs = document.querySelectorAll('div[' + fontAttribute + ']'); |
|
32 |
for (var i = 0, ii = divs.length; i < ii; ++i) { |
|
33 |
var div = divs[i]; |
|
34 |
div.className = 'debuggerHideText'; |
|
35 |
} |
|
36 |
} |
|
37 |
function selectFont(fontName, show) { |
|
38 |
var divs = document.querySelectorAll('div[' + fontAttribute + '=' + |
|
39 |
fontName + ']'); |
|
40 |
for (var i = 0, ii = divs.length; i < ii; ++i) { |
|
41 |
var div = divs[i]; |
|
42 |
div.className = show ? 'debuggerShowText' : 'debuggerHideText'; |
|
43 |
} |
|
44 |
} |
|
45 |
function textLayerClick(e) { |
|
46 |
if (!e.target.dataset.fontName || |
|
47 |
e.target.tagName.toUpperCase() !== 'DIV') { |
|
48 |
return; |
|
49 |
} |
|
50 |
var fontName = e.target.dataset.fontName; |
|
51 |
var selects = document.getElementsByTagName('input'); |
|
52 |
for (var i = 0; i < selects.length; ++i) { |
|
53 |
var select = selects[i]; |
|
54 |
if (select.dataset.fontName !== fontName) { |
|
55 |
continue; |
|
56 |
} |
|
57 |
select.checked = !select.checked; |
|
58 |
selectFont(fontName, select.checked); |
|
59 |
select.scrollIntoView(); |
|
60 |
} |
|
61 |
} |
|
62 |
return { |
|
63 |
// Properties/functions needed by PDFBug. |
|
64 |
id: 'FontInspector', |
|
65 |
name: 'Font Inspector', |
|
66 |
panel: null, |
|
67 |
manager: null, |
|
68 |
init: function init(pdfjsLib) { |
|
69 |
var panel = this.panel; |
|
70 |
panel.setAttribute('style', 'padding: 5px;'); |
|
71 |
var tmp = document.createElement('button'); |
|
72 |
tmp.addEventListener('click', resetSelection); |
|
73 |
tmp.textContent = 'Refresh'; |
|
74 |
panel.appendChild(tmp); |
|
75 |
|
|
76 |
fonts = document.createElement('div'); |
|
77 |
panel.appendChild(fonts); |
|
78 |
|
|
79 |
createObjectURL = pdfjsLib.createObjectURL; |
|
80 |
}, |
|
81 |
cleanup: function cleanup() { |
|
82 |
fonts.textContent = ''; |
|
83 |
}, |
|
84 |
enabled: false, |
|
85 |
get active() { |
|
86 |
return active; |
|
87 |
}, |
|
88 |
set active(value) { |
|
89 |
active = value; |
|
90 |
if (active) { |
|
91 |
document.body.addEventListener('click', textLayerClick, true); |
|
92 |
resetSelection(); |
|
93 |
} else { |
|
94 |
document.body.removeEventListener('click', textLayerClick, true); |
|
95 |
removeSelection(); |
|
96 |
} |
|
97 |
}, |
|
98 |
// FontInspector specific functions. |
|
99 |
fontAdded: function fontAdded(fontObj, url) { |
|
100 |
function properties(obj, list) { |
|
101 |
var moreInfo = document.createElement('table'); |
|
102 |
for (var i = 0; i < list.length; i++) { |
|
103 |
var tr = document.createElement('tr'); |
|
104 |
var td1 = document.createElement('td'); |
|
105 |
td1.textContent = list[i]; |
|
106 |
tr.appendChild(td1); |
|
107 |
var td2 = document.createElement('td'); |
|
108 |
td2.textContent = obj[list[i]].toString(); |
|
109 |
tr.appendChild(td2); |
|
110 |
moreInfo.appendChild(tr); |
|
111 |
} |
|
112 |
return moreInfo; |
|
113 |
} |
|
114 |
var moreInfo = properties(fontObj, ['name', 'type']); |
|
115 |
var fontName = fontObj.loadedName; |
|
116 |
var font = document.createElement('div'); |
|
117 |
var name = document.createElement('span'); |
|
118 |
name.textContent = fontName; |
|
119 |
var download = document.createElement('a'); |
|
120 |
if (url) { |
|
121 |
url = /url\(['"]?([^\)"']+)/.exec(url); |
|
122 |
download.href = url[1]; |
|
123 |
} else if (fontObj.data) { |
|
124 |
download.href = createObjectURL(fontObj.data, fontObj.mimeType); |
|
125 |
} |
|
126 |
download.textContent = 'Download'; |
|
127 |
var logIt = document.createElement('a'); |
|
128 |
logIt.href = ''; |
|
129 |
logIt.textContent = 'Log'; |
|
130 |
logIt.addEventListener('click', function(event) { |
|
131 |
event.preventDefault(); |
|
132 |
console.log(fontObj); |
|
133 |
}); |
|
134 |
var select = document.createElement('input'); |
|
135 |
select.setAttribute('type', 'checkbox'); |
|
136 |
select.dataset.fontName = fontName; |
|
137 |
select.addEventListener('click', (function(select, fontName) { |
|
138 |
return (function() { |
|
139 |
selectFont(fontName, select.checked); |
|
140 |
}); |
|
141 |
})(select, fontName)); |
|
142 |
font.appendChild(select); |
|
143 |
font.appendChild(name); |
|
144 |
font.appendChild(document.createTextNode(' ')); |
|
145 |
font.appendChild(download); |
|
146 |
font.appendChild(document.createTextNode(' ')); |
|
147 |
font.appendChild(logIt); |
|
148 |
font.appendChild(moreInfo); |
|
149 |
fonts.appendChild(font); |
|
150 |
// Somewhat of a hack, should probably add a hook for when the text layer |
|
151 |
// is done rendering. |
|
152 |
setTimeout(() => { |
|
153 |
if (this.active) { |
|
154 |
resetSelection(); |
|
155 |
} |
|
156 |
}, 2000); |
|
157 |
}, |
|
158 |
}; |
|
159 |
})(); |
|
160 |
|
|
161 |
var opMap; |
|
162 |
|
|
163 |
// Manages all the page steppers. |
|
164 |
var StepperManager = (function StepperManagerClosure() { |
|
165 |
var steppers = []; |
|
166 |
var stepperDiv = null; |
|
167 |
var stepperControls = null; |
|
168 |
var stepperChooser = null; |
|
169 |
var breakPoints = Object.create(null); |
|
170 |
return { |
|
171 |
// Properties/functions needed by PDFBug. |
|
172 |
id: 'Stepper', |
|
173 |
name: 'Stepper', |
|
174 |
panel: null, |
|
175 |
manager: null, |
|
176 |
init: function init(pdfjsLib) { |
|
177 |
var self = this; |
|
178 |
this.panel.setAttribute('style', 'padding: 5px;'); |
|
179 |
stepperControls = document.createElement('div'); |
|
180 |
stepperChooser = document.createElement('select'); |
|
181 |
stepperChooser.addEventListener('change', function(event) { |
|
182 |
self.selectStepper(this.value); |
|
183 |
}); |
|
184 |
stepperControls.appendChild(stepperChooser); |
|
185 |
stepperDiv = document.createElement('div'); |
|
186 |
this.panel.appendChild(stepperControls); |
|
187 |
this.panel.appendChild(stepperDiv); |
|
188 |
if (sessionStorage.getItem('pdfjsBreakPoints')) { |
|
189 |
breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints')); |
|
190 |
} |
|
191 |
|
|
192 |
opMap = Object.create(null); |
|
193 |
for (var key in pdfjsLib.OPS) { |
|
194 |
opMap[pdfjsLib.OPS[key]] = key; |
|
195 |
} |
|
196 |
}, |
|
197 |
cleanup: function cleanup() { |
|
198 |
stepperChooser.textContent = ''; |
|
199 |
stepperDiv.textContent = ''; |
|
200 |
steppers = []; |
|
201 |
}, |
|
202 |
enabled: false, |
|
203 |
active: false, |
|
204 |
// Stepper specific functions. |
|
205 |
create: function create(pageIndex) { |
|
206 |
var debug = document.createElement('div'); |
|
207 |
debug.id = 'stepper' + pageIndex; |
|
208 |
debug.setAttribute('hidden', true); |
|
209 |
debug.className = 'stepper'; |
|
210 |
stepperDiv.appendChild(debug); |
|
211 |
var b = document.createElement('option'); |
|
212 |
b.textContent = 'Page ' + (pageIndex + 1); |
|
213 |
b.value = pageIndex; |
|
214 |
stepperChooser.appendChild(b); |
|
215 |
var initBreakPoints = breakPoints[pageIndex] || []; |
|
216 |
var stepper = new Stepper(debug, pageIndex, initBreakPoints); |
|
217 |
steppers.push(stepper); |
|
218 |
if (steppers.length === 1) { |
|
219 |
this.selectStepper(pageIndex, false); |
|
220 |
} |
|
221 |
return stepper; |
|
222 |
}, |
|
223 |
selectStepper: function selectStepper(pageIndex, selectPanel) { |
|
224 |
var i; |
|
225 |
pageIndex = pageIndex | 0; |
|
226 |
if (selectPanel) { |
|
227 |
this.manager.selectPanel(this); |
|
228 |
} |
|
229 |
for (i = 0; i < steppers.length; ++i) { |
|
230 |
var stepper = steppers[i]; |
|
231 |
if (stepper.pageIndex === pageIndex) { |
|
232 |
stepper.panel.removeAttribute('hidden'); |
|
233 |
} else { |
|
234 |
stepper.panel.setAttribute('hidden', true); |
|
235 |
} |
|
236 |
} |
|
237 |
var options = stepperChooser.options; |
|
238 |
for (i = 0; i < options.length; ++i) { |
|
239 |
var option = options[i]; |
|
240 |
option.selected = (option.value | 0) === pageIndex; |
|
241 |
} |
|
242 |
}, |
|
243 |
saveBreakPoints: function saveBreakPoints(pageIndex, bps) { |
|
244 |
breakPoints[pageIndex] = bps; |
|
245 |
sessionStorage.setItem('pdfjsBreakPoints', JSON.stringify(breakPoints)); |
|
246 |
}, |
|
247 |
}; |
|
248 |
})(); |
|
249 |
|
|
250 |
// The stepper for each page's IRQueue. |
|
251 |
var Stepper = (function StepperClosure() { |
|
252 |
// Shorter way to create element and optionally set textContent. |
|
253 |
function c(tag, textContent) { |
|
254 |
var d = document.createElement(tag); |
|
255 |
if (textContent) { |
|
256 |
d.textContent = textContent; |
|
257 |
} |
|
258 |
return d; |
|
259 |
} |
|
260 |
|
|
261 |
function simplifyArgs(args) { |
|
262 |
if (typeof args === 'string') { |
|
263 |
var MAX_STRING_LENGTH = 75; |
|
264 |
return args.length <= MAX_STRING_LENGTH ? args : |
|
265 |
args.substring(0, MAX_STRING_LENGTH) + '...'; |
|
266 |
} |
|
267 |
if (typeof args !== 'object' || args === null) { |
|
268 |
return args; |
|
269 |
} |
|
270 |
if ('length' in args) { // array |
|
271 |
var simpleArgs = [], i, ii; |
|
272 |
var MAX_ITEMS = 10; |
|
273 |
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) { |
|
274 |
simpleArgs.push(simplifyArgs(args[i])); |
|
275 |
} |
|
276 |
if (i < args.length) { |
|
277 |
simpleArgs.push('...'); |
|
278 |
} |
|
279 |
return simpleArgs; |
|
280 |
} |
|
281 |
var simpleObj = {}; |
|
282 |
for (var key in args) { |
|
283 |
simpleObj[key] = simplifyArgs(args[key]); |
|
284 |
} |
|
285 |
return simpleObj; |
|
286 |
} |
|
287 |
|
|
288 |
function Stepper(panel, pageIndex, initialBreakPoints) { |
|
289 |
this.panel = panel; |
|
290 |
this.breakPoint = 0; |
|
291 |
this.nextBreakPoint = null; |
|
292 |
this.pageIndex = pageIndex; |
|
293 |
this.breakPoints = initialBreakPoints; |
|
294 |
this.currentIdx = -1; |
|
295 |
this.operatorListIdx = 0; |
|
296 |
} |
|
297 |
Stepper.prototype = { |
|
298 |
init: function init(operatorList) { |
|
299 |
var panel = this.panel; |
|
300 |
var content = c('div', 'c=continue, s=step'); |
|
301 |
var table = c('table'); |
|
302 |
content.appendChild(table); |
|
303 |
table.cellSpacing = 0; |
|
304 |
var headerRow = c('tr'); |
|
305 |
table.appendChild(headerRow); |
|
306 |
headerRow.appendChild(c('th', 'Break')); |
|
307 |
headerRow.appendChild(c('th', 'Idx')); |
|
308 |
headerRow.appendChild(c('th', 'fn')); |
|
309 |
headerRow.appendChild(c('th', 'args')); |
|
310 |
panel.appendChild(content); |
|
311 |
this.table = table; |
|
312 |
this.updateOperatorList(operatorList); |
|
313 |
}, |
|
314 |
updateOperatorList: function updateOperatorList(operatorList) { |
|
315 |
var self = this; |
|
316 |
|
|
317 |
function cboxOnClick() { |
|
318 |
var x = +this.dataset.idx; |
|
319 |
if (this.checked) { |
|
320 |
self.breakPoints.push(x); |
|
321 |
} else { |
|
322 |
self.breakPoints.splice(self.breakPoints.indexOf(x), 1); |
|
323 |
} |
|
324 |
StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints); |
|
325 |
} |
|
326 |
|
|
327 |
var MAX_OPERATORS_COUNT = 15000; |
|
328 |
if (this.operatorListIdx > MAX_OPERATORS_COUNT) { |
|
329 |
return; |
|
330 |
} |
|
331 |
|
|
332 |
var chunk = document.createDocumentFragment(); |
|
333 |
var operatorsToDisplay = Math.min(MAX_OPERATORS_COUNT, |
|
334 |
operatorList.fnArray.length); |
|
335 |
for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) { |
|
336 |
var line = c('tr'); |
|
337 |
line.className = 'line'; |
|
338 |
line.dataset.idx = i; |
|
339 |
chunk.appendChild(line); |
|
340 |
var checked = this.breakPoints.includes(i); |
|
341 |
var args = operatorList.argsArray[i] || []; |
|
342 |
|
|
343 |
var breakCell = c('td'); |
|
344 |
var cbox = c('input'); |
|
345 |
cbox.type = 'checkbox'; |
|
346 |
cbox.className = 'points'; |
|
347 |
cbox.checked = checked; |
|
348 |
cbox.dataset.idx = i; |
|
349 |
cbox.onclick = cboxOnClick; |
|
350 |
|
|
351 |
breakCell.appendChild(cbox); |
|
352 |
line.appendChild(breakCell); |
|
353 |
line.appendChild(c('td', i.toString())); |
|
354 |
var fn = opMap[operatorList.fnArray[i]]; |
|
355 |
var decArgs = args; |
|
356 |
if (fn === 'showText') { |
|
357 |
var glyphs = args[0]; |
|
358 |
var newArgs = []; |
|
359 |
var str = []; |
|
360 |
for (var j = 0; j < glyphs.length; j++) { |
|
361 |
var glyph = glyphs[j]; |
|
362 |
if (typeof glyph === 'object' && glyph !== null) { |
|
363 |
str.push(glyph.fontChar); |
|
364 |
} else { |
|
365 |
if (str.length > 0) { |
|
366 |
newArgs.push(str.join('')); |
|
367 |
str = []; |
|
368 |
} |
|
369 |
newArgs.push(glyph); // null or number |
|
370 |
} |
|
371 |
} |
|
372 |
if (str.length > 0) { |
|
373 |
newArgs.push(str.join('')); |
|
374 |
} |
|
375 |
decArgs = [newArgs]; |
|
376 |
} |
|
377 |
line.appendChild(c('td', fn)); |
|
378 |
line.appendChild(c('td', JSON.stringify(simplifyArgs(decArgs)))); |
|
379 |
} |
|
380 |
if (operatorsToDisplay < operatorList.fnArray.length) { |
|
381 |
line = c('tr'); |
|
382 |
var lastCell = c('td', '...'); |
|
383 |
lastCell.colspan = 4; |
|
384 |
chunk.appendChild(lastCell); |
|
385 |
} |
|
386 |
this.operatorListIdx = operatorList.fnArray.length; |
|
387 |
this.table.appendChild(chunk); |
|
388 |
}, |
|
389 |
getNextBreakPoint: function getNextBreakPoint() { |
|
390 |
this.breakPoints.sort(function(a, b) { |
|
391 |
return a - b; |
|
392 |
}); |
|
393 |
for (var i = 0; i < this.breakPoints.length; i++) { |
|
394 |
if (this.breakPoints[i] > this.currentIdx) { |
|
395 |
return this.breakPoints[i]; |
|
396 |
} |
|
397 |
} |
|
398 |
return null; |
|
399 |
}, |
|
400 |
breakIt: function breakIt(idx, callback) { |
|
401 |
StepperManager.selectStepper(this.pageIndex, true); |
|
402 |
var self = this; |
|
403 |
var dom = document; |
|
404 |
self.currentIdx = idx; |
|
405 |
var listener = function(e) { |
|
406 |
switch (e.keyCode) { |
|
407 |
case 83: // step |
|
408 |
dom.removeEventListener('keydown', listener); |
|
409 |
self.nextBreakPoint = self.currentIdx + 1; |
|
410 |
self.goTo(-1); |
|
411 |
callback(); |
|
412 |
break; |
|
413 |
case 67: // continue |
|
414 |
dom.removeEventListener('keydown', listener); |
|
415 |
var breakPoint = self.getNextBreakPoint(); |
|
416 |
self.nextBreakPoint = breakPoint; |
|
417 |
self.goTo(-1); |
|
418 |
callback(); |
|
419 |
break; |
|
420 |
} |
|
421 |
}; |
|
422 |
dom.addEventListener('keydown', listener); |
|
423 |
self.goTo(idx); |
|
424 |
}, |
|
425 |
goTo: function goTo(idx) { |
|
426 |
var allRows = this.panel.getElementsByClassName('line'); |
|
427 |
for (var x = 0, xx = allRows.length; x < xx; ++x) { |
|
428 |
var row = allRows[x]; |
|
429 |
if ((row.dataset.idx | 0) === idx) { |
|
430 |
row.style.backgroundColor = 'rgb(251,250,207)'; |
|
431 |
row.scrollIntoView(); |
|
432 |
} else { |
|
433 |
row.style.backgroundColor = null; |
|
434 |
} |
|
435 |
} |
|
436 |
}, |
|
437 |
}; |
|
438 |
return Stepper; |
|
439 |
})(); |
|
440 |
|
|
441 |
var Stats = (function Stats() { |
|
442 |
var stats = []; |
|
443 |
function clear(node) { |
|
444 |
while (node.hasChildNodes()) { |
|
445 |
node.removeChild(node.lastChild); |
|
446 |
} |
|
447 |
} |
|
448 |
function getStatIndex(pageNumber) { |
|
449 |
for (var i = 0, ii = stats.length; i < ii; ++i) { |
|
450 |
if (stats[i].pageNumber === pageNumber) { |
|
451 |
return i; |
|
452 |
} |
|
453 |
} |
|
454 |
return false; |
|
455 |
} |
|
456 |
return { |
|
457 |
// Properties/functions needed by PDFBug. |
|
458 |
id: 'Stats', |
|
459 |
name: 'Stats', |
|
460 |
panel: null, |
|
461 |
manager: null, |
|
462 |
init(pdfjsLib) { |
|
463 |
this.panel.setAttribute('style', 'padding: 5px;'); |
|
464 |
}, |
|
465 |
enabled: false, |
|
466 |
active: false, |
|
467 |
// Stats specific functions. |
|
468 |
add(pageNumber, stat) { |
|
469 |
if (!stat) { |
|
470 |
return; |
|
471 |
} |
|
472 |
var statsIndex = getStatIndex(pageNumber); |
|
473 |
if (statsIndex !== false) { |
|
474 |
var b = stats[statsIndex]; |
|
475 |
this.panel.removeChild(b.div); |
|
476 |
stats.splice(statsIndex, 1); |
|
477 |
} |
|
478 |
var wrapper = document.createElement('div'); |
|
479 |
wrapper.className = 'stats'; |
|
480 |
var title = document.createElement('div'); |
|
481 |
title.className = 'title'; |
|
482 |
title.textContent = 'Page: ' + pageNumber; |
|
483 |
var statsDiv = document.createElement('div'); |
|
484 |
statsDiv.textContent = stat.toString(); |
|
485 |
wrapper.appendChild(title); |
|
486 |
wrapper.appendChild(statsDiv); |
|
487 |
stats.push({ pageNumber, div: wrapper, }); |
|
488 |
stats.sort(function(a, b) { |
|
489 |
return a.pageNumber - b.pageNumber; |
|
490 |
}); |
|
491 |
clear(this.panel); |
|
492 |
for (var i = 0, ii = stats.length; i < ii; ++i) { |
|
493 |
this.panel.appendChild(stats[i].div); |
|
494 |
} |
|
495 |
}, |
|
496 |
cleanup() { |
|
497 |
stats = []; |
|
498 |
clear(this.panel); |
|
499 |
}, |
|
500 |
}; |
|
501 |
})(); |
|
502 |
|
|
503 |
// Manages all the debugging tools. |
|
504 |
window.PDFBug = (function PDFBugClosure() { |
|
505 |
var panelWidth = 300; |
|
506 |
var buttons = []; |
|
507 |
var activePanel = null; |
|
508 |
|
|
509 |
return { |
|
510 |
tools: [ |
|
511 |
FontInspector, |
|
512 |
StepperManager, |
|
513 |
Stats |
|
514 |
], |
|
515 |
enable(ids) { |
|
516 |
var all = false, tools = this.tools; |
|
517 |
if (ids.length === 1 && ids[0] === 'all') { |
|
518 |
all = true; |
|
519 |
} |
|
520 |
for (var i = 0; i < tools.length; ++i) { |
|
521 |
var tool = tools[i]; |
|
522 |
if (all || ids.includes(tool.id)) { |
|
523 |
tool.enabled = true; |
|
524 |
} |
|
525 |
} |
|
526 |
if (!all) { |
|
527 |
// Sort the tools by the order they are enabled. |
|
528 |
tools.sort(function(a, b) { |
|
529 |
var indexA = ids.indexOf(a.id); |
|
530 |
indexA = indexA < 0 ? tools.length : indexA; |
|
531 |
var indexB = ids.indexOf(b.id); |
|
532 |
indexB = indexB < 0 ? tools.length : indexB; |
|
533 |
return indexA - indexB; |
|
534 |
}); |
|
535 |
} |
|
536 |
}, |
|
537 |
init(pdfjsLib, container) { |
|
538 |
/* |
|
539 |
* Basic Layout: |
|
540 |
* PDFBug |
|
541 |
* Controls |
|
542 |
* Panels |
|
543 |
* Panel |
|
544 |
* Panel |
|
545 |
* ... |
|
546 |
*/ |
|
547 |
var ui = document.createElement('div'); |
|
548 |
ui.id = 'PDFBug'; |
|
549 |
|
|
550 |
var controls = document.createElement('div'); |
|
551 |
controls.setAttribute('class', 'controls'); |
|
552 |
ui.appendChild(controls); |
|
553 |
|
|
554 |
var panels = document.createElement('div'); |
|
555 |
panels.setAttribute('class', 'panels'); |
|
556 |
ui.appendChild(panels); |
|
557 |
|
|
558 |
container.appendChild(ui); |
|
559 |
container.style.right = panelWidth + 'px'; |
|
560 |
|
|
561 |
// Initialize all the debugging tools. |
|
562 |
var tools = this.tools; |
|
563 |
var self = this; |
|
564 |
for (var i = 0; i < tools.length; ++i) { |
|
565 |
var tool = tools[i]; |
|
566 |
var panel = document.createElement('div'); |
|
567 |
var panelButton = document.createElement('button'); |
|
568 |
panelButton.textContent = tool.name; |
|
569 |
panelButton.addEventListener('click', (function(selected) { |
|
570 |
return function(event) { |
|
571 |
event.preventDefault(); |
|
572 |
self.selectPanel(selected); |
|
573 |
}; |
|
574 |
})(i)); |
|
575 |
controls.appendChild(panelButton); |
|
576 |
panels.appendChild(panel); |
|
577 |
tool.panel = panel; |
|
578 |
tool.manager = this; |
|
579 |
if (tool.enabled) { |
|
580 |
tool.init(pdfjsLib); |
|
581 |
} else { |
|
582 |
panel.textContent = tool.name + ' is disabled. To enable add ' + |
|
583 |
' "' + tool.id + '" to the pdfBug parameter ' + |
|
584 |
'and refresh (separate multiple by commas).'; |
|
585 |
} |
|
586 |
buttons.push(panelButton); |
|
587 |
} |
|
588 |
this.selectPanel(0); |
|
589 |
}, |
|
590 |
cleanup() { |
|
591 |
for (var i = 0, ii = this.tools.length; i < ii; i++) { |
|
592 |
if (this.tools[i].enabled) { |
|
593 |
this.tools[i].cleanup(); |
|
594 |
} |
|
595 |
} |
|
596 |
}, |
|
597 |
selectPanel(index) { |
|
598 |
if (typeof index !== 'number') { |
|
599 |
index = this.tools.indexOf(index); |
|
600 |
} |
|
601 |
if (index === activePanel) { |
|
602 |
return; |
|
603 |
} |
|
604 |
activePanel = index; |
|
605 |
var tools = this.tools; |
|
606 |
for (var j = 0; j < tools.length; ++j) { |
|
607 |
if (j === index) { |
|
608 |
buttons[j].setAttribute('class', 'active'); |
|
609 |
tools[j].active = true; |
|
610 |
tools[j].panel.removeAttribute('hidden'); |
|
611 |
} else { |
|
612 |
buttons[j].setAttribute('class', ''); |
|
613 |
tools[j].active = false; |
|
614 |
tools[j].panel.setAttribute('hidden', 'true'); |
|
615 |
} |
|
616 |
} |
|
617 |
}, |
|
618 |
}; |
|
619 |
})(); |