beautypg.com

Write the javascript code, Stand-alone reports – Adobe Extending Dreamweaver CS4 User Manual

Page 201

background image

195

EXTENDING DREAMWEAVER CS4

Reports

Write the JavaScript code

Dreamweaver includes the Reports.js file. You can call any of the functions in Reports.js. However, you also have to
create the JavaScript file that contains any functions that are specific to your custom site report.

1

Create the file Configuration/Reports/HTML Reports/List Images.js, with the following content:

// Function: configureSettings

// Description: Standard report API, used to initialize and load
//the default values. Does not initialize the UI.
//
function configureSettings() {

return false;

}
// Function: processFile
// Description: Report command API called during file processing.
//
function processFile (fileURL) {

if (!isHTMLType(fileURL)) //If the file isn't an HTML file

return;

//skip it.

var curDOM = dw.getDocumentDOM(fileURL);

// Variable for DOM

var tagList = curDOM.getElementsByTagName('img'); // Variable for img tags
var imgfilename; // Variable for file name specified in img tag
for (var i=0; i < tagList.length; i++) { // For img tag list

imgfilename = tagList[i].getAttribute('src'); // Get image filename
if (imgfilename != null) { // If a filename is specified
// Print the appropriate icon, HTML filename,
// image filename, and line number

reportItem(REP_ITEM_CUSTOM, fileURL, imgfilename,

curDOM.nodeToSourceViewOffsets(tagList[i])); }

}

}

2

Save the file as List Images.js in the Configuration/Reports/HTML Reports folder.

Stand-alone reports

You can use the results window API to create a stand-alone report. Stand-alone reports are regular commands that
directly use the results window API rather than the reports API. You can access a stand-alone report the same way you
access any other command, through the menus or through another command.

Stand-alone reports reside in the Dreamweaver Configuration/Commands folder. A custom command for a stand-
alone report appears on the Commands menu.

Dreamweaver creates a new Results window each time the user runs a new stand-alone report.

Path

File

Description

Configuration/Commands

commandname.htm

Defines the UI for the dialog box that appears
when the user selects the command and
contains the JavaScript code or a reference to
the JavaScript file that performs the actions
needed to generate the report.

Configuration/Commands

commandname.js

Generates a Results window and puts the
report in it.

This manual is related to the following products: