havePreviewTarget()
The havePreviewTarget() function is a user-defined function that returns the value true if Adobe Dreamweaver has a valid target to display in the browser. A valid target is a document or a selected group of files in the site panel. The havePreviewTarget() function looks like the following example:
function havePreviewTarget(){ var bHavePreviewTarget = false; if (dw.getFocus(true) == 'site') { if (site.getFocus() == 'remote') { bHavePreviewTarget = site.getRemoteSelection().length > 0 && site.canBrowseDocument(); } else if (site.getFocus() != 'none') { var selFiles = site.getSelection(); if (selFiles.length > 0) { var i; bHavePreviewTarget = true; for (i = 0; i < selFiles.length; i++) { var selFile = selFiles[i]; // For server connections, the files will // already be remote URLs. if (selFile.indexOf("://") == (-1)) { var urlPrefix = "file:///"; var strTemp = selFile.substr(urlPrefix.length); if (selFile.indexOf(urlPrefix) == -1) bHavePreviewTarget = false; else if (strTemp.indexOf("/") == -1) bHavePreviewTarget = false; else if (!DWfile.exists(selFile)) bHavePreviewTarget = false; else if (DWfile.getAttributes(selFile).indexOf("D") != -1) bHavePreviewTarget = false; } else { bHavePreviewTarget = true; } } } } } else if (dw.getFocus() == 'document' || dw.getFocus() == 'textView' || dw.getFocus("true") == 'html' ) { var dom = dw.getDocumentDOM('document'); if (dom != null) { var parseMode = dom.getParseMode(); if (parseMode == 'html' || parseMode == 'xml') bHavePreviewTarget = true; } } return bHavePreviewTarget;}The havePreviewTarget() function sets the value bHavePreviewTarget to false as the default return value. The function performs two basic tests calling the dw.getFocus() function to determine what part of the application currently has input focus. The first test checks whether the site panel has focus (if (dw.getFocus(true) == 'site')). If the site panel does not have focus, the second test checks to see if a document (dw.getFocus() == 'document'), Text view (dw.getFocus() == 'textView'), or the Code inspector (dw.getFocus("true") == 'html') has focus. If neither test is true, the function returns the value false.
If the site panel has focus, the function checks whether the view setting is Remote view. If it is, the function sets bHavePreviewTarget to true if there are remote files (site.getRemoteSelection().length > 0) and the files can be opened in a browser (site.canBrowseDocument()). If the view setting is not Remote view, and if the view is not None, the function gets a list of the selected files (var selFiles = site.getSelection();) in the form of file:/// URLs.
For each item in the selected list, the function tests for the presence of the character string
"://". If it is not found, the code performs a series of tests on the list item. If the item is not in the form of a file:/// URL (if (selFile.indexOf(urlPrefix) == -1)), it sets the return value to false. If the remainder of the string following the file:/// prefix does not contain a slash (/) (if (strTemp.indexOf("/") == -1)), it sets the return value to false. If the file does not exist (else if (!DWfile.exists(selFile))), it sets the return value to false. Last, it checks to see if the specified file is a folder (else if (DWfile.getAttributes(selFile).indexOf("D") != -1)). If selfile is a folder, the function returns the value false. Otherwise, if the target is a file, the function sets bHavePreviewTarget to the value true.
If a document, Text view, or the Code inspector has input focus (else if (dw.getFocus() == 'document' || dw.getFocus() == 'textView' || dw.getFocus("true") == 'html' )), the function gets the DOM and checks to see if the document is an HTML or an XML document. If so, the function sets bHavePreviewTarget to true. Finally, the function returns the value stored in bHavePreviewTarget.