home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Open Browser Window.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  4.4 KB  |  134 lines

  1. // Copyright 1998 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS VARS *****************
  4.  
  5. var helpDoc = MM.HELP_behOpenBrowserWindow;
  6.  
  7. //******************* BEHAVIOR FUNCTION **********************
  8.  
  9. //Opens a new browser windows, with a number of options.
  10. //Accepts the following arguments:
  11. //  theURL   - URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  12. //  winName  - optional name for the window, used to access the window via javascript
  13. //  features - series of window options, none are required. Setting all of them gives:
  14. //                toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,
  15. //                resizable=yes,width=300,height=200
  16. //
  17. //Calls the window.open() method and passes it the desired features.
  18.  
  19. function MM_openBrWindow(theURL,winName,features) { //v2.0
  20.   window.open(theURL,winName,features);
  21. }
  22.  
  23.  
  24. //******************* API **********************
  25.  
  26.  
  27. //Checks to see to which tags or events this behavior applies.
  28. //This behavior can be used with any tag and any event.
  29.  
  30. function canAcceptBehavior(){
  31.   return true;
  32. }
  33.  
  34.  
  35.  
  36. //Returns a Javascript function to be inserted in HTML head with script tags.
  37.  
  38. function behaviorFunction(){
  39.   return "MM_openBrWindow";
  40. }
  41.  
  42.  
  43.  
  44. //Returns the MM_openBrWindow function call and arguments as
  45. //inputted by the user. The function call is inserted in the
  46. //HTML tag after the selected event
  47. //(<TAG...onEvent="functionCall(arg,arg,arg)">).
  48.  
  49. function applyBehavior() {
  50.   var i,theURL,theName,arrayIndex = 0;
  51.   var argArray = new Array; //use array to produce correct number of commas w/o spaces
  52.   var checkBoxNames = new Array("toolbar","location","status","menubar","scrollbars","resizable");
  53.  
  54.   for (i=0; i<checkBoxNames.length; i++) {
  55.     theCheckBox = eval("document.theForm." + checkBoxNames[i]);
  56.     if (theCheckBox.checked) argArray[arrayIndex++] = (checkBoxNames[i] + "=yes");
  57.   }
  58.   if (document.theForm.width.value)
  59.     argArray[arrayIndex++] = ("width=" + document.theForm.width.value);
  60.   if (document.theForm.height.value)
  61.     argArray[arrayIndex++] = ("height=" + document.theForm.height.value);
  62.   theURL = dw.doURLEncoding(document.theForm.URL.value);
  63.   theName = document.theForm.winName.value;
  64.   if (badChars(theName)) return MSG_BadChars;
  65.   else return "MM_openBrWindow('"+theURL+"','"+theName+"','"+argArray.join()+"')";
  66. }
  67.  
  68.  
  69.  
  70. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  71. //call arguments. This information is used by DW to fixup behavior args when the
  72. //document is moved or changed.
  73. //
  74. //It is passed an actual function call string generated by applyBehavior(), which
  75. //may have a variable list of arguments, and this should return a matching mask.
  76. //
  77. //The return values are:
  78. //  URL     : argument could be a file path, which DW will update during Save As...
  79. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  80. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  81. //  other...: argument is ignored
  82.  
  83. function identifyBehaviorArguments(fnCallStr) {
  84.   var argArray;
  85.  
  86.   argArray = extractArgs(fnCallStr);
  87.   if (argArray.length == 4) {
  88.     return "NAV,other,other";
  89.   } else {
  90.     return "";
  91.   }
  92. }
  93.  
  94.  
  95.  
  96. //Upon returning to the Behavior Inspector after applying a behavior,
  97. //inspectBehavior is called. It looks at the user's HTML document,
  98. //extracts the values from the behavior handler, and inserts them into
  99. //the form UI.
  100.  
  101. function inspectBehavior(enteredStr) {
  102.   var i;
  103.   var argArray = extractArgs(enteredStr);
  104.  
  105.   if (argArray.length == 4) {  //first arg is fn name, so ignore that
  106.     document.theForm.URL.value = unescape(argArray[1]);
  107.     document.theForm.winName.value = argArray[2];
  108.     var featuresStr = argArray[3];
  109.     var tokArray = getTokens(featuresStr, "=,");
  110.  
  111.     var checkBoxNames = new Array("toolbar","location","status","menubar","scrollbars","resizable");
  112.     for (i in checkBoxNames) {
  113.       if (featuresStr.indexOf(checkBoxNames[i]) != -1)
  114.         theCheckBox = eval("document.theForm." + checkBoxNames[i] + ".checked = true");
  115.     }
  116.     for (i=0; i < (tokArray.length-1); i++) {
  117.       if (tokArray[i] == "height") document.theForm.height.value = tokArray[i+1];
  118.       if (tokArray[i] == "width")  document.theForm.width.value = tokArray[i+1];
  119.     }
  120.   }
  121. }
  122.  
  123.  
  124.  
  125. //***************** LOCAL FUNCTIONS  ******************
  126.  
  127.  
  128. //Set the insertion point
  129.  
  130. function initializeUI(){
  131.   document.theForm.URL.focus(); //set focus on textbox
  132.   document.theForm.URL.select(); //set insertion point into textbox
  133. }
  134.