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 / TableCommands.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  7.8 KB  |  237 lines

  1. // Copyright 1999, 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4. var OBJECT_FILE = dw.getConfigurationPath() + '/commands/TableCommands.htm';
  5. var DEBUG_FILE = dw.getConfigurationPath() + '/Objects/Common/TABLE_DEBUG.txt';
  6. var helpDoc = MM.HELP_objTable;
  7. var returnTag='';
  8. var gDialogShown = false;
  9. var TBL_HDR;  //instance of iconSelectorClass, used for selecting table header icons
  10.  
  11. //---------------     API FUNCTIONS    ---------------
  12.  
  13. function isDOMRequired() {
  14.     return false;
  15. }
  16.  
  17. function commandButtons()
  18. {
  19.    return new Array("PutButtonsOnBottom", "OkButton defaultButton", MM.BTN_OK, "if (setTableStr()) window.close()",
  20.                     "PutButtonOnLeft", MM.BTN_Help, "displayHelp()",
  21.                     "CancelButton", MM.BTN_Cancel, "window.close()" );
  22. }
  23.     
  24.  
  25. function setTableStr() {
  26.   var dom = dw.getDocumentDOM();
  27.   var theNBSP = dom.getNBSPChar();
  28.   var Columns = document.theForm.Cols.value;
  29.   var Rows = document.theForm.Rows.value;
  30.   var Border = document.theForm.Border.value;
  31.   var Width = document.theForm.Width.value;
  32.   var cellSpacing = document.theForm.Cellspace.value;
  33.   var cellPadding = document.theForm.Cellpad.value;
  34.   var unitChoice = document.forms[0].Units.selectedIndex;
  35.   var captionStr = document.theForm.Caption.value;
  36.   var alignCapChoice = document.theForm.CaptionAlign.selectedIndex;
  37.   var alignCaption = document.theForm.CaptionAlign.options[alignCapChoice].value;
  38.   var summaryStr = document.theForm.Summary.value;
  39.  
  40.   var retStr = "";  
  41.   var tableCells='<'+'TD>' + theNBSP + '<'+'/TD>\n';
  42.   var tableScopeRowCells='<'+'TH scope="row">' + theNBSP + '<'+'/TH>\n';
  43.   var tableScopeColCells='<'+'TH scope="col">' + theNBSP + '<'+'/TH>\n';
  44.   var tableRow='',tableContent='', tableRowScopeRow='', tableRowScopeCol='';
  45.   var openTag= '<' + 'table';
  46.   var captionTag = '<caption';
  47.   var spaceIndex;
  48.   var widthAttr;
  49.  
  50.   // header choice can be "none", "row", "column" or "both"
  51.   var i = 0;
  52.   var headerchoice;
  53.   headerChoice = TBL_HDR.value;
  54.  
  55.   //change any negative or non-numeric row or column value into 1
  56.   Columns = parseInt(Columns);
  57.   Columns = (Columns>0)?Columns:1;
  58.   Rows = parseInt(Rows);
  59.   Rows = (Rows>0)?Rows:1;
  60.  
  61.   //CREATE TABLE
  62.   //determine contents of 1 table row according to the number of columns
  63.   //accessibility: first column value is added later; begin with the second column
  64.  
  65.   for (i=1; i< Columns; i++){
  66.     tableRow+=tableCells;
  67.     tableRowScopeRow+=tableScopeRowCells;
  68.     tableRowScopeCol+=tableScopeColCells;
  69.   }
  70.  
  71.   // set the value for FirstTableRow and RestTableRow depending on header request.
  72.   if (headerChoice == 'row'){
  73.  
  74.     FirstTableRow = "<"+"TR>\n" + tableScopeColCells + tableRowScopeCol + "<"+"/TR>\n";
  75.     RestTableRow = "<"+"TR>\n" + tableCells + tableRow + "<"+"/TR>\n";
  76.   }
  77.   else{
  78.         if(headerChoice == 'col'){
  79.  
  80.          FirstTableRow = "<"+"TR>\n"+ tableScopeRowCells + tableRow + "<"+"/TR>\n";
  81.          RestTableRow = FirstTableRow;
  82.  
  83.         }
  84.         else{
  85.               if(headerChoice == 'both'){
  86.                 FirstTableRow = "<"+"TR>\n" + tableScopeColCells + tableRowScopeCol + "<"+"/TR>\n";
  87.                 RestTableRow = "<"+"TR>\n"+ tableScopeRowCells + tableRow + "<"+"/TR>\n";
  88.               } 
  89.               else{
  90.                     FirstTableRow = "<"+"TR>\n"+ tableCells + tableRow + "<"+"/TR>\n";
  91.                     RestTableRow = FirstTableRow;
  92.               }
  93.  
  94.         }
  95.   }
  96.  
  97.   tableContent+= FirstTableRow;
  98.  
  99.   //determine number of table rows & concatanate rows together
  100.   for (i=1; i< Rows; i++)
  101.     tableContent += RestTableRow;
  102.  
  103.   //add percent or pixel values to opening tag, if applicable
  104.   if (Width)
  105.     openTag += ' width="'+Width + ((unitChoice == 0)? '%" ' : '"');
  106.   //add border value, if applicable
  107.   if (Border)
  108.     openTag+=' border="' + Border + '"';
  109.   //add cellspacing value, if applicable
  110.   if (cellSpacing)
  111.     openTag+=' cellspacing="' + cellSpacing + '"';
  112.   //add cellpadding value, if applicable
  113.   if (cellPadding)
  114.     openTag+=' cellpadding="' + cellPadding + '"';
  115.  
  116.   //add summary to openTag table tag, if applicable 
  117.   if(summaryStr != null && summaryStr != "") 
  118.     openTag+= ' summary="' + summaryStr + '"';
  119.  
  120.   //add caption to openTag table tag, if applicable 
  121.   if(captionStr != null && captionStr != "") 
  122.   {
  123.     (alignCaption == "default" || alignCaption == undefined)?captionTag+= '>':captionTag+= ' align="' + alignCaption + '">';
  124.     openTag+= '>\n' + captionTag + captionStr + '<\/CAPTION>\n' + tableContent;
  125.   }
  126.   else {
  127.     openTag += '>\n' + tableContent;
  128.   }
  129.  
  130.   //strip extra space from openTag, if it exists
  131.   spaceIndex = openTag.length-1
  132.   if (escape(openTag.charAt(spaceIndex))=='%20')
  133.     openTag = openTag.substring(0,spaceIndex);
  134.  
  135.   openTag += '<'+'/table'+'>';
  136.   
  137.   retStr = openTag;
  138.  
  139.   if (gDialogShown){
  140.     document.theForm.Summary.value = "";
  141.     document.theForm.Caption.value = "";
  142.     dwscripts.saveExtension(document);
  143.   }
  144.   gDialogShown = false; // Reset show dialog global.
  145.  
  146.   returnTag = retStr;
  147.   return true;
  148. }
  149.  
  150. function createTableStr()
  151. {
  152.     return returnTag;
  153. }
  154.  
  155. //---------------    LOCAL FUNCTIONS   ---------------
  156.  
  157. function initializeUI()
  158. {
  159.   //initialize Table Header selector, default value "none"
  160.   TBL_HDR = new IconSelectorClass(new Array("none","row","col","both"),"none");
  161.   document.theForm.Rows.focus(); //set focus on textbox
  162.   document.theForm.Rows.select(); //set insertion point into textbox
  163.   gDialogShown = true;
  164. }
  165.  
  166.  
  167. ///--------------------------------------------------------------------
  168. // CLASS:
  169. //   IconSelectorClass
  170. //
  171. // DESCRIPTION:
  172. //   This class is used to provide radio-button functionality to images.
  173. // When clicking images in table cells, their cells will highlight. To
  174. // find out which image is selected, get the value property of the object.
  175. //
  176. // To set it up, place images in table cells, name the table cells uniquely,
  177. // and add onMouse handlers to each image that call the update method and
  178. // pass the name of their table cells.
  179. //
  180. // PUBLIC PROPERTIES:
  181. //   value (read-only) - the name of the table cell currently selected.
  182. //
  183. // PUBLIC FUNCTIONS:
  184. //   update(value) - passed by the click handler to select a new cell.
  185. //
  186. // CONSTRUCTOR:
  187. //   tableCellNames - an array of all table cell names to be used
  188. //   initialName (optional) - initial cell to select (otherwise 1st)
  189. //
  190. //--------------------------------------------------------------------
  191.  
  192. function IconSelectorClass(tableCellNames, initialName)
  193. {
  194.   //Private properties
  195.   this.selectedColor = "#316AC5";   //background color for selected table cell
  196.   this.unselectedColor = "#CCCCCC";        //background color for unselected table cell (#9D9CA7 on table)
  197.   this.selectedTextColor = "#FFFFFF";   //color for selected text (white)
  198.   this.unselectedTextColor = "#000000"; //color for unselected text (black)
  199.  
  200.   // find which is selected
  201.   for (var i=0; i<tableCellNames.length; i++)
  202.   {
  203.     if (document[tableCellNames[i]].bgColor == this.selectedColor)
  204.     {
  205.       this.value = tableCellNames[i];
  206.       break;
  207.     }
  208.   }
  209.  
  210.   // if didn't find it, initialize it
  211.   if (!this.value)
  212.     this.value = initialName;
  213. }
  214.  
  215. IconSelectorClass.prototype.update = IconSelectorClass_update;
  216.  
  217.  
  218. //Update method. Pass in a new value, one of the table cell names.
  219. function IconSelectorClass_update(newValue)
  220. {
  221.   if (this.value == newValue)
  222.     return;
  223.  
  224.   // for the previously selected cell, change bgColor and font color to unselected colors
  225.   document[this.value].bgColor = this.unselectedColor;
  226.   document[this.value + "font"].color = this.unselectedTextColor;
  227.  
  228.   //change the value to the new value
  229.   this.value = newValue;
  230.  
  231.   // set the colors for the newly selected cell
  232.   document[this.value].bgColor = this.selectedColor;
  233.   document[this.value + "font"].color = this.selectedTextColor;
  234. }
  235.  
  236. //----------- END IconSelectorClass --------------
  237.