For the last couple of months, I’ve been tinkering around in Adobe Dreamweaver’s Extension APIs and uncovering alot of hidden or undocumented features in Dreamweaver’s API. This will be my first post in a series regarding the Dreamweaver API. In this post I will be discussing the hidden extension eventhandlers in the Dreamweaver API.
There are three eventhandlers:
- after save event – this is triggered when the changes to a file have been saved.
- before save event – this is triggered before the changes to a file have been saved.
- on open event – this is triggered when Dreamweaver (and when documents) are opened.
You can find the global events in Dreamweaver’s default Commands directory.
Mac: Macintosh HD:Applications:Adobe Dreamweaver CS4:configuration:Commands
Windows: C:\Program Files\Adobe\Adobe Dreamweaver CS4\configuration\Commands
The eventhandler files are:
- _afterSave.htm
- _beforeSave.htm
- _onOpen.htm
To create your own eventhandlers you simple create a prefixed version of the eventhandler command (e.g. alert_afterSave.htm). You can include the necessary JavaScript within <script> tags in your .htm file or you can write a corresponding .js (alert_afterSave.js) file that needs to be included in your .htm file.
I’ve created a very simple example extension that demonstrates how the eventhandlers work. The .mxp installer and source code can be downloaded at the end of this post. The example extension will install into your user account’s application data folder.
Mac: Macintosh HD:Users:<userName>:Library:Application Support:Adobe:Dreamweaver CS4:en_US:Configuration:Commands
Windows: C:\Documents and Settings\<userName>\Application Data\Adobe\Dreamweaver CS4\en_US\Configuration\Commands