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 / Design Time Style Sheets.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  4.3 KB  |  145 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2. /***************** GLOBAL VARIABLES *****************/
  3.     
  4. var LIST_INCLUDED;
  5. var LIST_EXCLUDED;
  6.  
  7. var helpDoc = MM.HELP_cmdDesignTimeCSS;
  8.     
  9. /******************* API FUNCTIONS ******************/
  10.  
  11. function canAcceptCommand()
  12. {
  13.     // enable the menu item only if the document has been saved
  14.     
  15.     var filePath = dreamweaver.getDocumentPath("document");
  16.     
  17.     // also check if to see if the file is saved and there is a dom
  18.     var retVal = ((filePath!=null && filePath.length > 0) 
  19.                     && (dw.getFocus() == 'document' || dw.getFocus() == 'textView' || dw.getFocus(true) == 'html') 
  20.                     && dw.getDocumentDOM()!=null);
  21.     return retVal;
  22.     
  23. }
  24.  
  25. function commandButtons(){
  26.   return new Array(MM.BTN_OK,"doCommand()",MM.BTN_Cancel,"window.close()",MM.BTN_Help,"displayHelp()");
  27. }
  28.  
  29.  
  30. /****************** LOCAL FUNCTIONS *****************/
  31.  
  32. function initUI(){
  33.     // initialize form fields
  34.     LIST_INCLUDED = new ListControl("included");
  35.     LIST_EXCLUDED = new ListControl("excluded");
  36.  
  37.     // Initialize from the design notes
  38.     var foundNotes = false;
  39.     var filePath = dreamweaver.getDocumentPath("document");
  40.     if (filePath) {
  41.         var metaFile;
  42.         metaFile = MMNotes.open(filePath, false);
  43.         if (metaFile) {
  44.             foundNotes = true;
  45.             
  46.             var includeString = MMNotes.get(metaFile, 'MM_css_include');
  47.             var includes = (includeString == "")?new Array(0):includeString.split(',');
  48.             for (var i=0; i < includes.length; i++){
  49.                 LIST_INCLUDED.append(includes[i],includes[i]);
  50.                 LIST_INCLUDED.setIndex(0);
  51.             }
  52.  
  53.             if (LIST_INCLUDED.getLen() > 0){
  54.                 LIST_INCLUDED.setIndex(0);
  55.             }
  56.  
  57.             var excludeString = MMNotes.get(metaFile, 'MM_css_exclude');
  58.             var excludes = (excludeString == "")?new Array(0):excludeString.split(',');
  59.             for (var i=0; i < excludes.length; i++){
  60.                 LIST_EXCLUDED.append(excludes[i],excludes[i]);
  61.             }
  62.  
  63.             if (LIST_EXCLUDED.getLen() > 0){
  64.                 LIST_EXCLUDED.setIndex(0);
  65.             }
  66.  
  67.  
  68.             MMNotes.close(metaFile);
  69.         }
  70.     }
  71. }
  72.  
  73. //*********************************************************************************
  74. // doCommand()
  75. //
  76. // Called when user clicks the OK button. Updates the design note with the lists
  77. // of included and excluded style sheets.
  78. //
  79. //*********************************************************************************
  80. function doCommand(){
  81.  
  82.     // if we were called from the UI (rather than arguments passed to 
  83.     // runCommand), then save includes and excludes text for next call to the command
  84.     var path = dw.getDocumentDOM().URL;
  85.     var metaFile;
  86.     metaFile = MMNotes.open(path, true);
  87.     if (metaFile) {
  88.         if (LIST_INCLUDED.getLen() > 0){
  89.             MMNotes.set(metaFile, 'MM_css_include', LIST_INCLUDED.getValue('all'));
  90.         }else{
  91.             MMNotes.set(metaFile, 'MM_css_include', "");
  92.         }
  93.         
  94.         if (LIST_EXCLUDED.getLen() > 0){
  95.             MMNotes.set(metaFile, 'MM_css_exclude', LIST_EXCLUDED.getValue('all'));
  96.         }else{
  97.             MMNotes.set(metaFile, 'MM_css_exclude', "");
  98.         }
  99.         
  100.         MMNotes.close(metaFile);
  101.     }
  102.  
  103.     // reload the document to fresh styles
  104.     dw.getDocumentDOM().refreshViews();
  105.  
  106.     window.close();
  107. }
  108.  
  109. //*********************************************************************************
  110. // addSS()
  111. //
  112. // Called when user clicks the + button. Opens a Browse dialog box that lets the
  113. // user choose a stylesheet; when the OK button in that dialog box is clicked,
  114. // the selected stylesheet is added to the list.
  115. //
  116. // arguments:
  117. // -    theList is the ListControl object that should be updated.
  118. //
  119. //*********************************************************************************
  120. function addSS(theList){
  121.     var newStyleSheet = dw.browseForFileURL();
  122.     if (!theList.pickValue(newStyleSheet)){
  123.         if (newStyleSheet != ""){
  124.             theList.append(newStyleSheet,newStyleSheet);
  125.         }
  126.     }else{
  127.         alert(MSG_ALREADY_THERE);
  128.     }
  129. }
  130.  
  131. //*********************************************************************************
  132. // removeSS()
  133. //
  134. // Called when user clicks the + button. Opens a Browse dialog box that lets the
  135. // user choose a stylesheet; when the OK button in that dialog box is clicked,
  136. // the selected stylesheet is added to the list.
  137. //
  138. // arguments:
  139. // -    theList is the ListControl object that should be updated.
  140. //
  141. //*********************************************************************************
  142. function removeSS(theList){
  143.     theList.del();
  144. }
  145.