home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / dwmx61.exe / Disk1 / data1.cab / Configuration_En / Objects / Common / Table.js < prev    next >
Encoding:
JavaScript  |  2002-11-25  |  3.8 KB  |  115 lines

  1. // Copyright 1999-2002 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4. var OBJECT_FILE = dw.getConfigurationPath() + '/Objects/Common/Table.htm';
  5. var DEBUG_FILE = dw.getConfigurationPath() + '/Objects/Common/TABLE_DEBUG.txt';
  6. var helpDoc = MM.HELP_objTable;
  7. var gDialogShown = false;
  8.  
  9. //---------------     API FUNCTIONS    ---------------
  10.  
  11. function isDOMRequired() {
  12.     return false;
  13. }
  14.  
  15.     
  16.  
  17. function objectTag() {
  18.   var Columns = document.theForm.Cols.value;
  19.   var Rows = document.theForm.Rows.value;
  20.   var Border = document.theForm.Border.value;
  21.   var Width = document.theForm.Width.value;
  22.   var cellSpacing = document.theForm.Cellspace.value;
  23.   var cellPadding = document.theForm.Cellpad.value;
  24.   var unitChoice = document.forms[0].Units.selectedIndex;
  25.   var retStr = "";
  26.   
  27.   var tableCells='<'+'TD>' + dw.getDocumentDOM("document").getNBSPChar() + '<'+'/TD>';
  28.   var tableRow='',tableContent='';
  29.   var openTag= '<' + 'table ', spaceIndex;
  30.   var widthAttr;
  31.  
  32.   //change any negative or non-numeric row or column value into 1
  33.   Columns = parseInt(Columns);
  34.   Columns = (Columns>0)?Columns:1;
  35.   Rows = parseInt(Rows);
  36.   Rows = (Rows>0)?Rows:1;
  37.  
  38.   //CREATE TABLE
  39.   //determine contents of 1 table row
  40.   for (i=0; i< Columns; i++)
  41.     tableRow+=tableCells;
  42.   tableRow = "<"+"TR>" + tableRow + "<"+"/TR>";
  43.  
  44.   //determine number of table rows & concatanate rows together
  45.   for (i=0; i< Rows; i++)
  46.     tableContent += tableRow;
  47.  
  48.   //add percent or pixel values to opening tag, if applicable
  49.   if (Width)
  50.     openTag += 'width="'+Width + ((unitChoice == 0)? '%" ' : '" ');
  51.   //add border value, if applicable
  52.   if (Border)
  53.     openTag+='border="' + Border + '" ';
  54.   //add cellspacing value, if applicable
  55.   if (cellSpacing)
  56.     openTag+='cellspacing="' + cellSpacing + '" ';
  57.   //add cellpadding value, if applicable
  58.   if (cellPadding)
  59.     openTag+='cellpadding="' + cellPadding + '" ';
  60.  
  61.   //strip extra space from openTag, if it exists
  62.   spaceIndex = openTag.length-1
  63.   if (escape(openTag.charAt(spaceIndex))=='%20')
  64.     openTag = openTag.substring(0,spaceIndex);
  65.  
  66.   openTag += '>' + tableContent;
  67.   openTag += '<'+'/table'+'>';
  68.   
  69.   retStr = openTag;
  70.   
  71.   if (gDialogShown){
  72.     saveExtension(document);
  73.   }
  74.   gDialogShown = false; // Reset show dialog global.
  75.  
  76.   // if accessibility preference for tables is on, call command to generate
  77.   // table string. pass already-set options as arguments; replace retStr with value
  78.   // generated by command.
  79.     if (dw.getPreferenceString("Accessibility", "Accessibility Table Options", "") == 'TRUE'){
  80.  
  81.        var cmdFile = dreamweaver.getConfigurationPath() + "/Commands/TableOptions.htm";
  82.        var cmdDOM = dreamweaver.getDocumentDOM(cmdFile);
  83.      
  84.        dreamweaver.runCommand("TableOptions.htm",Columns,Rows,Border,Width,cellSpacing,cellPadding,unitChoice);
  85.        var cmdRetStr = (cmdDOM.parentWindow.createTableStr());    
  86.      retStr = (cmdRetStr != "")?cmdRetStr:retStr;
  87.   
  88.   }
  89.  
  90.   return retStr;
  91. }
  92.  
  93. //---------------    LOCAL FUNCTIONS   ---------------
  94.  
  95. function saveExtension(curDOM) {
  96.   var curHTML = DWfile.read(curDOM.URL);
  97.   var tempFilename = dw.getConfigurationPath() + '/Shared/MM/Cache/empty.htm';
  98.   if (DWfile.exists(tempFilename)) {
  99.     var tempDOM = dw.getDocumentDOM(tempFilename);
  100.     tempDOM.documentElement.outerHTML = curHTML;
  101.     var atrStr = DWfile.getAttributes(curDOM.URL);
  102.     if (tempDOM.body.outerHTML != curDOM.body.outerHTML && (atrStr.indexOf('R') == -1)){
  103.       tempDOM.body.outerHTML = curDOM.body.outerHTML;
  104.       DWfile.write(curDOM.URL, tempDOM.documentElement.outerHTML);
  105.     }
  106.   }
  107. }
  108.  
  109. function initializeUI()
  110. {
  111.   document.theForm.Rows.focus(); //set focus on textbox
  112.   document.theForm.Rows.select(); //set insertion point into textbox
  113.   gDialogShown = true;
  114. }
  115.