Skip to content

Commit

Permalink
Merge pull request #10890 from Snuffleupagus/outline-items-hidden
Browse files Browse the repository at this point in the history
Add support for outline items, in the default viewer, which default to collapsed when the outline is built
  • Loading branch information
timvandermeij authored Jun 9, 2019
2 parents bb540e4 + 26bc630 commit 06b253d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Catalog {
const title = outlineDict.get('Title');
const flags = outlineDict.get('F') || 0;
const color = outlineDict.getArray('C');
const count = outlineDict.get('Count');
let rgbColor = blackColor;

// We only need to parse the color when it's valid, and non-default.
Expand All @@ -159,7 +160,7 @@ class Catalog {
newWindow: data.newWindow,
title: stringToPDFString(title),
color: rgbColor,
count: outlineDict.get('Count'),
count: Number.isInteger(count) ? count : undefined,
bold: !!(flags & 2),
italic: !!(flags & 1),
items: [],
Expand Down
1 change: 1 addition & 0 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ class PDFDocumentProxy {
* bold: boolean,
* italic: boolean,
* color: rgb Uint8ClampedArray,
* count: integer or undefined,
* dest: dest obj,
* url: string,
* items: array of more items like this
Expand Down
16 changes: 10 additions & 6 deletions web/pdf_outline_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ class PDFOutlineViewer {
*
* @private
*/
_addToggleButton(div) {
_addToggleButton(div, { count, items, }) {
let toggler = document.createElement('div');
toggler.className = 'outlineItemToggler';
if (count < 0 && Math.abs(count) === items.length) {
toggler.classList.add('outlineItemsHidden');
}
toggler.onclick = (evt) => {
evt.stopPropagation();
toggler.classList.toggle('outlineItemsHidden');
Expand Down Expand Up @@ -173,10 +176,8 @@ class PDFOutlineViewer {
let queue = [{ parent: fragment, items: this.outline, }];
let hasAnyNesting = false;
while (queue.length > 0) {
let levelData = queue.shift();
for (let i = 0, len = levelData.items.length; i < len; i++) {
let item = levelData.items[i];

const levelData = queue.shift();
for (const item of levelData.items) {
let div = document.createElement('div');
div.className = 'outlineItem';

Expand All @@ -190,7 +191,7 @@ class PDFOutlineViewer {

if (item.items.length > 0) {
hasAnyNesting = true;
this._addToggleButton(div);
this._addToggleButton(div, item);

let itemsDiv = document.createElement('div');
itemsDiv.className = 'outlineItems';
Expand All @@ -204,6 +205,9 @@ class PDFOutlineViewer {
}
if (hasAnyNesting) {
this.container.classList.add('outlineWithDeepNesting');

this.lastToggleIsShow =
(fragment.querySelectorAll('.outlineItemsHidden').length === 0);
}

this.container.appendChild(fragment);
Expand Down

0 comments on commit 06b253d

Please sign in to comment.