Conditional Javascript

This forum is for Single-Sourcing your Flare content to multiple outputs.
Post Reply
JasonSTI
Sr. Propeller Head
Posts: 112
Joined: Mon Jan 07, 2008 11:34 am

Conditional Javascript

Post by JasonSTI »

We have a bit of javascript in the head of each of our topics (being compiled into HTML Help/CHMs). This is used for adding additional functionality, and contains links to other topics that are called in a uniform way. However, we are working on multiple versions of the release within one project, so the links on a couple of topics have changed. I assumed that I could conditionalize the javascript block so it works one way in the existing version, and another way in the new version (these conditions are already working for the new text in the topic). That does not seem to be the case, however. Both are being included (per View Source after the build), and the second one is being used. We could have sworn this was working earlier this month, but fails now.

Can conditions not be applied to scripts at all, or is it just an issue with conditions in the head instead of in the body? Here is what I tried:

Code: Select all

  <head>
    <script type="text/javascript" MadCap:conditions="Version Control.OldVersion">
    //my script
    </script>
    <script type="text/javascript" MadCap:conditions="Version Control.NewVersion">
    //my script
    </script>
  </head>
We are using both Flare 6 and 7, depending on the workstation, both with the latest updates. Same issue on both.
crdmerge
Sr. Propeller Head
Posts: 248
Joined: Tue Dec 16, 2008 5:37 am

Re: Conditional Javascript

Post by crdmerge »

The Flare help doesn't specifically say not to use spaces, in either the Tag Set or Tag names, but all of their examples are single terms with camel case. So I guess I'd try renaming the "Version Control" tag set to "VersionControl" to see what happens. (I've always followed that naming format for snippets, variables, tags, etc., because most HATs tend to gag on encountering spaces in these entities' file names.)


Good luck,
Leon
JasonSTI
Sr. Propeller Head
Posts: 112
Joined: Mon Jan 07, 2008 11:34 am

Re: Conditional Javascript

Post by JasonSTI »

I tried this in a copy of the project and it still doesn't work for the script tags in the head, but works for other elements in the body. It has to be something related to either script tags or the head location. I'm going to try moving the script into the body (yuk) and see how that works.
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: Conditional Javascript

Post by LTinker68 »

Is it the same Javascript from page to page? What about using multiple masterpages? One masterpage contains the Javascript and is used with TargetA. One masterpage is identical to the first but doesn't include the Javascript and is used with TargetB. It might get a bit trickier if you have to explicitly call the code from an event in the body of the topic. Do you, or does the code run automatically without requiring a user-initiated event handler?
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
JasonSTI
Sr. Propeller Head
Posts: 112
Joined: Mon Jan 07, 2008 11:34 am

Re: Conditional Javascript

Post by JasonSTI »

The code in each page are basically identifiers unique to that page. We have four sets of variables that are initialized in a JS file, and are called as part of other functions when certain buttons are pressed (onclick events). Since each page can have any, all, or none of these set, each needs to be defined per topic. So, yes, they are called from an event in the topic body.

We don't use masterpages at this point; in our next revision, we might look at that, but it was much easier during the conversion from HLP to CHM to replace the mass of variables with a much simpler set of variables. It would take weeks to rewrite it completely, but that may end up being what happens. But not today.

Hopefully the overnight build with the script in the body resolves the issue. I should be able to do a find/replace to move all of the scripts when we split the project for the next version. Its just too much work to do mass changes like that while under source control. Luckily, we are doing that in the next couple of months, and moving to Subversion, which will make all of this easier.

Thanks for the suggestions!
JasonSTI
Sr. Propeller Head
Posts: 112
Joined: Mon Jan 07, 2008 11:34 am

Re: Conditional Javascript

Post by JasonSTI »

It does conditionalize the script if it is in the body, and I've noticed that other objects in the head also do not conditionalize (the title tag, for example), so its definitely something about the location of the tag. I've submitted a bug for this, but in the mean time we will need to move conditional scripts out of the head and into the body. Just an FYI for anyone else who runs into this issue.
Post Reply