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 / TableOptions.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  6.0 KB  |  197 lines

  1. //
  2. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  3.  
  4. //---------------   GLOBAL VARIABLES   ---------------
  5. var helpDoc = MM.HELP_objTableAccessOptions;
  6. var targetDom = null;
  7. var returnTag='';
  8.  
  9. var COLS;
  10. var ROWS;
  11. var BORDER;
  12. var WIDTH;
  13. var CELLSPACE;
  14. var CELLPAD;
  15. var UNITS;
  16.  
  17. //---------------     API FUNCTIONS    ---------------
  18.  
  19. function isDOMRequired() {
  20.     return false;
  21. }
  22.  
  23. function commandButtons(){
  24.    return new Array(MM.BTN_OK,         "setTableStr();window.close()",
  25.                     MM.BTN_Cancel,     "window.close()",
  26.                     MM.BTN_Help,       "displayHelp()" );
  27. }
  28.  
  29. function receiveArguments(){
  30.   // gather arguments from table object and
  31.   // use to set global vars
  32.   COLS = arguments[0];
  33.   ROWS = arguments[1];
  34.   BORDER = arguments[2];
  35.   WIDTH = arguments[3];
  36.   CELLSPACE = arguments[4];
  37.   CELLPAD = arguments[5];
  38.   UNITS = arguments[6];
  39. }
  40.  
  41. function setTableStr(){
  42.   var dom = dw.getDocumentDOM();
  43.   var theNBSP = dom.getNBSPChar();
  44.   
  45.   var summaryStr = document.theForm.Summary.value;
  46.   var captionStr = document.theForm.Caption.value;
  47.   var alignCapChoice = document.theForm.alignCap.selectedIndex;
  48.   var alignCaption = document.theForm.alignCap.options[alignCapChoice].value;
  49.   var headerChoiceIndex = document.theForm.Header.selectedIndex;
  50.   var headerChoice= document.theForm.Header.options[headerChoiceIndex].value;
  51.  
  52.   var captionTag = '<caption';
  53.   var tableCells='<'+'TD>' + theNBSP + '<'+'/TD>\n';
  54.   var tableScopeRowCells='<'+'TH scope="row">' + theNBSP + '<'+'/TH>\n';
  55.   var tableScopeColCells='<'+'TH scope="col">' + theNBSP + '<'+'/TH>\n';
  56.   var tableRow='',tableContent='', tableRowScopeRow='', tableRowScopeCol='';
  57.   var openTag= '<' + 'table', spaceIndex;
  58.   var widthAttr;
  59.  
  60.   //change any negative or non-numeric row or column value into 1
  61.   COLS = parseInt(COLS);
  62.   COLS = (COLS>0)?COLS:1;
  63.   ROWS = parseInt(ROWS);
  64.   ROWS = (ROWS>0)?ROWS:1;
  65.  
  66.   //CREATE TABLE
  67.   //determine contents of 1 table row according to the number of columns
  68.   //accessibility: first column value is added later; begin with the second column
  69.  
  70.   for (i=1; i< COLS; i++){
  71.     tableRow+=tableCells;
  72.     tableRowScopeRow+=tableScopeRowCells;
  73.     tableRowScopeCol+=tableScopeColCells;
  74.   }
  75.  
  76.   // set the value for FirstTableRow and RestTableRow depending on header request.
  77.   if (headerChoice == 'row'){
  78.  
  79.     FirstTableRow = "<"+"TR>\n" + tableScopeColCells + tableRowScopeCol + "<"+"/TR>\n";
  80.     RestTableRow = "<"+"TR>\n" + tableCells + tableRow + "<"+"/TR>\n";
  81.   }
  82.   else{
  83.         if(headerChoice == 'col'){
  84.  
  85.          FirstTableRow = "<"+"TR>\n"+ tableScopeRowCells + tableRow + "<"+"/TR>\n";
  86.          RestTableRow = FirstTableRow;
  87.  
  88.         }
  89.         else{
  90.               if(headerChoice == 'both'){
  91.                 FirstTableRow = "<"+"TR>\n" + tableScopeColCells + tableRowScopeCol + "<"+"/TR>\n";
  92.                 RestTableRow = "<"+"TR>\n"+ tableScopeRowCells + tableRow + "<"+"/TR>\n";
  93.               } 
  94.               else{
  95.                     FirstTableRow = "<"+"TR>\n"+ tableCells + tableRow + "<"+"/TR>\n";
  96.                     RestTableRow = FirstTableRow;
  97.               }
  98.  
  99.         }
  100.   }
  101.  
  102.         tableContent+= FirstTableRow;
  103.  
  104.   //determine number of table rows & concatanate rows together
  105.   for (i=1; i< ROWS; i++)
  106.       tableContent += RestTableRow;
  107.  
  108.   //add percent or pixel values to opening tag, if applicable
  109.   if (WIDTH)
  110.     openTag += ' width="'+WIDTH + ((UNITS == 0)? '%" ' : '"');
  111.   //add border value, if applicable
  112.   if (BORDER)
  113.     openTag+=' border="' + BORDER + '"';
  114.   //add cellspacing value, if applicable
  115.   if (CELLSPACE)
  116.     openTag+=' cellspacing="' + CELLSPACE + '"';
  117.   //add cellpadding value, if applicable
  118.   if (CELLPAD)
  119.     openTag+=' cellpadding="' + CELLPAD + '"';
  120.  
  121.   //add summary to openTag table tag, if applicable 
  122.   if(summaryStr != null && summaryStr != "") 
  123.     openTag+= ' summary="' + summaryStr + '"';
  124.  
  125.   //add caption to openTag table tag, if applicable 
  126.   if(captionStr != null && captionStr != "") 
  127.     {
  128.       (alignCaption == "default" || alignCaption == undefined)?captionTag+= '>':captionTag+= ' align="' + alignCaption + '">';
  129.       openTag+= '>\n' + captionTag + captionStr + '<\/CAPTION>\n' + tableContent;
  130.     }
  131.     else {
  132.       openTag += '>\n' + tableContent;
  133.     }
  134.  
  135.   //strip extra space from openTag, if it exists
  136.   spaceIndex = openTag.length-1
  137.   if (escape(openTag.charAt(spaceIndex))=='%20')
  138.     openTag = openTag.substring(0,spaceIndex);
  139.  
  140.  
  141.   openTag += '<'+'/table'+'>';
  142.  
  143.   // set global
  144.   returnTag = openTag;
  145. }
  146.  
  147.  
  148. function createTableStr() {
  149.  
  150.     return returnTag;
  151.  
  152. }
  153.  
  154.  
  155. //////////////////////////////////////////////////////////////
  156. // /////////// Update Radio Button Control functions /////////
  157. //
  158. // Header is set to 'none'; 
  159. // if user changes it updateHeader resets its icon accordingly
  160. //
  161. //////////////////////////////////////////////////////////////
  162.  
  163. function updateHeader(){
  164.   var headerChoiceIndex = document.theForm.Header.selectedIndex;
  165.   var headerChoice= document.theForm.Header.options[headerChoiceIndex].value;
  166.  
  167.     switch(headerChoice) {
  168.         case 'col': document.theForm.tableImage.src= "../Shared/MM/Images/tableHeaderColumn.gif"; break;
  169.         case 'row': document.theForm.tableImage.src= "../Shared/MM/Images/tableHeaderRow.gif"; break;
  170.         case 'none': document.theForm.tableImage.src= "../Shared/MM/Images/tableHeaderNone.gif"; break;
  171.         case 'both': document.theForm.tableImage.src= "../Shared/MM/Images/tableHeaderBoth.gif"; break;
  172.     }
  173. }
  174.  
  175.  
  176.  
  177. //////////////////////////////////////////////////////////////////
  178. // Initialize UI:                                   
  179. // set default values for fields, visibility for layers.
  180. //////////////////////////////////////////////////////////////////
  181.  
  182. function initializeUI()
  183. {    
  184.     document.theForm.Caption.value = "";
  185.     document.theForm.Summary.value = "";
  186.      
  187.       var alignCaption="";
  188.       var headerChoice='none';
  189.       document.theForm.Header.selectedIndex= 0;
  190.       document.theForm.tableImage.src= "../Shared/MM/Images/tableHeaderNone.gif";
  191.  
  192.       document.theForm.Caption.focus(); //set focus on textbox
  193.       document.theForm.Caption.select(); //set insertion point into textbox
  194.     
  195.  
  196.