receiveArguments()

Adobe Dreamweaver calls the receiveArguments() function to let the command process any arguments that pass from the menu item. For the Preview in Browsers menu, the receiveArguments() function invokes the browser that the user selects. The receiveArguments() function looks like the following example:

function receiveArguments(){ var whichBrowser = arguments[0]; var theBrowser = null; var i=0; var browserList = null; var result = false; if (havePreviewTarget()) { // Code to check if we were called from a shortcut key if (whichBrowser == 'primary' || whichBrowser == 'secondary') { // get the path of the selected browser if (whichBrowser == 'primary') { theBrowser = dw.getPrimaryBrowser(); } else if (whichBrowser == 'secondary') { theBrowser = dw.getSecondaryBrowser(); } // Match the path with the name of the corresponding browser // that appears in the menu. browserList = dw.getBrowserList(); while(i < browserList.length) { if (browserList[i+1] == theBrowser) theBrowser = browserList[i]; i+=2; } } else theBrowser = whichBrowser; // Only launch the browser if we have a valid browser selected. if (theBrowser != "file:///" && typeof(theBrowser) != "undefined" && theBrowser.length > 0) { if (dw.getFocus(true) == 'site') { // Only get the first item of the selection because // browseDocument() can't take an array. //dw.browseDocument(site.getSelection()[0],theBrowser); site.browseDocument(theBrowser); } else dw.browseDocument(dw.getDocumentPath('document'),theBrowser); } else { // Otherwise, F12 or Ctrl+F12 was pressed, ask if the user wants // to specify a primary or secondary browser now. if (whichBrowser == 'primary') { result = window.confirm(MSG_NoPrimaryBrowserDefined); } else if (whichBrowser == 'secondary') { result = window.confirm(MSG_NoSecondaryBrowserDefined); } // If the user clicked OK, show the prefs dialog with the browser panel. if (result) dw.showPreferencesDialog('browsers'); } }}

The function first sets the variable whichBrowser to the value that Adobe Dreamweaver passes, arguments[0]. Along with setting other default values, the function also sets result to a default value of false.

After variables are initialized, the receiveArguments() function calls the user-defined function havePreviewTarget() and tests the result. If the result of the test is true, the function checks to see if the user selected the primary or secondary browser. If so, the function sets the variable theBrowser to the path of the executable file that starts the browser (dw.getPrimaryBrowser() or dw.getSecondaryBrowser()). The function then performs a loop that examines the list of browsers returned by dw.getBrowsersList(). If the path to a browser in the list matches the path to the primary or secondary browser, the function sets the variable theBrowser to the matching value in browserList. This value contains the name of the browser and the path to the executable file that starts the browser. If havePreviewTarget() returns the value false, the function sets the variable theBrowser to the value of the variable whichBrowser.

Next, the receiveArguments() function tests the variable theBrowser to make sure that it does not begin with a path, that it is not "undefined", and that it has a length greater than 0. If all these conditions are true, and if the Site panel has focus, the receiveArguments() function calls the site.browseDocument() function to invoke the selected browser with the files selected in the Site panel. If the Site panel does not have focus, the receiveArguments() function calls the function dw.browseDocument() and passes it the path of the current document and the value of the variable theBrowser, which specifies the name of the browser with which to open the document.

If the user pressed the shortcut keys (F12 or Ctrl+F12) and no primary or secondary browser has been specified, a dialog box appears to inform the user. If the user clicks OK, the function calls the function dw.showPreferencesDialog() with the browsers argument to let the user specify a browser at that point.