home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Objects / Common / Table.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  2.7 KB  |  88 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var helpDoc = MM.HELP_objTable;
  6. var gDialogShown = false;
  7.  
  8. //---------------     API FUNCTIONS    ---------------
  9.  
  10.  
  11. function objectTag() {
  12.   var Columns = document.theForm.Cols.value;
  13.   var Rows = document.theForm.Rows.value;
  14.   var Border = document.theForm.Border.value;
  15.   var Width = document.theForm.Width.value;
  16.   var cellSpacing = document.theForm.Cellspace.value;
  17.   var cellPadding = document.theForm.Cellpad.value;
  18.   var unitChoice = document.forms[0].Units.selectedIndex;
  19.  
  20.   var tableCells='<'+'TD> <'+'/TD>';
  21.   var tableRow='',tableContent='';
  22.   var openTag= '<' + 'table ', spaceIndex;
  23.   var widthAttr;
  24.  
  25.   //change any negative or non-numeric row or column value into 1
  26.   Columns = (parseInt(Columns)== Columns && Columns>0)?Columns:1;
  27.   Rows = (parseInt(Rows)== Rows && Rows>0)?Rows:1;
  28.  
  29.   //CREATE TABLE
  30.   //determine contents of 1 table row
  31.   for (i=0; i< Columns; i++)
  32.     tableRow+=tableCells;
  33.   tableRow = "<"+"TR>" + tableRow + "<"+"/TR>";
  34.  
  35.   //determine number of table rows & concatanate rows together
  36.   for (i=0; i< Rows; i++)
  37.     tableContent += tableRow;
  38.  
  39.   //add percent or pixel values to opening tag, if applicable
  40.   if (Width)
  41.     openTag += 'width="'+Width + ((unitChoice == 0)? '%" ' : '" ');
  42.   //add border value, if applicable
  43.   if (Border)
  44.     openTag+='border="' + Border + '" ';
  45.   //add cellspacing value, if applicable
  46.   if (cellSpacing)
  47.     openTag+='cellspacing="' + cellSpacing + '" ';
  48.   //add cellpadding value, if applicable
  49.   if (cellPadding)
  50.     openTag+='cellpadding="' + cellPadding + '" ';
  51.  
  52.   //strip extra space from openTag, if it exists
  53.   spaceIndex = openTag.length-1
  54.   if (escape(openTag.charAt(spaceIndex))=='%20')
  55.     openTag = openTag.substring(0,spaceIndex);
  56.  
  57.   openTag += '>' + tableContent;
  58.  
  59.   if (gDialogShown) {
  60.     saveExtension(document)
  61.   }
  62.   gDialogShown = false; // Reset show dialog global.
  63.   return openTag;
  64. }
  65.  
  66. //---------------    LOCAL FUNCTIONS   ---------------
  67.  
  68. function saveExtension(curDOM) {
  69.   var curHTML = DWfile.read(curDOM.URL);
  70.   var tempFilename = dw.getConfigurationPath() + '/Shared/MM/Cache/empty.htm';
  71.   if (DWfile.exists(tempFilename)) {
  72.     var tempDOM = dw.getDocumentDOM(tempFilename);
  73.     tempDOM.documentElement.outerHTML = curHTML;
  74.     var atrStr = DWfile.getAttributes(curDOM.URL);
  75.     if (tempDOM.body.outerHTML != curDOM.body.outerHTML && (atrStr.indexOf('R') == -1)){
  76.       tempDOM.body.outerHTML = curDOM.body.outerHTML;
  77.       DWfile.write(curDOM.URL, tempDOM.documentElement.outerHTML);
  78.     }
  79.   }
  80. }
  81.  
  82. function initializeUI()
  83. {
  84.   document.theForm.Rows.focus(); //set focus on textbox
  85.   document.theForm.Rows.select(); //set insertion point into textbox
  86.   gDialogShown = true;
  87. }
  88.