Variable for toolbar Download PDF button HTML5

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
Toko
Propeller Head
Posts: 25
Joined: Thu Jul 05, 2018 3:24 am

Variable for toolbar Download PDF button HTML5

Post by Toko »

My HTML5 output has a "Download PDF" button on the toolbar. I need to have a variable that sets the URL to the PDF on the button per Target.

The place to define this and where it works for static URLs is in the HTML5 skin: Styles tab > Topic group > Download > Event field: window.open("https://abc.com/usermanual.pdf");return false;

The problem is that I have multiple Targets, each has obviously its own PDF.

The easiest solution would be to use a variable in the Event field, and then set the URL in the Target. For example: window.open("<MadCap:variable name="ac_Variables.UrlPDF" />");return false

However, it doesn't work!

Does anyone know the way to achieve this?

Thanks!
NorthEast
Master Propellus Maximus
Posts: 6398
Joined: Mon Mar 05, 2007 8:33 am

Re: Variable for toolbar Download PDF button HTML5

Post by NorthEast »

Toko wrote:My HTML5 output has a "Download PDF" button on the toolbar. I need to have a variable that sets the URL to the PDF on the button per Target.

The place to define this and where it works for static URLs is in the HTML5 skin: Styles tab > Topic group > Download > Event field: window.open("https://abc.com/usermanual.pdf");return false;

The problem is that I have multiple Targets, each has obviously its own PDF.

The easiest solution would be to use a variable in the Event field, and then set the URL in the Target. For example: window.open("<MadCap:variable name="ac_Variables.UrlPDF" />");return false

However, it doesn't work!

Does anyone know the way to achieve this?

Thanks!
AFAIK, you can't use MadCap variables in the toolbar event/click, or inside any piece of javascript.

Normally the skin editor will include a variables button in the places that you can insert them in a skin, but the event/click doesn't have this.
It also doesn't work if you manually insert the variable using the syntax [%=ac_Variables.UrlPDF%]

As a workaround, if you only have one manual per target, you could you could just use a relative link to the PDF like window.open("../Manual.pdf"); and put a file called Manual.pdf in the output folder.
Obviously the downside is that all your manuals will have the same filename.
Toko
Propeller Head
Posts: 25
Joined: Thu Jul 05, 2018 3:24 am

Re: Variable for toolbar Download PDF button HTML5

Post by Toko »

Thanks Dave for your response.

I understand what you are saying.

Actually this is the custom script that the designers original added to the HTML5Tripane skin for the toolbar. I can see where the PDF is called from ("Content/PDFs/' + pdfUr;") but not sure about what the PDF name is - see bold below:

/* Add PDF path to toolbar button */
tidAttempts = 0;
var tid = setInterval(function () {
if (++tidAttempts > 20) clearInterval(tid);

var olhUrl = MadCap.Utilities.Url.GetDocumentUrl().Path;
var mif = $('#toc .tree li:first-child a');
if (!mif.length) return;
var pdfUrl = encodeURI(mif.attr('href').split('/').pop().split('%3F')[0]);

if (!pdfUrl.length) return;
clearInterval(tid);

if (pdfUrl.match(/\.pdf$/i)) {
mif.remove();
var el = document.createElement('A');
el.target="_blank";
el.href =olhUrl + 'Content/PDFs/' + pdfUrl;
$('.download-button img').wrap(el);
} else {
$('.download-button').remove();
}
}, 250);
NorthEast
Master Propellus Maximus
Posts: 6398
Joined: Mon Mar 05, 2007 8:33 am

Re: Variable for toolbar Download PDF button HTML5

Post by NorthEast »

I'd suggest asking whoever wrote your custom script.

I'm not good at javascript and don't understand your code, but it seems to do something like check the TOC for PDF filenames, and use that to create a button(s) linked to the PDF(s):
* It seems to set 'mif' as the link in the TOC menu, then 'pdfUrl' is being set as part of the 'mif' href - presumably the filename.
* It does some sort of check on 'pdfUrl' to see if it contains ".pdf" (?), and if so then it creates a button with a link to the PDF.
Post Reply