Fix coding style in web/debugger.js

This commit is contained in:
Jonas Jenwald 2014-03-08 23:42:23 +01:00
parent 665b862b7f
commit e9cfae84a0

View File

@ -46,13 +46,17 @@ var FontInspector = (function FontInspectorClosure() {
} }
} }
function textLayerClick(e) { function textLayerClick(e) {
if (!e.target.dataset.fontName || e.target.tagName.toUpperCase() !== 'DIV') if (!e.target.dataset.fontName ||
e.target.tagName.toUpperCase() !== 'DIV') {
return; return;
}
var fontName = e.target.dataset.fontName; var fontName = e.target.dataset.fontName;
var selects = document.getElementsByTagName('input'); var selects = document.getElementsByTagName('input');
for (var i = 0; i < selects.length; ++i) { for (var i = 0; i < selects.length; ++i) {
var select = selects[i]; var select = selects[i];
if (select.dataset.fontName != fontName) continue; if (select.dataset.fontName != fontName) {
continue;
}
select.checked = !select.checked; select.checked = !select.checked;
selectFont(fontName, select.checked); selectFont(fontName, select.checked);
select.scrollIntoView(); select.scrollIntoView();
@ -140,8 +144,9 @@ var FontInspector = (function FontInspectorClosure() {
// Somewhat of a hack, should probably add a hook for when the text layer // Somewhat of a hack, should probably add a hook for when the text layer
// is done rendering. // is done rendering.
setTimeout(function() { setTimeout(function() {
if (this.active) if (this.active) {
resetSelection(); resetSelection();
}
}.bind(this), 2000); }.bind(this), 2000);
} }
}; };
@ -172,8 +177,9 @@ var StepperManager = (function StepperManagerClosure() {
stepperDiv = document.createElement('div'); stepperDiv = document.createElement('div');
this.panel.appendChild(stepperControls); this.panel.appendChild(stepperControls);
this.panel.appendChild(stepperDiv); this.panel.appendChild(stepperDiv);
if (sessionStorage.getItem('pdfjsBreakPoints')) if (sessionStorage.getItem('pdfjsBreakPoints')) {
breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints')); breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints'));
}
}, },
enabled: false, enabled: false,
active: false, active: false,
@ -191,19 +197,22 @@ var StepperManager = (function StepperManagerClosure() {
var initBreakPoints = breakPoints[pageIndex] || []; var initBreakPoints = breakPoints[pageIndex] || [];
var stepper = new Stepper(debug, pageIndex, initBreakPoints); var stepper = new Stepper(debug, pageIndex, initBreakPoints);
steppers.push(stepper); steppers.push(stepper);
if (steppers.length === 1) if (steppers.length === 1) {
this.selectStepper(pageIndex, false); this.selectStepper(pageIndex, false);
}
return stepper; return stepper;
}, },
selectStepper: function selectStepper(pageIndex, selectPanel) { selectStepper: function selectStepper(pageIndex, selectPanel) {
if (selectPanel) if (selectPanel) {
this.manager.selectPanel(1); this.manager.selectPanel(1);
}
for (var i = 0; i < steppers.length; ++i) { for (var i = 0; i < steppers.length; ++i) {
var stepper = steppers[i]; var stepper = steppers[i];
if (stepper.pageIndex == pageIndex) if (stepper.pageIndex == pageIndex) {
stepper.panel.removeAttribute('hidden'); stepper.panel.removeAttribute('hidden');
else } else {
stepper.panel.setAttribute('hidden', true); stepper.panel.setAttribute('hidden', true);
}
} }
var options = stepperChooser.options; var options = stepperChooser.options;
for (var i = 0; i < options.length; ++i) { for (var i = 0; i < options.length; ++i) {
@ -223,8 +232,9 @@ var Stepper = (function StepperClosure() {
// Shorter way to create element and optionally set textContent. // Shorter way to create element and optionally set textContent.
function c(tag, textContent) { function c(tag, textContent) {
var d = document.createElement(tag); var d = document.createElement(tag);
if (textContent) if (textContent) {
d.textContent = textContent; d.textContent = textContent;
}
return d; return d;
} }
@ -297,10 +307,11 @@ var Stepper = (function StepperClosure() {
cbox.checked = checked; cbox.checked = checked;
cbox.onclick = (function(x) { cbox.onclick = (function(x) {
return function() { return function() {
if (this.checked) if (this.checked) {
self.breakPoints.push(x); self.breakPoints.push(x);
else } else {
self.breakPoints.splice(self.breakPoints.indexOf(x), 1); self.breakPoints.splice(self.breakPoints.indexOf(x), 1);
}
StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints); StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints);
}; };
})(i); })(i);
@ -336,8 +347,9 @@ var Stepper = (function StepperClosure() {
getNextBreakPoint: function getNextBreakPoint() { getNextBreakPoint: function getNextBreakPoint() {
this.breakPoints.sort(function(a, b) { return a - b; }); this.breakPoints.sort(function(a, b) { return a - b; });
for (var i = 0; i < this.breakPoints.length; i++) { for (var i = 0; i < this.breakPoints.length; i++) {
if (this.breakPoints[i] > this.currentIdx) if (this.breakPoints[i] > this.currentIdx) {
return this.breakPoints[i]; return this.breakPoints[i];
}
} }
return null; return null;
}, },
@ -385,13 +397,16 @@ var Stepper = (function StepperClosure() {
var Stats = (function Stats() { var Stats = (function Stats() {
var stats = []; var stats = [];
function clear(node) { function clear(node) {
while (node.hasChildNodes()) while (node.hasChildNodes()) {
node.removeChild(node.lastChild); node.removeChild(node.lastChild);
}
} }
function getStatIndex(pageNumber) { function getStatIndex(pageNumber) {
for (var i = 0, ii = stats.length; i < ii; ++i) for (var i = 0, ii = stats.length; i < ii; ++i) {
if (stats[i].pageNumber === pageNumber) if (stats[i].pageNumber === pageNumber) {
return i; return i;
}
}
return false; return false;
} }
return { return {
@ -408,8 +423,9 @@ var Stats = (function Stats() {
active: false, active: false,
// Stats specific functions. // Stats specific functions.
add: function(pageNumber, stat) { add: function(pageNumber, stat) {
if (!stat) if (!stat) {
return; return;
}
var statsIndex = getStatIndex(pageNumber); var statsIndex = getStatIndex(pageNumber);
if (statsIndex !== false) { if (statsIndex !== false) {
var b = stats[statsIndex]; var b = stats[statsIndex];
@ -428,8 +444,9 @@ var Stats = (function Stats() {
stats.push({ pageNumber: pageNumber, div: wrapper }); stats.push({ pageNumber: pageNumber, div: wrapper });
stats.sort(function(a, b) { return a.pageNumber - b.pageNumber; }); stats.sort(function(a, b) { return a.pageNumber - b.pageNumber; });
clear(this.panel); clear(this.panel);
for (var i = 0, ii = stats.length; i < ii; ++i) for (var i = 0, ii = stats.length; i < ii; ++i) {
this.panel.appendChild(stats[i].div); this.panel.appendChild(stats[i].div);
}
} }
}; };
})(); })();
@ -448,12 +465,14 @@ var PDFBug = (function PDFBugClosure() {
], ],
enable: function(ids) { enable: function(ids) {
var all = false, tools = this.tools; var all = false, tools = this.tools;
if (ids.length === 1 && ids[0] === 'all') if (ids.length === 1 && ids[0] === 'all') {
all = true; all = true;
}
for (var i = 0; i < tools.length; ++i) { for (var i = 0; i < tools.length; ++i) {
var tool = tools[i]; var tool = tools[i];
if (all || ids.indexOf(tool.id) !== -1) if (all || ids.indexOf(tool.id) !== -1) {
tool.enabled = true; tool.enabled = true;
}
} }
if (!all) { if (!all) {
// Sort the tools by the order they are enabled. // Sort the tools by the order they are enabled.
@ -509,19 +528,21 @@ var PDFBug = (function PDFBugClosure() {
panels.appendChild(panel); panels.appendChild(panel);
tool.panel = panel; tool.panel = panel;
tool.manager = this; tool.manager = this;
if (tool.enabled) if (tool.enabled) {
tool.init(); tool.init();
else } else {
panel.textContent = tool.name + ' is disabled. To enable add ' + panel.textContent = tool.name + ' is disabled. To enable add ' +
' "' + tool.id + '" to the pdfBug parameter ' + ' "' + tool.id + '" to the pdfBug parameter ' +
'and refresh (seperate multiple by commas).'; 'and refresh (seperate multiple by commas).';
}
buttons.push(panelButton); buttons.push(panelButton);
} }
this.selectPanel(0); this.selectPanel(0);
}, },
selectPanel: function selectPanel(index) { selectPanel: function selectPanel(index) {
if (index === activePanel) if (index === activePanel) {
return; return;
}
activePanel = index; activePanel = index;
var tools = this.tools; var tools = this.tools;
for (var j = 0; j < tools.length; ++j) { for (var j = 0; j < tools.length; ++j) {