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

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var gPropList;
  6. var helpDoc = MM.HELP_objGenerator;
  7.  
  8. //---------------     API FUNCTIONS    ---------------
  9.  
  10. function commandButtons(){
  11.   return new Array(
  12.                    BTN_Insert,   'insert();',
  13.                    BTN_Cancel,   'cleanup();'
  14.                   );
  15. }
  16.  
  17. function canAcceptCommand() {
  18.   return true;
  19. }
  20.  
  21.  
  22. //---------------    LOCAL FUNCTIONS   ---------------
  23.  
  24.  
  25. // Function: stripWhite
  26. // Description: Removes whitespace at beginning and end of the string.
  27. function stripWhite(theStr) {
  28.   if (!theStr) theStr = '';  //ensure its not null
  29.   theStr = theStr.replace(/^\s*/,''); //strip leading
  30.   theStr = theStr.replace(/\s*$/,''); //strip trailing
  31.   return theStr;
  32. }
  33.  
  34. // Function: initializeUI
  35. // Description: initialize UI and other associated preferences
  36. function initializeUI() {
  37.   // Create controlling list class.
  38.   gPropList = new ListControl('Parameters');
  39.   document.MainForm.TemplateFile.focus();
  40.   document.MainForm.TemplateFile.select();
  41. }
  42.  
  43. // Function: cleanup
  44. // Description: 
  45. function cleanup() {
  46.   // Exit
  47.   window.close();
  48. }
  49.  
  50. // Function: insert
  51. // Description: 
  52. function insert() {
  53.   // Exit
  54.   putParams();
  55.   window.close();
  56. }
  57.  
  58. function genParams() {
  59.   // Return generator parameters in URL format.
  60.   var rtnStr = '';
  61.   if (gPropList) {
  62.     rtnStr = gPropList.get('all').join('&');
  63.   }
  64.   return rtnStr;
  65. }
  66.  
  67.  
  68. // Function: objectTag
  69. // Description: Return inserted value for an Object
  70. function objectTag() {
  71.   // Return the html tag that should be inserted
  72.   
  73.   var rtnStr = '';
  74.   
  75.   var GeneratorType = document.MainForm.Format.options[document.MainForm.Format.selectedIndex].value;
  76.   var ObjectName = dw.doURLEncoding(document.MainForm.TemplateFile.value) ; // URL Encode Template filename
  77.   var Params = genParams();
  78.   var SrcSpec = ObjectName + '?' + ((Params) ? Params + '&': '') + 'type=' + GeneratorType;
  79.   var SwfSpec = (Params) ? ('?' + Params) : '';
  80.   
  81.   switch (GeneratorType) {
  82.     case 'gif':
  83.       rtnStr = '<IMG SRC="' + SrcSpec + '" BORDER=0>';
  84.       break;
  85.  
  86.     case 'jpg':
  87.       rtnStr = '<IMG SRC="' + SrcSpec + '" BORDER=0>';
  88.       break;
  89.  
  90.     case 'png':
  91.       rtnStr = '<IMG SRC="' + SrcSpec + '" BORDER=0>';
  92.       break;
  93.  
  94.     case 'mov':
  95.       rtnStr = '<EMBED SRC="' + SrcSpec + '" BORDER="0" PLUGINSPAGE="http://www.apple.com/quicktime/download/"><\/EMBED>';
  96.       break;
  97.       
  98.     case 'swf':
  99.     default:
  100.       rtnStr = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + 
  101.         ' CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0"' +
  102.         ' WIDTH="32" HEIGHT="32">\n' + 
  103.         '<PARAM NAME=movie VALUE="' + ObjectName + SwfSpec + '"> <PARAM NAME=quality VALUE=high>\n' +
  104.         '<EMBED SRC="' + ObjectName + SwfSpec + 
  105.         '" quality=high PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ' +
  106.         'TYPE="application/x-shockwave-flash" WIDTH="32" HEIGHT="32">'+
  107.         '<\/EMBED>\n' + 
  108.         '<\/OBJECT>';
  109.       break;
  110.   }  
  111.   return rtnStr;
  112. }
  113.  
  114. //------ Interface Support Functions
  115.  
  116. // Browse for generator template URL, and set form field.
  117. function browseFileAndSet(){
  118.   var fileName;
  119.   fileName = browseForFileURL('select', DLG_PROMPT, false);
  120.   // If selection canceled, empty string returned
  121.   if (fileName) { // Do not erase current field value.
  122.     document.MainForm.TemplateFile.value = fileName;
  123.   }
  124. }
  125.  
  126. function setParams() {
  127.   if (gPropList.getIndex() == -1) {  // If no selection (or no items)
  128.     if (document.MainForm.ParamName.value + document.MainForm.ParamValue.value)
  129.       gPropList.append(stripWhite(document.MainForm.ParamName.value) 
  130.       + '=' + document.MainForm.ParamValue.value);
  131.   } else {
  132.     gPropList.set(stripWhite(document.MainForm.ParamName.value) 
  133.     + '=' + document.MainForm.ParamValue.value);
  134. } }
  135.  
  136. function putParams() {
  137.   var pvArr;
  138.   var tempStr;
  139.   
  140.   tempStr = gPropList.get();
  141.   pvArr = tempStr.split('=');
  142.   if (pvArr[0])
  143.     document.MainForm.ParamName.value = pvArr[0];
  144.   else
  145.     document.MainForm.ParamName.value = '';
  146.     
  147.   if (pvArr[1])
  148.     document.MainForm.ParamValue.value = pvArr[1];
  149.   else
  150.     document.MainForm.ParamValue.value = '';   
  151. }
  152.  
  153. function addParam() {
  154.   if (gPropList.getIndex() == -1) {
  155.     gPropList.append('name=value');
  156.   } else {
  157.     gPropList.add('name=value');
  158.   }
  159.   putParams();
  160.   document.MainForm.ParamName.focus();
  161.   document.MainForm.ParamName.select();
  162. }
  163.  
  164. function delParam() {
  165.   gPropList.del();
  166.   putParams();
  167. }
  168.  
  169.