home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 April / maximum-cd-2000-04.iso / Utilities / InternetTools / dreamweaver3 / data1.cab / App_Files / Configuration / Behaviors / Actions / Go To URL.js < prev    next >
Encoding:
JavaScript  |  1999-12-09  |  7.9 KB  |  218 lines

  1.  
  2. // Copyright 1998 Macromedia, Inc. All rights reserved.
  3. //*************** GLOBAL VARS  *****************
  4.  
  5. var helpDoc = MM.HELP_behGoToURL;
  6.  
  7. //******************* BEHAVIOR FUNCTION **********************
  8.  
  9. //Causes the browser to go to a new URL, or can send multiple
  10. //frames to new URLs.
  11. //The function accepts a variable number of args, in pairs as follows:
  12. //  objStr  - window or frame object reference (ex: window, parent.myFrame)
  13. //  theURL  - URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  14. //
  15. //With each pair of args, sets objStr.location = theURL. Normally, you would
  16. //use a link, but this function can be used to send multiple frames to new locations.
  17. //Returns "false" to prevent a link's HREF from overriding the change.
  18.  
  19. function MM_goToURL() { //v3.0
  20.   var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  21.   for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
  22. }
  23.  
  24. document.VERSION_MM_goToURL = 3.0; //define latest version number for behavior inspector
  25.  
  26. //******************* API **********************
  27.  
  28.  
  29. //Can be used with any tag and any event
  30.  
  31. function canAcceptBehavior(){
  32.   return true;
  33. }
  34.  
  35.  
  36.  
  37. //Returns a Javascript function to be inserted in HTML head with script tags.
  38.  
  39. function behaviorFunction(){
  40.   return "MM_goToURL";
  41. }
  42.  
  43.  
  44.  
  45. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  46. //Gets list of URLs from doc property. With each URL, it gets the parallel
  47. //frame name from select 'menu'. Each theURL & frameName are embedded as args,
  48. //and the URLs are encoded w/ dw.doURLEncoding().
  49.  
  50. function applyBehavior() {
  51.   var argList,numItems,i,theURL,frameName,bMain,bFrames;
  52.  
  53.   bMain = false; bFrames=false;
  54.   argList = "";
  55.   numItems = document.MM_myURLs.length;
  56.   for (i=0; i<numItems; i++) {    //with each URL
  57.     theURL = document.MM_myURLs[i];
  58.     if (theURL) {      //if not empty
  59.       frameName = document.MM_NS_REFS[i]; //get frame name from parallel prop
  60.  
  61.       if (frameName.indexOf(REF_UNNAMED) == 0)  //if unnamed reference
  62.         return MSG_FrameUnnamed;
  63.  
  64.       if (i==0) {
  65.         frameName = "parent"; //set first item correctly
  66.         bMain = true;  //there's a Main URL
  67.       } else bFrames = true;  //there's a frame URL
  68.       if (argList) argList += ",";  //if stuff already in list, add comma
  69.       argList += "'"+escQuotes(frameName)+"','"+dw.doURLEncoding(theURL)+"'";
  70.     }
  71.   }
  72.   if (argList) {
  73.     if (bMain && bFrames) //if user added URLs for MainWindow *and* frames (illegal)
  74.          return MSG_FrameMixConflict;
  75.     else {
  76.       updateBehaviorFns("MM_goToURL");
  77.       return "MM_goToURL("+argList+")";  //return fn call with args
  78.     }
  79.   } else return MSG_MissingURL;
  80. }
  81.  
  82.  
  83.  
  84. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  85. //call arguments. This information is used by DW to fixup behavior args when the
  86. //document is moved or changed.
  87. //
  88. //It is passed an actual function call string generated by applyBehavior(), which
  89. //may have a variable list of arguments, and this should return a matching mask.
  90. //
  91. //The return values are:
  92. //  URL     : argument could be a file path, which DW will update during Save As...
  93. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  94. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  95. //  other...: argument is ignored
  96.  
  97. function identifyBehaviorArguments(fnCallStr) {
  98.   var argList, argArray, numArgGroups, i;
  99.  
  100.   argList = "";
  101.   argArray = extractArgs(fnCallStr);
  102.   numArgGroups = (argArray.length - 1) / 2; //args come in pairs
  103.   for (i=0; i<numArgGroups; i++) {          //with each frame,URL pair
  104.     argList += ((argList)?",":"")+"other,NAV";
  105.   }
  106.   return argList;
  107. }
  108.  
  109.  
  110.  
  111. //Given the original function call, this parses out the args and updates
  112. //the UI. First it calls initializeUI(). Then it gets new frame,URL pairs.
  113. //If frame already present in menu, stuff URL name in URLarray. If frame
  114. //doesn't exist, add to menu, and extend URLarray.
  115.  
  116. function inspectBehavior(upStr){
  117.   var i, j, argArray, URLarray, found, numFrames, theFrame, theURL;
  118.  
  119.   URLarray = document.MM_myURLs; //get the prior list of URLs
  120.   argArray = extractArgs(upStr); //get new list of frame,URL pairs
  121.   numFrames = document.MM_NS_REFS.length;
  122.   for (i=1; i<argArray.length; i+=2){ //with each frame,URL pair
  123.     theFrame=argArray[i];
  124.     if (theFrame.toUpperCase() == "PARENT") theFrame = TYPE_MainWindow;
  125.     theURL=unescape(argArray[i+1]);
  126.     found = false;
  127.     for (j=0; j<numFrames; j++){  //check if frame is in menu
  128.       if (document.MM_NS_REFS[j] == theFrame) { //if frame there
  129.         URLarray[j] = theURL;               //store URL at that pos
  130.         if (theURL) addStarToMenuItem(document.theForm.menu,j); //mark with  *
  131.         found = true;
  132.         break;
  133.       }
  134.     }
  135.     if (!found) alert(errMsg(MSG_FrameNotFound,theFrame,theURL)); //if frame name not found
  136.   }
  137.   document.MM_myURLs = URLarray; //save updated URL list
  138.   displayURL();         //load the URL for selected frame
  139. }
  140.  
  141.  
  142.  
  143. //***************** LOCAL FUNCTIONS  ******************
  144.  
  145.  
  146. //Load the select menu with frame names.
  147. //Also sets the global property MM_myURLs to the right num of items.
  148.  
  149. function initializeUI(){
  150.   var i,frameArray;
  151.   var URLarray = new Array;
  152.   var nameArray = new Array;
  153.  
  154.   frameArray = getObjectRefs("NS 4.0","parent","FRAME"); //get NS frame refs (IE is same)
  155.   nameArray[0] = TYPE_MainWindow;
  156.   for (i=0; i<frameArray.length; i++)   //copy array to append to MainWindow
  157.     nameArray[i+1] = frameArray[i]; //add the frame names to the list
  158.   document.MM_NS_REFS = nameArray; //store NS frame refs for later
  159.   nameArray = niceNames(nameArray,TYPE_Frame);  //convert to nice
  160.   for (i=0; i<nameArray.length; i++){
  161.     document.theForm.menu.options[i]=new Option(nameArray[i]); //add frames to menu
  162.     URLarray[i] = "";  //create blank parallel array to store URLs
  163.   }
  164.   document.MM_myURLs = URLarray; //set global
  165.  
  166.   document.theForm.theURL.focus(); //set focus on textbox
  167.   document.theForm.theURL.select(); //set insertion point into textbox
  168. }
  169.  
  170.  
  171.  
  172. //Given URL in form, looks up the menu's selection number, and stores the
  173. //new URL at that position in the global document property "MM_myURLs".
  174.  
  175. function storeURL(){
  176.   var newURL, URLarray, menuIndex, newMenuText;
  177.  
  178.   newURL = document.theForm.theURL.value;
  179.   URLarray = document.MM_myURLs; //get the prior list of URLs
  180.   menuIndex = document.theForm.menu.selectedIndex; //get index to swap
  181.   URLarray[menuIndex] = newURL;   //swap
  182.   document.MM_myURLs = URLarray;   //rewrite list
  183.   if (newURL.length > 0) {  //if non-empty, mark with  *
  184.     addStarToMenuItem(document.theForm.menu, menuIndex);
  185.   } else { //nothing to store, strip off any previous star
  186.     newMenuText = stripStar(document.theForm.menu.options[menuIndex].text); //remove if old star
  187.     document.theForm.menu.options[menuIndex]=new Option(newMenuText); //add new line to menu
  188.   }
  189.   document.theForm.menu.selectedIndex = menuIndex; //reset selection index BUG!: CAUSES BOMB!
  190. }
  191.  
  192.  
  193.  
  194. //Looks at the menu of names, and returns the URL associated with the
  195. //selected item. Example: if the 2nd menu item's selected, returns 2nd item
  196. //stored in property "MM_myURLs".
  197.  
  198. function displayURL(){
  199.   var URLarray = document.MM_myURLs; //get the list of URLs
  200.   curFrameNum = document.theForm.menu.selectedIndex; //get index selected
  201.   theURL = URLarray[curFrameNum];   //lookup URL
  202.   document.theForm.theURL.value= theURL;    //write into text field
  203.   document.theForm.menu.selectedIndex = curFrameNum; //WORKAROUND! resets the menu selection
  204. }
  205.  
  206.  
  207.  
  208. //Invokes dialog to allow user to select filename. Puts value in text input.
  209.  
  210. function browseFileAndStore(){
  211.   var fileName = "";
  212.   fileName = browseForFileURL();  //returns a local filename
  213.   if (fileName) {
  214.     document.theForm.theURL.value = fileName;
  215.     storeURL();
  216.   }
  217. }
  218.