Drupalist

Javascript

How to tell Ads from Photos and other Images

When I was a child my great Aunt Cornelia gave me a copy of Robert Williams Wood's How to tell the Birds from the Flowers: And Other Woodcuts. The joke behind every poem and illustration is the same - you can't. Check out Amazon's cover shot to see that a Pansy looks very much like a Chim-pansy, for example. In writing the package of JavaScripts that parses the InDesign files for an entire issue of the Boston Review into the files needed to upload all of the issue's content into the new Drupal-based web site I am building for them, I was faced with a very similar question: How do you tell an ad from a photo?.

Modular programming for InDesign JavaScripts using ExtendScript

The focus of the Boston Review is its print edition. So one task in creating their new web site has been creating an automated system for parsing the InDesign files that lay out an issue of the print edition, and creating the files needed to post the entire issue, if they desire, to their new web site.

The best answer to this task is clearly not one huge script, but a collection of smaller scripts that call one another, pass variables, and share one common log file (for my own sanity when debugging). In this article, I list some of the issues I have overcome in setting up such a collection of JavaScript files, rather than one enormous JavaScript, to script InDesign CS2.

Robust File-writing from InDesign JavaScripts

Recently I've been scripting InDesign with JavaScript to parse an entire issue of the print version of the Boston Review and produce the files needed for the new Drupal site I am building for them.

After getting oriented in the Adobe ExtendScript scripting environment, I found that outputting all my debugging print statements to the JavaScript console with $.write() was really slowing things down. Since I was going to have to write files eventually anyway, I was thrilled to find Dave Saunder's code for logging from InDesign JavaScripts. Using this logging function sped up my code greatly versus writing everything to the console.

Flexibly titled pop-up windows

Here's a tip to add to the previous articles here about pop-up windows. When you invoke a pop-up with Javascript, the window is automatically given a title which is the URL of the page it is viewing. But often one wants a simpler title like, say, "Play audio", instead of the URL of the audio file. What to do?

An easy solution I found was to put the file within its own Javascript IFrame(). That way, the invisible title of the IFrame is the file URL, while the window can have whatever title one sets.

Robust popup links in Drupal 6

Once MIDI files were reliably playing in the browser (see the previous post), the next thing I wanted was to have them play in little popup windows, instead of making a blank new page and playing there. Having to hit the browser's "Back button" after playing any MIDI was not acceptable.

The first way I did this was to put the Javascript code to make the popup window inside the link (with an onclick attribute). The problem with that method is that the link is completely broken when Javascript is not supported. Clearly a new page to play the file is the best option when Javascript is not supported.

So, the question is, how can one get a popup when Javascript is supported, but have the link still go to a new page and load the file when it is not?

Drupal SEO