Skip to content
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

[JS] Hide field borders and buttons (#15053) #15054

Merged
merged 1 commit into from
Jun 17, 2022

Conversation

calixteman
Copy link
Contributor

  • Since the border belongs to the section containing the HTML
    counterpart of an annotation, this section must be hidden when
    a JS action requires it;
  • it wasn't possible to hide a button in using JS.

@calixteman calixteman requested a review from Snuffleupagus June 17, 2022 13:23
@calixteman calixteman linked an issue Jun 17, 2022 that may be closed by this pull request
@@ -570,6 +570,7 @@ class LinkAnnotationElement extends AnnotationElement {
render() {
const { data, linkService } = this;
const link = document.createElement("a");
link.setAttribute("id", data.id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary, since all containers already provide that information in a data-annotation-id attribute and I cannot immediately tell where in this patch (or the tests) this is even being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We "need" it here:

const element = document.getElementById(elementId);

Most of (all?) the actions have an impact on the field's HTML counterpart (e.g. textarea/input for a text field) so it's why I originally decided to use the id: my idea was to directly have the element which will receive the change.
And I think it wasn't so bad.
I added the id on the a just to be consistent with what we've for other containers.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the potentially annoying part of adding ids to these elements is that they become "linkable" through the URL hash in a way that's not supported/intended (see issue #11499 and PR #11503 for some context).

These ids could potentially clash with named destinations, and by adding this to all link elements these issues could very well become more common. I wonder if there's a better way, in general for all annotations, to handle things rather than using ids like this!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least from a JS pov, I think we can get rid of it easily: we could select the section with the correct data-annotation-id which will itself update the correct child.
I wonder if it could have a measurable impact on perf: query selector vs getElementById and then go to the child...
Anyway I played /f1040.pdf#208R (an annotation on the bottom of page 2) and the form is scrolled...

Copy link
Collaborator

@Snuffleupagus Snuffleupagus Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it could have a measurable impact on perf: query selector vs getElementById and then go to the child...

My gut feeling is that query-selector probably is slower in general :-(

Although we're already using that in some parts of the AnnotationLayer-code, see

const elements = div.querySelectorAll(
`[data-annotation-id="${data.id}"]`
);
and
const element = div.querySelector(`[data-annotation-id="${id}"]`);

Anyway I played /f1040.pdf#208R (an annotation on the bottom of page 2) and the form is scrolled...

Which it obviously shouldn't :-)
As mentioned that may cause some trouble if the document has a "named destination" which happens to be called 208R.


Anyway, we obviously don't have to try and fix all of that right now here in this patch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed a bug:
#15056

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me, with the comment addressed and passing tests; thank you!

Comment on lines 1434 to 1436
this._setDefaultPropertiesFromJS(container.lastChild);

container.lastChild.addEventListener("updatefromsandbox", jsEvent => {
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it a bit clearer which element this actually references, how about something like the following (assuming that I'm understanding the code correctly)?

Suggested change
this._setDefaultPropertiesFromJS(container.lastChild);
container.lastChild.addEventListener("updatefromsandbox", jsEvent => {
const linkElement = container.lastChild;
this._setDefaultPropertiesFromJS(linkElement);
linkElement.addEventListener("updatefromsandbox", jsEvent => {

- Since the border belongs to the section containing the HTML
  counterpart of an annotation, this section must be hidden when
  a JS action requires it;
- it wasn't possible to hide a button in using JS.
@calixteman
Copy link
Contributor Author

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_unittest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/f6d856d940d93d1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/b907c49ad0f2a8c/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/b907c49ad0f2a8c/output.txt

Total script time: 3.21 mins

  • Unit Tests: FAILED

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/f6d856d940d93d1/output.txt

Total script time: 6.47 mins

  • Unit Tests: Passed

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/ab86d80632acccf/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/53d4ed3ef1a1a1f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/ab86d80632acccf/output.txt

Total script time: 4.49 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/53d4ed3ef1a1a1f/output.txt

Total script time: 7.73 mins

  • Integration Tests: Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Acrobat JavaScript Bugs related with Forms
3 participants