Adobe Extending Dreamweaver CS4 User Manual

Page 343

Advertising
background image

337

EXTENDING DREAMWEAVER CS4

Data translators

<html>

<head>
<title>Conditional Translator</title>
<meta http-equiv="Content-Type" content="text/html; charset=">
<script language="JavaScript">

/*************************************************************
* This translator handles the following statement syntaxes: *
* <# if (condition) then foo else bar #> *
* <# if (condition) then att="foo" else att="bar" #> *
* <# if (condition) then att1="foo" att2="jinkies" *
* att3="jeepers" else att1="bar" att2="zoinks" #> *
* *
* It does not handle statements with no else clause. *
*************************************************************/

var count = 1;

function translateMarkup(docNameStr, siteRootStr, inStr){
var count = 1;
// Counter to ensure unique mmTranslatedValues
var outStr = inStr;
// String that will be manipulated
var spacer = "";
// String to manage space between encoded attributes
var start = inStr.indexOf('<# if'); // 1st instance of Pound Conditional code
// Declared but not initalized //
var attAndValue;
// Boolean indicating whether the attribute is part of
// the conditional statement
var trueStart;

// The beginning of the true case
var falseStart;
// The beginning of the false case
var trueValue;

// The HTML that would render in the true case
var attName;

// The name of the attribute that is being
// set conditionally.
var equalSign;

// The position of the equal sign just to the
// left of the <#, if there is one
var transAtt;

// The entire translated attribute
var transValue;
// The value that must be URL-encoded
var back3FromStart;
// Three characters back from the start position
// (used to find equal sign to the left of <#
var tokens;

// An array of all the attributes set in the true case
var end;

// The end of the current conditional statement.
// As long as there's still a <# conditional that hasn't been
// translated.
while (start != -1){

back3FromStart = start-3;

Advertising
This manual is related to the following products: