JavaScript: image click in dialog isn't executed anymore

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

benep
User
Posts: 15
Joined: Thu Dec 08, 2022 7:14 am

JavaScript: image click in dialog isn't executed anymore

Post by benep »

Hello,

in previous versions it was possible to call a function when an image in a dialog got clicked, see the example below.
I can't reconstruct in which version it did stop working. I am pretty sure it did still work in build 10.3.1.387.

Code: Select all

// to execute paste for example in javascript console
{
// function to create icon data
const getIcon = (hex) => {
    return {
        count: 0,
        width: 64,
        height: 64,
        read: function(nBytes) {
            return hex.slice(this.count, this.count += nBytes);
        }
    }
};

// test image data (blue square)
const blueImgHex = 'ff0000ff'.repeat(64*64);

// dialog
const dialog = {
    initialize: function(dlg) {
        dlg.load({img1: getIcon(blueImgHex)}); // initialize img1 with image data
    },
    description: {
        name: 'Test', elements: [
            { type: 'image', item_id: 'img1', height: 64, width: 64 } // define image element
        ]
    },
    img1: function(dlg) {
        // this did execute before, when element img1 was clicked, but it doesn't in
        // xce version 10.5.2 build 395 
        console.println('image clicked');
        // expected behaviour is a console output when the image is clicked
        // currently nothing happens
    }
};

// show the dialog
app.execDialog(dialog);

}
Can you please look into this. Thank you!

Kind regards
benep
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11263
Joined: Wed Jan 03, 2018 6:52 pm

Re: JavaScript: image click in dialog isn't executed anymore

Post by Daniel - PDF-XChange »

Hello, benep

On investigation, this seems to have changed between build 393 and 394. I am unsure as to why, since I cannot see any JS changes that should be relevant to your script, but I will be escalating it to the Dev team for review in our next meeting.

In the meantime, If you need to use this functionality, you can find the build 393 installer (Or portable version) for download on our previous builds page while signed into your account, here:
https://www.pdf-xchange.com/version/pdf-xchange-editor

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 601
Joined: Thu Jun 19, 2014 7:30 pm

Re: JavaScript: image click in dialog isn't executed anymore

Post by Mathew »

This is one of the non-documented features of dialog that would be super useful. My current very klunky workaround: add a button next to it :roll: .

It does work in Acrobat, btw:
image.png
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11263
Joined: Wed Jan 03, 2018 6:52 pm

Re: JavaScript: image click in dialog isn't executed anymore

Post by Daniel - PDF-XChange »

Hello, Mathew

Hopefully that workaround wont be necessary for long. As it did work in the past, I would assume we will be fixing the issue that causes this, unless there is some clear security risk reason that it was disabled.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11263
Joined: Wed Jan 03, 2018 6:52 pm

Re: JavaScript: image click in dialog isn't executed anymore

Post by Daniel - PDF-XChange »

Hello, Once again

It seems I spoke too soon. That workaround will be required going forward.

Image elements are not intended to fire events in JS Dlg's and as such that capability was intentionally removed as it is a security risk.
I am sorry to say that it will not be returning for the foreseeable future.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 601
Joined: Thu Jun 19, 2014 7:30 pm

Re: JavaScript: image click in dialog isn't executed anymore

Post by Mathew »

I don't know what to say :shock: I guess I'm disappointed: This was one of the best 'easter eggs' I've stumbled on. Based on the only information I could find on the web - it was intended to fire events, but was never part of the tab order, so didn't play well with accessibility.
benep
User
Posts: 15
Joined: Thu Dec 08, 2022 7:14 am

Re: JavaScript: image click in dialog isn't executed anymore

Post by benep »

The API (https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#execdialog) states, that the dialog box handler is called, whenever the item with ItemID is "modified":
Called when the dialog box element ItemID is modified. For a text box, it is when the text box loses focus. For other controls, it is when the selection changes. If ItemID is not a JavaScript identifier, the name must be enclosed in double quotes when the method is defined, as in the example below
So an image element did work like a button element, which is also not stated directly within the API, but you can click on it nonetheless.
The image element itslef is not listed in the "type" property within the API, however pdfxce is still supporting the image element/type itself and did only remove the call to the handler.

I have whole custom UI elements built on top of image elements which can't be replaced equivalently with a simple button. As far as I know there is no other option to display an image you can interact with. This makes some scripts of mine basically unusable, at least regarding the user experience.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: JavaScript: image click in dialog isn't executed anymore

Post by Stefan - PDF-XChange »

Hello benep,

I presume that technically you can place the image and a link object on top of it, and that Link object can then fire the JS.
It will still appear like "clickable image" to the end users, but would indeed likely be more work to set the file up initially.

Kind regards,
Stefan
Mathew
User
Posts: 601
Joined: Thu Jun 19, 2014 7:30 pm

Re: JavaScript: image click in dialog isn't executed anymore

Post by Mathew »

so I assume a feature request to reinstate it would get rejected?

how about a feature request to have a means to put an image into a button in a dialog? Because image click is accepted by other pdf viewers, this would be a unique PXE feature, though.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: JavaScript: image click in dialog isn't executed anymore

Post by Stefan - PDF-XChange »

Hello Mathew,

I will ask our devs to take a look at this once again and advise. I can not make any promises at this time, but it is already with the devs and awaiting their follow up!

Kind regards,
Stefan
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: JavaScript: image click in dialog isn't executed anymore

Post by Stefan - PDF-XChange »

Hello again Mathew,

Just heard back from the devs that this will be changed in V10.6.0.x - I do not have a release date for that version yet - but it will be there as it's already fixed according to our dev team.

Kind regards,
Stefan
Mathew
User
Posts: 601
Joined: Thu Jun 19, 2014 7:30 pm

Re: JavaScript: image click in dialog isn't executed anymore

Post by Mathew »

:D
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11263
Joined: Wed Jan 03, 2018 6:52 pm

JavaScript: image click in dialog isn't executed anymore

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com