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 / InsertEditableRegion.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  3.2 KB  |  126 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var helpDoc = MM.HELP_insertEditableRegion; 
  6. var targetDom = null;
  7. var abortCommand = false; //Set to true if the user cancels out of the 'save as template' dialog
  8. var abortMessage = ""; 
  9.  
  10. var selectedEditableNode = null; 
  11.  
  12. //---------------     API FUNCTIONS    ---------------
  13.  
  14. function commandButtons()
  15.     {
  16.       return new Array(
  17.                       MM.BTN_OK,"okClicked()",
  18.                       MM.BTN_Cancel,"window.close()",
  19.                       MM.BTN_Help,"displayHelp()");
  20.     }
  21.  
  22.  
  23. function isDomRequired() {
  24.     return true;
  25. }
  26.  
  27. function receiveArguments()
  28.     {
  29.     targetDom = arguments[0]; 
  30.     if (targetDom == null)
  31.         targetDom = dw.getDocumentDOM(); 
  32.     abortCommand = false; 
  33.     if (!CheckWarnNoTemplate(targetDom))
  34.         {
  35.         abortCommand = true; 
  36.         return "abort";
  37.         }
  38.     
  39.     var result = new Object();
  40.         
  41.     if (!abortCommand && !canMakeTemplateContent("editable", targetDom, result))
  42.         {
  43.         if (result.status == "contained in DW4 edit")
  44.             alert(MM.MSG_SaveDW4First); 
  45.         else if (result.status == "locked")
  46.             alert(MM.TEMPLATE_UTILS_CantInsertOptionalHere); 
  47.         else
  48.             alert(MM.MSG_AlreadyEdit);
  49.         
  50.         abortCommand = true; 
  51.         return "abort"; 
  52.         }
  53.         
  54.    var curSelNode = getUnlockedSelNode(targetDom, false); 
  55.    selectedEditableNode = null;
  56.    
  57.    if (curSelNode.tagName == "MMTEMPLATE:EDITABLE" && arguments.length > 1 && arguments[1] == "useSelectedNode")
  58.         selectedEditableNode = curSelNode; 
  59.     } //receiveArguments
  60.  
  61. function canAcceptCommand()
  62.     {
  63.     return (dw.getDocumentDOM('document') != null && dw.getFocus() != 'browser' && dw.getDocumentDOM().getParseMode() == 'html');
  64.     } //canAcceptCommand
  65.  
  66. function okClicked()
  67.     {    
  68.     
  69.     var curDOM = (targetDom == null) ? dw.getDocumentDOM('document') : targetDom; 
  70.     if (selectedEditableNode != null)
  71.         {    
  72.             
  73.         if (selectedEditableNode.name == document.theForm.name.value)
  74.             {
  75.             window.close();
  76.             return; 
  77.             }
  78.             
  79.         if (findNamedEditableRegion(document.theForm.name.value, curDOM, null, false, selectedEditableNode) != null)    
  80.             {
  81.             alert(MSG_alreadyExists);
  82.             document.theForm.name.focus();
  83.               document.theForm.name.select(); //set insertion point into textbox
  84.             return; 
  85.             }        
  86.             
  87.         curDOM.disableLocking(); 
  88.         curDOM.syncronizeDocument(); 
  89.         selectedEditableNode.name = dwscripts.minentityNameEncode(document.theForm.name.value);            
  90.         curDOM.synchronizeDocument();
  91.         curDOM.enableLocking();
  92.         
  93.         window.close();
  94.         }
  95.     else 
  96.         {
  97.         
  98.         if (doInsertEditable(document.theForm.name.value, targetDom))
  99.             window.close();
  100.         }
  101.         
  102.     }
  103.     
  104.     
  105. //---------------    LOCAL FUNCTIONS   ---------------
  106.  
  107.  
  108. function initializeUI()
  109.     {    
  110.     if (abortCommand)
  111.         {        
  112.         window.close();
  113.         return; 
  114.         }
  115.     
  116.    if (selectedEditableNode != null)
  117.         document.theForm.name.value = dwscripts.minEntityNameDecode(selectedEditableNode.name); 
  118.     else
  119.         document.theForm.name.value =   getUniqueRegionName(MM.EditAutonamePreamble, "MMTemplate:Editable",  dw.getDocumentDOM('document'));
  120.         
  121.       document.theForm.name.focus(); //set focus on textbox
  122.       document.theForm.name.select(); //set insertion point into textbox
  123.     } //initializeUI
  124.  
  125.  
  126.