home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 July / 07_02.iso / software / mdmx / files / DreamweaverMXInstaller.exe / Disk1 / data1.cab / Configuration_En / Commands / TableMain.js < prev    next >
Encoding:
JavaScript  |  2002-05-01  |  5.2 KB  |  177 lines

  1. // Copyright 2001-2002 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var helpDoc = MM.HELP_objTable;
  6. var gDialogShown = false;
  7. var gReturnTag;
  8. var gRepeatRows = false; 
  9.  
  10. //---------------     API FUNCTIONS    ---------------
  11.  
  12. function isDOMRequired() {
  13.     return false;
  14. }
  15.     
  16. function commandButtons(){
  17.    return new Array(MM.BTN_OK,         "onOK()",
  18.                     MM.BTN_Cancel,     "window.close()",
  19.                     MM.BTN_Help,       "displayHelp()" );
  20. }
  21.  
  22. function receiveArguments()
  23.     {    
  24.     gRepeatRows = (arguments.length > 0 && arguments[0] == "repeatRows");
  25.     } //receiveArguments
  26.  
  27. function onOK()
  28.     {
  29.     if (gRepeatRows)
  30.         {
  31.         //Make sure the rows make sense. 
  32.           var Rows = document.theForm.Rows.value;
  33.          var repeatStart = document.theForm.startingRow.value; 
  34.           var repeatEnd = document.theForm.endingRow.value;
  35.           
  36.           if (repeatStart > Rows || repeatEnd < repeatStart || repeatEnd > Rows)
  37.               {
  38.               alert(MM.RepeatTableRowsWarning);
  39.               return;
  40.               }
  41.           }
  42.         
  43.     setTableStr();
  44.     window.close();
  45.     }
  46.  
  47. //Get a row of a table that has edit regions in each cell. 
  48. function getEditTableRow(columnCount)
  49.     {
  50.     var tableRow = ""; 
  51.       for (i=0; i< Columns; i++)
  52.           {
  53.           var curCellName = getUniqueRegionName(MM.EditAutonamePreamble, "MMTemplate:Editable", dw.getDocumentDOM("document")); 
  54.           var curCell = "<TD>\n<MMTemplate:Editable name=\"" + curCellName + "\">" + dw.getDocumentDOM("document").getNBSPChar() + "</MMTemplate:Editable>\n</TD>";
  55.         tableRow += curCell;
  56.            }
  57.            
  58.      return tableRow = "<"+"TR>" + tableRow + "<"+"/TR>";
  59.     }
  60.             
  61. function setTableStr(){
  62.  
  63.   var Columns = document.theForm.Cols.value;
  64.   var Rows = document.theForm.Rows.value;
  65.   var Border = document.theForm.Border.value;
  66.   var Width = document.theForm.Width.value;
  67.   var cellSpacing = document.theForm.Cellspace.value;
  68.   var cellPadding = document.theForm.Cellpad.value;
  69.   var unitChoice = document.forms[0].Units.selectedIndex;
  70.  
  71.   var repeatStart = -1; 
  72.   var repeatEnd = -1; 
  73.   var repeatStartContent = ""; 
  74.   var repeatEndContent = ""; 
  75.   
  76.   if (gRepeatRows)
  77.       {
  78.       repeatStart = document.theForm.startingRow.value;
  79.       repeatEnd = document.theForm.endingRow.value;
  80.       
  81.       var regionName = getUniqueRegionName(MM.RepeatAutonamePreamble, "MMTemplate:Repeat", dw.getDocumentDOM("document"));
  82.       
  83.       repeatStartContent = "<MMTemplate:Repeat name=\"" + regionName + "\">"; 
  84.       repeatEndContent = "</MMTemplate:Repeat>";
  85.       }
  86.       
  87.   var tableCells='<'+'TD>' + dw.getDocumentDOM("document").getNBSPChar() + '<'+'/TD>\n';
  88.   var tableRow='',tableContent='';
  89.   var openTag= '<' + 'table', spaceIndex;
  90.   var widthAttr;
  91.  
  92.   //change any negative or non-numeric row or column value into 1
  93.   Columns = (parseInt(Columns)== Columns && Columns>0)?Columns:1;
  94.   Rows = (parseInt(Rows)== Rows && Rows>0)?Rows:1;
  95.  
  96.   //CREATE TABLE
  97.   //determine contents of 1 table row
  98.   for (i=0; i< Columns; i++)
  99.     tableRow+=tableCells;
  100.   tableRow = "<"+"TR>\n" + tableRow + "<"+"/TR>\n";
  101.   
  102.   //determine number of table rows & concatenate rows together
  103.   for (i=0; i< Rows; i++)
  104.       {
  105.     if (gRepeatRows && i == repeatStart-1)
  106.         tableContent += repeatStartContent; 
  107.     
  108.     if (gRepeatRows && i >= repeatStart-1 && i <= repeatEnd -1)
  109.         tableContent += getEditTableRow(Columns); 
  110.     else
  111.         tableContent += tableRow;
  112.     
  113.     if (gRepeatRows && i == repeatEnd - 1)
  114.         tableContent += repeatEndContent; 
  115.     }
  116.     
  117.     
  118.   //add percent or pixel values to opening tag, if applicable
  119.   if (Width)
  120.     openTag += ' width="'+Width + ((unitChoice == 0)? '%" ' : '"');
  121.   //add border value, if applicable
  122.   if (Border)
  123.     openTag+=' border="' + Border + '" ';
  124.   //add cellspacing value, if applicable
  125.   if (cellSpacing)
  126.     openTag+=' cellspacing="' + cellSpacing + '"';
  127.   //add cellpadding value, if applicable
  128.   if (cellPadding)
  129.     openTag+=' cellpadding="' + cellPadding + '"';
  130.  
  131.   //strip extra space from openTag, if it exists
  132.   spaceIndex = openTag.length-1
  133.   if (escape(openTag.charAt(spaceIndex))=='%20')
  134.     openTag = openTag.substring(0,spaceIndex);
  135.  
  136.   openTag += '>\n' + tableContent;
  137.  
  138.   if (gDialogShown) {
  139.     saveExtension(document)
  140.   }
  141.   gDialogShown = false; // Reset show dialog global.
  142.   
  143.   openTag += '<'+'/table'+'>';
  144.   gReturnTag= openTag;
  145. }
  146.  
  147.  
  148. function createTableStr() {
  149.  
  150.     return gReturnTag;
  151.  
  152. }
  153. //---------------    LOCAL FUNCTIONS   ---------------
  154.  
  155. function saveExtension(curDOM) {
  156.   var curHTML = DWfile.read(curDOM.URL);
  157.   var tempFilename = dw.getConfigurationPath() + '/Shared/MM/Cache/empty.htm';
  158.   if (DWfile.exists(tempFilename)) {
  159.     var tempDOM = dw.getDocumentDOM(tempFilename);
  160.     tempDOM.documentElement.outerHTML = curHTML;
  161.     var atrStr = DWfile.getAttributes(curDOM.URL);
  162.     if (tempDOM.body.outerHTML != curDOM.body.outerHTML && (atrStr.indexOf('R') == -1)){
  163.       tempDOM.body.outerHTML = curDOM.body.outerHTML;
  164.       DWfile.write(curDOM.URL, tempDOM.documentElement.outerHTML);
  165.     }
  166.   }
  167. }
  168.  
  169. function initializeUI()
  170. {    
  171.   document.theForm.Rows.focus(); //set focus on textbox
  172.   document.theForm.Rows.select(); //set insertion point into textbox
  173.   gDialogShown = true;
  174.   gReturnTag = '';
  175. }
  176.  
  177.