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 / InsertOfficeDoc.js < prev    next >
Encoding:
Text File  |  2003-09-05  |  2.2 KB  |  100 lines

  1. //=========================================================================================================
  2. //
  3. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  4. //
  5. // Feature: Paste Fix
  6. // Author:  JDH
  7. // Module:  InsertOfficeDoc.js
  8. // Purpose:    Insert Office Document menu item handler.
  9. // Updates:
  10. //    8/1/02 - Started file control
  11. //
  12. //=========================================================================================================
  13.  
  14.     // The threshold where we should warn the user they are importing a big file
  15.  
  16. MM.od_WarnThreshold = 100000;
  17.  
  18.     // The threshold where we should not allow the user to import the file.
  19.  
  20. MM.od_MaxThreshold = 200000;
  21.  
  22. // insertOfficeDoc - Inserts the given file name into the current document.
  23.  
  24. function insertOfficeDoc( file, retArray, allowLink )
  25. {
  26.     // Switch on Excel or Word.  Use one of those to open up the file, and
  27.     // to save the contents as HTML and return it.
  28.  
  29.     var usedWord = false;
  30.  
  31.     var result;
  32.     if ( file.match( /[.]xls/i ) )
  33.     {
  34.         result = dw.excelSaveAsHTML( file );
  35.     }
  36.     else
  37.     {
  38.         result = dw.wordSaveAsHTML( file );
  39.         usedWord = true;
  40.     }
  41.  
  42.     // Get the text and the base URL
  43.  
  44.     var text = result[ 0 ];
  45.     var url = result[ 1 ];
  46.  
  47.     // Go through a bunch of logic to warn or alert the user to large files,
  48.     // and either insert it or not
  49.  
  50. // alert( text.length );
  51.  
  52.     if ( text != null && text.length > 0 )
  53.     {
  54.         if ( text.length < MM.od_WarnThreshold )
  55.         {
  56.             dw.getDocumentDOM().pasteInHTML( text, url );
  57.         }
  58.         else if ( text.length < MM.od_MaxThreshold )
  59.         {
  60.             if ( allowLink )
  61.             {
  62.                 var retVal = confirm( MM.MSG_odWarnWithLink );
  63.  
  64.                 if ( retVal == true )
  65.                     dw.getDocumentDOM().pasteInHTML( text, url );
  66.                 else
  67.                     retArray[ 0 ] = false;
  68.             }
  69.             else
  70.             {
  71.                 if ( confirm( MM.MSG_odWarn ) )
  72.                     dw.getDocumentDOM().pasteInHTML( text, url );
  73.             }
  74.         }
  75.         else
  76.         {
  77.             if ( allowLink )
  78.             {
  79.                 alert( MM.MSG_odStopWithLink );
  80.                 retArray[ 0 ] = false;
  81.             }
  82.             else
  83.             {
  84.                 alert( MM.MSG_odStop );
  85.             }
  86.         }
  87.     }
  88.     else
  89.     {
  90.         if ( usedWord )
  91.         {
  92.             alert( MM.MSG_odWordUnableToSaveAs );
  93.         }
  94.         else
  95.         {
  96.             alert( MM.MSG_odExcelUnableToSaveAs );
  97.         }
  98.     }
  99. }
  100.