-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow outline to be collapsed / shown via +/-. #6242
Conversation
Funtionality-wise this appears to be the same as #3753, but code-wise it looks much cleaner to me. Also, that previous PR has not been touched for a while. Some initial feedback: I do think the +/- signs should be the same color as the text (white) to make them stand out, as they are currently not very visible. @Snuffleupagus What do you think? Is there funtionality in your PR that this PR does not have? |
I suggested something similar in PR #3753, but I don't think that consensus was reached regarding if we wanted this feature or not (which is why I stopped working on it). |
I think it is a useful feature (as I have also been working with the spec a lot lately and this was bothering me too), from #3753 (comment) I sense that @brendandahl likes the idea and there was someone else in that PR that wanted it. Now @Rob--W would like to have it too. Only @yurydelendik was unsure about the feature. |
1c74aea
to
b3fb8b4
Compare
@timvandermeij I've added a grey-ish color to the +/- (actually, white with 50% transparency). |
Yes, it looks much better this way. I also like how the subitems are highlighted when you hover over the +/- sign, and how this is done with pure CSS and no images. A few additional remarks:
Aside from that I really like this PR. I will play with it more the coming days. Edit: I would also increase the size of the +/- sign somewhat to make it easier to recognize and to be able to click it more easily. |
_addToggleButton: function PDFOutlineView_addToggleButton(div) { | ||
var toggler = document.createElement('div'); | ||
toggler.className = 'outlineItemToggler'; | ||
toggler.onclick = function(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use toggler.addEventListener('click', function() { ... });
here as we use addEventListener
almost everywhere in the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost everywhere, except in this file:
pdf.js/web/pdf_outline_view.js
Line 66 in 8623421
element.onclick = function goToDestination(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we can keep it as-is then to at least keep it consistent with that file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more examples, so I think this is fine; see e.g.
I've just closed PR #3753, since I think that this one is probably a lot more likely to be accepted. A couple of questions/ideas:
html[dir='ltr'] .outlineItem > a {
- padding: 2px 0 5px 10px;
+ padding: 2px 0 5px 5px;
} |
The + / - and getting a different color upon hover offers enough affordance in my opinion. I intentionally used a cursor different from the link, so that it's easier to notice that you're no longer hovering over the link.
I do want an option to toggle the whole tree, since clicking on the items one by one is a bit clumsy. In UX, double-clicking is often used to be a stronger version of the single-click. Clicking once shows the outline, and clicking again does nothing at the moment. That's why I used double-click, it shows the outline again (fully expands outline) or collapses the outline (when you double-click again).
After merging, I plan on adding documentation to the wiki (https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#user-content-what-are-the-pdfjs-keyboard-shortcuts), so it'll be discoverable by users. None of the current shortcuts are discoverable from the UI, so if we're going to e.g. change the tooltip to add the shortcut, then we'd better do that for every item. @Snuffleupagus & @timvandermeij I'll play with the styles and follow up soon. |
Actually, those are some really good points! The functionality and the choices that inspired it are fine then, as long as we document them properly in the wiki. What remains for me then is to make the click area larger because I find that I often need to click twice because the signs are small, but that will probably be fixed automatically if you increase the size of the signs. Nice work. I'm curious to see where this is going. |
@timvandermeij The icon (although not clearly visible as such) is currently 15x15 pixels. Do you think that this needs to be bigger? Edit: I personally think that a bit larger is better than 15x15. |
b3fb8b4
to
e9d6d63
Compare
Updated PR with bigger icons and smaller padding. WDYT? diff --git a/web/viewer.css b/web/viewer.css
index 6091c94..875ff36 100644
--- a/web/viewer.css
+++ b/web/viewer.css
@@ -1223,7 +1223,7 @@ html[dir='rtl'] .outlineItem > .outlineItems {
}
html[dir='ltr'] .outlineItem > a {
- padding: 2px 0 5px 10px;
+ padding: 2px 0 5px 4px;
}
html[dir='ltr'] .attachmentsItem > button {
padding: 2px 0 3px 7px;
@@ -1231,7 +1231,7 @@ html[dir='ltr'] .attachmentsItem > button {
}
html[dir='rtl'] .outlineItem > a {
- padding: 2px 10px 5px 0;
+ padding: 2px 4px 5px 0;
}
html[dir='rtl'] .attachmentsItem > button {
padding: 2px 7px 3px 0;
@@ -1246,10 +1246,14 @@ html[dir='rtl'] .attachmentsItem > button {
}
.outlineItemToggler::before {
display: block;
- content: '-';
+ content: '\02012'; /* figure dash */
position: absolute;
- width: 15px;
- height: 15px;
+ width: 20px;
+ height: 20px;
+ line-height: 20px;
+ text-align: center;
+ font-size: 18px;
+ font-weight: bold;
}
.outlineItemToggler.outlineItemsHidden::before {
content: '+'; |
@Snuffleupagus The left margin is already 20px, so having a 20px wide button won't cause a loss in estate. |
e9d6d63
to
605f1e5
Compare
@Snuffleupagus I've picked a different pairs of (matching) (unicode) characters. How does that look? |
That actually looks worse than the previous version, i.e. #6242 (comment) and #6242 (comment), see: The only thing "wrong" with the previous version was the vertical placement of the +/-. Would just reducing the |
@Snuffleupagus What part "looks worse"? The horizontal line is correctly aligned, isn't it? If the icon is too big, we can decrease its font size. The line height is chosen to be equal to the height, so that the glyph is vertically centered. The appearance is up to the font designer and font renderer, but I think that it's easier to get consistent and reliable results with the new unicode fonts (HEAVY MINUS SIGN & HEAVY PLUS SIGN) than the previous options (FIGURE DASH and PLUS). |
I was referring to the "huge" size of the icons. Sorry, I should have been more clear! |
605f1e5
to
ba96b5f
Compare
@Snuffleupagus I adjusted the font size. Take another look ;) |
_toggleOutlineItem: function PDFOutlineView_toggleOutlineItem(root, show) { | ||
this.lastToggleIsShow = show; | ||
var togglers = root.querySelectorAll('.outlineItemToggler'); | ||
for (var i = 0; i < togglers.length; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: cache togglers.length
, e.g.
for (var i = 0, ii = togglers.length; i < ii; ++i) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Just out of curiousity, why did you want this change? If mainly for consistency with the code base, then I agree. If for performance, then I don't (introducing an extra variable for the length of a non-live NodeList is not going to have any measurable impact on the performance.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that caching might have helped in older browsers, which is probably why we use it even though it's not really necessary today.
Considering that we currently use this pattern "everywhere" in the code-base, consistency is nice :)
ba96b5f
to
b96f0f3
Compare
@Snuffleupagus I've removed the bold font weight, and also increased the font size from 13 to 15px to avoid the appearance of a too tiny icon. |
With these new characters and styles it looks a lot better. The icons are still quite large for me, and with the developer tools I have found that a font size of 11px seems the most reasonable to me. It currently looks like https://cloud.githubusercontent.com/assets/2692120/8820162/503cd984-3053-11e5-88a6-bd139a94305c.png for me, only without the bold style. They should be smaller in my opinion and 11px makes them look just big enough to click, yet not too invasive. |
@timvandermeij It depends on the font, I guess. Here's how the +/- looks to me (Chromium, Linux). Top = 15px, bottom = 11px. What about 13px? That's the font size of the label next to the +/-. In the short term, a +/- might do, but perhaps it's better to ask Stephen Horlander for expand/collapse icons (side note, we already have +/- icons for zoom in/out.). |
Yes, it seems to depend on the font. Let's do |
b96f0f3
to
b5eb839
Compare
Also, if you e-mail Stephen, remember to ask for @2x assets too, as those are used for hidpi screens. See https://github.com/mozilla/pdf.js/tree/master/web/images for examples. |
@timvandermeij I've switched from 15px to 13px in the latest version of the PR. Why don't we use SVG instead of PNG for the images? That looks good on any screen, at any zoom level. |
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/d7e21587254eaaa/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/d7e21587254eaaa/output.txt Total script time: 0.63 mins Published |
@Rob--W That would be ideal, but that has to be done in a follow-up PR as all icons would have to be remade in SVG format by the UX team. I'll ask the UX team on IRC what they think about this PR and whether or not we should use icons, and if they can provide those. That might be easier than e-mailing. |
I haven't received an icon from anyone. On IRC someone (@brendandahl or @yurydelendik, I don't remember) suggested to use triangles (like Firefox's devtools). Which icon shall we pick? |
You can ping shorlander on irc.mozilla.org at #ux. IIRC, he has been working on those icons and also thought about using triangles. |
b5eb839
to
105b55f
Compare
Thanks for the icons @shorlander. I have updated the PR to use the given icons instead of +/-. |
- This commit adds a '>' before every outline item that has subitems. - Click on the '>' to collapse all subitems under that item (which turns the '>' in a 'v'). - Shift + click expands/collapses all descendant items under that tree. - Double-clicking on the "Show Document Outline" button in the toolbar expands/collapses all outline items.
105b55f
to
7c99224
Compare
@yurydelendik Could you review and merge this PR? See the initial message for the functionality (read "+" / "-" as "expand-icon" / "collapse-icon"). @timvandermeij and @Snuffleupagus are definitely positive towards this feature, and we have icons from shorlander. I guess that the PR can be merged if your concerns have been resolved (#3753 (comment)). Once merged, I will add documentation to the wiki. |
/botio-windows preview |
From: Bot.io (Windows)ReceivedCommand cmd_preview from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/2de28aa9aed49f7/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/2de28aa9aed49f7/output.txt Total script time: 1.07 mins Published |
Allow outline to be collapsed / shown via +/-.
Thank you for the patch. |
I was trying to navigating through a PDF with a huge outline (http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf), and needed a way to toggle a subtree under an outline item. Unfortunately this feature was not yet available, so I decided to implement it.
To test: Preview this PR and check whether the four listed features works for the given PDF file. And for a good measure, double-clicking on the "Show Document Outline" button does nothing for a document without an outline (no errors, just nothing).