Merge pull request #6242 from Rob--W/outline-collapsible
Allow outline to be collapsed / shown via +/-.
This commit is contained in:
commit
70fd360d51
BIN
web/images/treeitem-collapsed.png
Normal file
BIN
web/images/treeitem-collapsed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 125 B |
BIN
web/images/treeitem-collapsed@2x.png
Normal file
BIN
web/images/treeitem-collapsed@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 172 B |
BIN
web/images/treeitem-expanded.png
Normal file
BIN
web/images/treeitem-expanded.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 128 B |
BIN
web/images/treeitem-expanded@2x.png
Normal file
BIN
web/images/treeitem-expanded@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 149 B |
@ -36,6 +36,7 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
|
|||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
this.outline = options.outline;
|
this.outline = options.outline;
|
||||||
this.linkService = options.linkService;
|
this.linkService = options.linkService;
|
||||||
|
this.lastToggleIsShow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFOutlineView.prototype = {
|
PDFOutlineView.prototype = {
|
||||||
@ -44,6 +45,7 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
|
|||||||
while (container.firstChild) {
|
while (container.firstChild) {
|
||||||
container.removeChild(container.firstChild);
|
container.removeChild(container.firstChild);
|
||||||
}
|
}
|
||||||
|
this.lastToggleIsShow = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +71,51 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepend a button before an outline item which allows the user to toggle
|
||||||
|
* the visibility of all outline items at that level.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_addToggleButton: function PDFOutlineView_addToggleButton(div) {
|
||||||
|
var toggler = document.createElement('div');
|
||||||
|
toggler.className = 'outlineItemToggler';
|
||||||
|
toggler.onclick = function(event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
toggler.classList.toggle('outlineItemsHidden');
|
||||||
|
|
||||||
|
if (event.shiftKey) {
|
||||||
|
var shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
|
||||||
|
this._toggleOutlineItem(div, shouldShowAll);
|
||||||
|
}
|
||||||
|
}.bind(this);
|
||||||
|
div.insertBefore(toggler, div.firstChild);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the visibility of the subtree of an outline item.
|
||||||
|
*
|
||||||
|
* @param {Element} root - the root of the outline (sub)tree.
|
||||||
|
* @param {boolean} state - whether to show the outline (sub)tree. If false,
|
||||||
|
* the outline subtree rooted at |root| will be collapsed.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_toggleOutlineItem: function PDFOutlineView_toggleOutlineItem(root, show) {
|
||||||
|
this.lastToggleIsShow = show;
|
||||||
|
var togglers = root.querySelectorAll('.outlineItemToggler');
|
||||||
|
for (var i = 0, ii = togglers.length; i < ii; ++i) {
|
||||||
|
togglers[i].classList[show ? 'remove' : 'add']('outlineItemsHidden');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collapse or expand all subtrees of the outline.
|
||||||
|
*/
|
||||||
|
toggleOutlineTree: function PDFOutlineView_toggleOutlineTree() {
|
||||||
|
this._toggleOutlineItem(this.container, !this.lastToggleIsShow);
|
||||||
|
},
|
||||||
|
|
||||||
render: function PDFOutlineView_render() {
|
render: function PDFOutlineView_render() {
|
||||||
var outline = this.outline;
|
var outline = this.outline;
|
||||||
var outlineCount = 0;
|
var outlineCount = 0;
|
||||||
@ -80,7 +127,9 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var queue = [{ parent: this.container, items: this.outline }];
|
var fragment = document.createDocumentFragment();
|
||||||
|
var queue = [{ parent: fragment, items: this.outline }];
|
||||||
|
var hasAnyNesting = false;
|
||||||
while (queue.length > 0) {
|
while (queue.length > 0) {
|
||||||
var levelData = queue.shift();
|
var levelData = queue.shift();
|
||||||
for (var i = 0, len = levelData.items.length; i < len; i++) {
|
for (var i = 0, len = levelData.items.length; i < len; i++) {
|
||||||
@ -93,6 +142,9 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
|
|||||||
div.appendChild(element);
|
div.appendChild(element);
|
||||||
|
|
||||||
if (item.items.length > 0) {
|
if (item.items.length > 0) {
|
||||||
|
hasAnyNesting = true;
|
||||||
|
this._addToggleButton(div);
|
||||||
|
|
||||||
var itemsDiv = document.createElement('div');
|
var itemsDiv = document.createElement('div');
|
||||||
itemsDiv.className = 'outlineItems';
|
itemsDiv.className = 'outlineItems';
|
||||||
div.appendChild(itemsDiv);
|
div.appendChild(itemsDiv);
|
||||||
@ -103,6 +155,11 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
|
|||||||
outlineCount++;
|
outlineCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (hasAnyNesting) {
|
||||||
|
this.container.classList.add('outlineWithDeepNesting');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.container.appendChild(fragment);
|
||||||
|
|
||||||
this._dispatchEvent(outlineCount);
|
this._dispatchEvent(outlineCount);
|
||||||
}
|
}
|
||||||
|
@ -1191,10 +1191,12 @@ a:focus > .thumbnail > .thumbnailSelectionRing,
|
|||||||
padding: 3px 4px 0;
|
padding: 3px 4px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html[dir='ltr'] .outlineWithDeepNesting > .outlineItem,
|
||||||
html[dir='ltr'] .outlineItem > .outlineItems {
|
html[dir='ltr'] .outlineItem > .outlineItems {
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html[dir='rtl'] .outlineWithDeepNesting > .outlineItem,
|
||||||
html[dir='rtl'] .outlineItem > .outlineItems {
|
html[dir='rtl'] .outlineItem > .outlineItems {
|
||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
}
|
}
|
||||||
@ -1222,7 +1224,7 @@ html[dir='rtl'] .outlineItem > .outlineItems {
|
|||||||
}
|
}
|
||||||
|
|
||||||
html[dir='ltr'] .outlineItem > a {
|
html[dir='ltr'] .outlineItem > a {
|
||||||
padding: 2px 0 5px 10px;
|
padding: 2px 0 5px 4px;
|
||||||
}
|
}
|
||||||
html[dir='ltr'] .attachmentsItem > button {
|
html[dir='ltr'] .attachmentsItem > button {
|
||||||
padding: 2px 0 3px 7px;
|
padding: 2px 0 3px 7px;
|
||||||
@ -1230,13 +1232,46 @@ html[dir='ltr'] .attachmentsItem > button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
html[dir='rtl'] .outlineItem > a {
|
html[dir='rtl'] .outlineItem > a {
|
||||||
padding: 2px 10px 5px 0;
|
padding: 2px 4px 5px 0;
|
||||||
}
|
}
|
||||||
html[dir='rtl'] .attachmentsItem > button {
|
html[dir='rtl'] .attachmentsItem > button {
|
||||||
padding: 2px 7px 3px 0;
|
padding: 2px 7px 3px 0;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.outlineItemToggler {
|
||||||
|
position: relative;
|
||||||
|
height: 0;
|
||||||
|
width: 0;
|
||||||
|
color: hsla(0,0%,100%,.5);
|
||||||
|
}
|
||||||
|
.outlineItemToggler::before {
|
||||||
|
content: url(images/treeitem-collapsed.png);
|
||||||
|
display: inline-block;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
.outlineItemToggler.outlineItemsHidden::before {
|
||||||
|
content: url(images/treeitem-expanded.png);
|
||||||
|
}
|
||||||
|
.outlineItemToggler.outlineItemsHidden ~ .outlineItems {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
html[dir='ltr'] .outlineItemToggler {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
html[dir='rtl'] .outlineItemToggler {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
html[dir='ltr'] .outlineItemToggler::before {
|
||||||
|
right: 4px;
|
||||||
|
}
|
||||||
|
html[dir='rtl'] .outlineItemToggler::before {
|
||||||
|
left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.outlineItemToggler:hover,
|
||||||
|
.outlineItemToggler:hover + a,
|
||||||
|
.outlineItemToggler:hover ~ .outlineItems,
|
||||||
.outlineItem > a:hover,
|
.outlineItem > a:hover,
|
||||||
.attachmentsItem > button:hover {
|
.attachmentsItem > button:hover {
|
||||||
background-color: hsla(0,0%,100%,.02);
|
background-color: hsla(0,0%,100%,.02);
|
||||||
|
@ -1405,6 +1405,11 @@ function webViewerInitialized() {
|
|||||||
PDFViewerApplication.switchSidebarView('outline');
|
PDFViewerApplication.switchSidebarView('outline');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('viewOutline').addEventListener('dblclick',
|
||||||
|
function() {
|
||||||
|
PDFViewerApplication.outline.toggleOutlineTree();
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('viewAttachments').addEventListener('click',
|
document.getElementById('viewAttachments').addEventListener('click',
|
||||||
function() {
|
function() {
|
||||||
PDFViewerApplication.switchSidebarView('attachments');
|
PDFViewerApplication.switchSidebarView('attachments');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user