home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 86 / PIWD86.iso / pc / contents / dreamweaver / software / dwmx2004.exe / Disk1 / data1.cab / Configuration_En / Commands / Jump Menu.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  5.6 KB  |  191 lines

  1.  
  2. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  3.  
  4. //////
  5.  
  6. //*************************GLOBAL VARS********************
  7.  
  8. var helpDoc = MM.HELP_objJumpMenu;
  9.  
  10. //form objects
  11. var GlistOptions;
  12. var GtfLabel;
  13. var GtfURL;
  14. var GtfName;
  15. var GselTarget;
  16. var GcbRestore
  17. var GcbGo;
  18.  
  19.  
  20. var GarrMenuOptions;  //global array storing menu option text and URLs
  21.                      
  22.  
  23. //function: initGlobals
  24. //description: initialize global variables
  25.  
  26. function initGlobals(){
  27.  
  28.    var theForm = document.forms[0];
  29.    GlistOptions = theForm.MenuOptions;
  30.    GtfURL = theForm.fileURL;
  31.    GtfLabel = theForm.Label;
  32.    GtfName = theForm.Name;
  33.    GselTarget = theForm.Target;
  34.    GcbRestore = theForm.Restore;
  35.    GcbGo = theForm.Go; 
  36.    
  37.    GarrMenuOptions = new Array();
  38.    GarrMenuOptions[0] = new Array();
  39.    GarrMenuOptions[0][0] = getUniqueLabel();
  40.    GarrMenuOptions[0][1] = "";
  41. }
  42.  
  43. //***************************API FUNCTIONS*****************************
  44.  
  45. function isDOMRequired() { 
  46.     // Return false, indicating that this object is available in code view.
  47.     return false;
  48. }
  49.  
  50. function commandButtons(){
  51.    return new Array(MM.BTN_OK,        "okClicked()",
  52.                     MM.BTN_Cancel,    "cancelClicked()",          
  53.                     MM.BTN_Help,      "displayHelp()"  );
  54.  
  55. }
  56.  
  57. //***************************LOCAL FUNCTIONS*****************************
  58.  
  59. //function: okClicked
  60. //description: creates the jump menu that is inserted into the document
  61.  
  62. function okClicked(){ 
  63.    
  64.    var target = escQuotes(GselTarget.options[GselTarget.selectedIndex].value);
  65.    var bRestore = (GcbRestore.checked)?1:0;
  66.    var bInsideForm = IPIsInsideOfForm();
  67.    var nOptions = GarrMenuOptions.length,i,attrPos;
  68.    var optionStr="",formObjArr,uniqueFormName;
  69.    
  70.    //create opening of select tag
  71.    var menuStr = '<SELECT name="' + GtfName.value + '" ' +
  72.               'onChange="MM_jumpMenu(\'' + target + '\',this,' + bRestore + ')">\n';
  73.    
  74.    //create inner options string, i.e.:<option value="foo">label</option> 
  75.    for (i=0;i<nOptions;i++){
  76.       if (GarrMenuOptions[i][0] || GarrMenuOptions[i][1]){
  77.          optionStr = (GarrMenuOptions[i][1])?'<option value="' + GarrMenuOptions[i][1] + '">':
  78.                                              '<option>';                   
  79.          optionStr += GarrMenuOptions[i][0] + '</option>\n';
  80.          menuStr += optionStr;
  81.       }
  82.    }
  83.    menuStr += '</select>';       
  84.    
  85.    //if the "Insert a Go Button" is checked, then add a Go button
  86.    if (GcbGo.checked){
  87.       menuStr += createGoBtnStr(target,bRestore);
  88.    }
  89.    
  90.    //add a form to the document if one is not there already     
  91.    if ( !bInsideForm  ){ //if there isn't a form, add one
  92.       uniqueFormName = createUniqueName("FORM","form");
  93.       menuStr = '<form name="' + uniqueFormName + '">' + menuStr + '\n</form>';     
  94.    }  
  95.    MM.commandReturnValue = menuStr;
  96.    window.close();
  97. }    
  98.  
  99.  
  100.  
  101. function cancelClicked() {
  102.   MM.commandReturnValue = "";
  103.   window.close();
  104. }
  105.  
  106.  
  107. //function: createGoBtnStr
  108. //description: creates the text string for the go button
  109.  
  110. function createGoBtnStr(target,bRestore){
  111.  
  112.    var btnStr="";
  113.    
  114.    //get the select menu name
  115.    objName = GtfName.value;
  116.    
  117.    //create unique button name
  118.    var btnName = createUniqueName("INPUT","Button");
  119.  
  120.    //piece together button string 
  121.    btnStr += '<INPUT type="button" name="' + btnName + '" value="' + BTN_Go + '" ' +
  122.               'onClick="MM_jumpMenuGo(\'' + objName + '\',\'' + target + '\',' + bRestore + ')">';
  123.                   
  124.    return ( btnStr );
  125.  
  126. }
  127.  
  128. //function: initializeUI
  129. //description: initializes the UI, attached to body onload
  130. function initializeUI(){
  131.    initGlobals();
  132.    
  133.    //initial state of dialog is that "Option Label" appears in Lable field,
  134.    //"Option URL" appears in URL field, and the lable field selected
  135.    populateMenuOptions(0);
  136.    GlistOptions.selectedIndex = 0; 
  137.    GtfLabel.value = GarrMenuOptions[0][0];
  138.    GtfURL.value = GarrMenuOptions[0][1];
  139.    GtfLabel.focus();
  140.    GtfLabel.select();
  141.    
  142.    //populate frame target menu
  143.    populateFrameTargetMenu(GselTarget);
  144.    
  145.    //create a unique name for this menu
  146.    GtfName.value = createUniqueName("SELECT","menu");
  147. }
  148.  
  149. //function: popuplateFrameTargetMenu
  150. //description: populates the frame target menu with either:
  151. //"Main Window" - if there are no frames
  152. //"Main Window" plus named frames, if there are frames
  153.  
  154. function populateFrameTargetMenu(selectObj){
  155.    var counter = 0;
  156.    var frameList;
  157.    
  158.    selectObj.options[counter] = new Option(MM.TYPE_MainWindow);
  159.    selectObj.options[counter++].value = 'parent';
  160.    
  161.    frameList=getObjectRefs("NS 4.0","parent","frame"); //get list of frames
  162.    if (frameList && frameList.length>0) { //if frames
  163.    //if the frame has a name, add name to target picklist
  164.       for (i=0; i<frameList.length; i++) {
  165.          if (frameList[i].indexOf('unnamed')==-1){ //if the frame has a name
  166.             frameName=extrapolateFrameName(frameList[i]);
  167.             selectObj.options[counter] = new Option(MM.TYPE_Frame + ' "' + frameName + '"');
  168.             selectObj.options[counter++].value = frameList[i];
  169.          }
  170.       }
  171.     }
  172.    
  173.     //select the "Main Window" item
  174.     selectObj.selectedIndex = 0;
  175. }
  176.  
  177. //function: extrapolateFrameName
  178. //description: given a frame reference, extrapolates the frame's name
  179.  
  180. function extrapolateFrameName(frameRef){
  181.    return frameRef.substring(frameRef.indexOf("['")+2,frameRef.indexOf("']"));
  182. }
  183.  
  184.  
  185.  
  186. //****************************GLOBAL FUNCTIONS***************************
  187.  
  188. //createUniqueName
  189. //IPisInsideOfForm
  190. //isLayer
  191.