<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<meta name="generator" content="Adobe GoLive 6" />
		<title>SetTitle Extension</title>
	</head>

	<body>
		<hr />
		<p>ADOBE SYSTEMS INCORPORATED</p>
		<p>Copyright 2002 Adobe Systems Incorporated<br />
			All Rights Reserved</p>
		<p>NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe.</p>
		<hr />
		<p><b>Extension Name:</b> SetTitle</p>
		<p><b>Folder name:</b> SetTitle</p>
		<hr />
		<p><b>Description:</b></p>
		<p>This extension prompts the user to set the title of the document when saving an HTML document.</p>
		<p>A dialog prompts the user to set the title if the title is:</p>
		<ul>
			<li>blank or contains only whitespace</li>
			<li>contains the language localized version of &quot;Welcome to Adobe GoLive&quot;</li>
			<li>contains &quot;Welcome to GoLive CyberStudio&quot;</li>
			<li>is set to &quot;untitled&quot;, &quot;untitled-&lt;n&gt;&quot;, &quot;untitled &lt;n&gt;&quot;. Ignore case and any white space before and after.</li>
		</ul>
		<p>A checkbox allows the user to set the title to the name of the document minus the extension.</p>
		<p>The user may disable the functionality for the remainder of the session and permanently by checking the &quot;Don't remind me again.&quot; checkbox.</p>
		<hr />
		<p><b>Module Definition:</b></p>
		<jsxmodule info="$$$/info=This extension displays an edit title dialog if a user saves a document with a default title." name="SetTitle" version="1.0" /> 
		<p><b>Scripts:</b></p>
		<script><!--
//--------------------------------------------------------------------
// GLOBAL VARIABLES
//--------------------------------------------------------------------

//  global variables 


//--------------------------------------------------------------------
// CALLBACK FUNCTIONS
//--------------------------------------------------------------------

function startModule()
{
	setTitleDlg.addEventListener( 'onShow', function(e){this.children['titleEdit'].active=true;} );
}

//---------------------------------------------------------
// controlSignal -  called when the state of a control has changed
//
// Description:
//   Use to extract the state of the control, and react to the state
//   change.
//
// Warning: see documentation for warnings about reparse, 
//   reformat, setInnerHTML, and setOuterHTML.

function controlSignal(control)
{
	if (control.name == "docNameCheck") {
		setTitleDlg.titleEdit.value = getDocNameMinusExt(document.file.name);
	}
}


//----------------------------------------------------
// onDocEvent - called when GoLive receives an event
//
// Description:
// This event handler is called when GoLive receives
// an event such as document open, new document
// created, document view changed, etc.
//  
// Parameters:
//	doc: the document where the event occurred
//	notification: the event that occurred
//

function docSignal(doc, notification) 
{
	switch (notification) {		
	case "save":
		// if user checked disable, do not prompt user
		if (setTitleDlg.checkDisable.state == true) {
			return;
		}
		
		// When an existing document is opened,
		// if title not set, prompt user to set the Title
		//
		if (doc.type == "markup") {
			if (checkForTitle(doc)) {
				promptForTitle(doc);
			}
		}
		break;
	}
}


//--------------------------------------------------------------------
// add your own functions here
//--------------------------------------------------------------------

//----------------------------------------------------
// checkForTitle
//
// Description:
// This function checks to see if the current title element:
//  1. contains "Welcome to Adobe GoLive"
//  2. contains "Welcome to GoLive CyberStudio"
//  3. is set to "untitled", "untitled-<n>", or "untitled <n>"
//		ignoring case and white space before and after
//  4. is blank or contains only whitespace.
// If so, it returns true.
//
// Parameters:
//    doc: document to act upon

function checkForTitle(doc) 
{
	if( doc.element )
		var titleElt = doc.element.getSubElement("title");
	if (!titleElt) {
		return false;
	}
		
	var returnVal = false;
			
	var titleContents = titleElt.getInnerHTML();
	
    if ((titleContents == "") ||
        (titleContents.indexOf("Welcome to Adobe GoLive") >= 0) ||
        (titleContents.indexOf(module.localize("$$$/welcome1=Welcome to Adobe GoLive")) >= 0) ||
        (titleContents.indexOf("Welcome to GoLive CyberStudio") >= 0) ||
        (titleContents.indexOf(module.localize("$$$/welcome2=Welcome to GoLive CyberStudio")) >= 0) ||
        (titleContents.search(/^\s\s*$/) >= 0))
    {
        returnVal = true;
    }
	else {
		// check for "untitled" and variations
		if (titleContents.search(/^\s*untitled\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*untitled-[0-9]+\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*untitled-[0-9]+\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*untitled page\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*Namnlös sida\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*Unavngivet side\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*Naamloze pagina\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*Pagina senza nome\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*Página sin nombre\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*Unbenannte Seite\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*Page sans titre\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*未标题页面\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*未命名頁面\s*$/i) >= 0) {
			returnVal = true;
		}
		else if (titleContents.search(/^\s*무제 페이지\s*$/i) >= 0) {
			returnVal = true;
		}
	}
	return returnVal;
}	
	

//----------------------------------------------------
// getDocNameMinusExt - 
//
// Description: get document name minus
// the extension. The extension is the last 
// period and any text following the period
//
// Parameters:
//	doc: document to act upon.
		
function getDocNameMinusExt(doc)
{
	var newTitle = '';
	// find the last period and text following period
	var dotLoc = doc.lastIndexOf('.');
	if (dotLoc > 0)
	{
		newTitle = doc.substring(0,dotLoc);
	}
	return newTitle;
}


//----------------------------------------------------
// promptForTitle - prompt user for Title of document
//
// Description:
//   This function prompts the user to change the 
//   title. The current title is displayed in the prompt
//   dialog.
//
// Parameters:
//	doc: document to act upon

function promptForTitle(doc)
{
	var titleElt = doc.element.getSubElement("title");
	if (!titleElt) {
		return;
	}
		
	setTitleDlg.titleEdit.value = titleElt.getInnerHTML();
	setTitleDlg.docNameCheck.state = false;
	if (setTitleDlg.runModal()) {
		titleElt.setInnerHTML(setTitleDlg.titleEdit.value); 
	}
	// turn off this module if user specifies in dialog
	if (setTitleDlg.checkDisable.state == true) {
		module.switchOff();
	}
}
//-->
</script>
		<p><b>Dialogs</b> Define Dialogs here.</p>
		<jsxdialog height="180" name="setTitleDlg" title="$$$/dialog=Set Title" width="328">
			<table width="328" border="0" cellspacing="0" cellpadding="0" cool="cool" gridx="5" gridy="5" height="180" showgridx="yes" showgridy="yes" usegridx="yes" usegridy="yes">
				<tr height="10">
					<td rowspan="7" width="10" height="179"></td>
					<td colspan="4" width="317" height="10"></td>
					<td width="1" height="10"><spacer height="10" type="block" width="1" /></td>
				</tr>
				<tr height="25">
					<td colspan="4" align="left" valign="top" width="317" height="25" xpos="10">
						<jsxcontrol height="16" name="static" posx="10" posy="10" type="static" value="$$$/static1=Note: This document contains a default title." width="300"></jsxcontrol>
					</td>
					<td width="1" height="25"><spacer height="25" type="block" width="1" /></td>
				</tr>
				<tr height="5">
					<td colspan="2" width="125" height="5"></td>
					<td rowspan="2" colspan="2" align="left" valign="top" width="192" height="30" xpos="135">
						<jsxcontrol halign="scale" height="19" name="titleEdit" posx="135" posy="35" type="edit" value="Edit" width="180" enterOK="true"></jsxcontrol>
					</td>
					<td width="1" height="5"><spacer height="5" type="block" width="1" /></td>
				</tr>
				<tr height="25">
					<td colspan="2" align="left" valign="top" width="125" height="25" xpos="10">
						<jsxcontrol height="15" name="static" posx="10" posy="40" type="static" value="$$$/static2=Enter a new title:" width="120"></jsxcontrol>
					</td>
					<td width="1" height="25"><spacer height="25" type="block" width="1" /></td>
				</tr>
				<tr height="30">
					<td colspan="4" align="left" valign="top" width="317" height="30" xpos="10">
						<jsxcontrol height="20" name="docNameCheck" posx="10" posy="65" type="checkbox" value="$$$/checkbox1=Set title to document name" width="300"></jsxcontrol>
					</td>
					<td width="1" height="30"><spacer height="30" type="block" width="1" /></td>
				</tr>
				<tr height="55">
					<td width="69" height="55"></td>
					<td colspan="2" align="left" valign="top" width="88" height="55" xpos="79">
						<jsxcontrol height="19" name="dialogok" posx="79" posy="95" type="button" value="$$$/button1=Set" width="80"></jsxcontrol>
					</td>
					<td align="left" valign="top" width="160" height="55" xpos="167">
						<jsxcontrol height="19" name="dialogcancel" posx="167" posy="95" type="button" value="$$$/button2=Don't Set" width="80"></jsxcontrol>
					</td>
					<td width="1" height="55"><spacer height="55" type="block" width="1" /></td>
				</tr>
				<tr height="29">
					<td colspan="4" align="left" valign="top" width="317" height="29" xpos="10">
						<jsxcontrol height="19" name="checkDisable" posx="10" posy="148" type="checkbox" value="$$$/checkbox2=Don't remind me again." width="300"></jsxcontrol>
					</td>
					<td width="1" height="29"><spacer height="29" type="block" width="1" /></td>
				</tr>
				<tr cntrlrow="cntrlrow" height="1">
					<td width="10" height="1"><spacer height="1" type="block" width="10" /></td>
					<td width="69" height="1"><spacer height="1" type="block" width="69" /></td>
					<td width="56" height="1"><spacer height="1" type="block" width="56" /></td>
					<td width="32" height="1"><spacer height="1" type="block" width="32" /></td>
					<td width="160" height="1"><spacer height="1" type="block" width="160" /></td>
					<td width="1" height="1"></td>
				</tr>
			</table>
			<jsxcontrol height="3" posx="3" posy="130" type="frame" width="322"></jsxcontrol>
			<jsxlayoutline direction="false" x="133" y="35" length="20" />
		</jsxdialog>
	</body>

</html>