home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2 (Special) / PCPro-2b.iso / Demos / Macromedia / CourseBuilder / CourseBuilderInstaller.exe / Disk1 / data1.cab / Dreamweaver-leaveBehind / Configuration / Startup / CourseBuilderInit.js < prev   
Encoding:
JavaScript  |  1999-12-06  |  8.9 KB  |  228 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS  *****************
  4.  
  5.  
  6. var NEWLINE = (navigator.platform != "Win32") ? "\x0D" : "\x0D\x0A";
  7.  
  8. var LABEL_profileStart = "-- CourseBuilder Start";
  9. var LABEL_profileStop  = "-- CourseBuilder Stop";
  10.  
  11. var CB_PROFILE = NEWLINE +
  12.   LABEL_profileStart + NEWLINE +
  13.   '<!ELEMENT INTERACTION >' + NEWLINE +
  14.   '<!ATTLIST INTERACTION name object template includeSrc >' + NEWLINE +
  15.   '<!ELEMENT CBI-SELECT >' + NEWLINE +
  16.   '<!ATTLIST CBI-SELECT object >' + NEWLINE +
  17.   LABEL_profileStop + NEWLINE;
  18.  
  19. var LABEL_menuItemStart = "<!-- CourseBuilder Start: %s -->";
  20. var LABEL_menuItemStop  = "<!-- CourseBuilder Stop: %s -->";
  21.  
  22. var FILE_configPath = dw.getConfigurationPath();
  23. var FILE_commandPath = FILE_configPath + "/Commands/";
  24. var FILE_prefFile   = FILE_configPath.substring(0, FILE_configPath.lastIndexOf('/')) + "/CourseBuilder/Config/Preferences.txt";
  25.  
  26. var FILE_menuMarker = FILE_configPath + "/Menus/CourseBuilder.txt";
  27. var FILE_menuFile   = FILE_configPath + "/Menus/menus.xml";
  28. var FILE_menuBackup = FILE_menuFile + ".preCourseBuilder";
  29.  
  30. var FILE_profileMarker = FILE_configPath + "/BrowserProfiles/CourseBuilder.txt";
  31. var FILE_profileDir    = FILE_configPath + "/BrowserProfiles/";
  32.  
  33. var MSG_menuMarkerContents = '';
  34. var MSG_profileMarkerContents = '';
  35.  
  36.  
  37. //******************* API **********************
  38.  
  39. function initialize() {
  40.   if (DWfile.exists(FILE_prefFile)) {
  41.     // update menu items and register for events
  42.     updateMenus();
  43.     updateProfiles();
  44.  
  45.     if (DWfile.exists(FILE_commandPath + 'Paste Interaction.htm'))
  46.       MM.event.registerFnCall('dw.clipPaste()', 'Paste Interaction.htm');
  47.     if (DWfile.exists(FILE_commandPath + 'Cut Interaction.htm'))
  48.       MM.event.registerFnCall('dw.clipCut()', 'Cut Interaction.htm');
  49.     if (DWfile.exists(FILE_commandPath + 'Clear Interaction.htm'))
  50.       MM.event.registerFnCall('dw.deleteSelection()', 'Clear Interaction.htm');
  51.   } else {
  52.     // Remove menu items and delete this file
  53.     if (clearMenus() && clearProfiles())
  54.       removeFiles();
  55.   }
  56. }
  57.  
  58.  
  59. //***************** LOCAL FUNCTIONS  ******************
  60.  
  61. function updateMenus() {
  62.   var menuDOM, menusChanged = false;
  63.   if (!DWfile.exists(FILE_menuMarker)) {
  64.     menuDOM = dw.getDocumentDOM(FILE_menuFile);
  65.     DWfile.write(FILE_menuBackup, menuDOM.body.innerHTML); // backup menus.xml
  66.  
  67.     // insert the edit statements here
  68.     menusChanged = menuInsert(menuDOM, "DWMenu_Insert", 0, CB_INSERT) || menusChanged;
  69.     menusChanged = menuInsert(menuDOM, "DWMenu_Modify", "DWMenu_Modify_Timeline", CB_MODIFY) || menusChanged;
  70.     menusChanged = menuInsert(menuDOM, "DWMenu_Help", "DWMenu_Help_ExtendingDW", CB_HELP) || menusChanged;
  71.     menusChanged = menuInsert(menuDOM, "DWMenu_MainSite_Help", "DWMenu_MainSite_Help_ExtendingDW", CB_SITEHELP) || menusChanged;
  72.  
  73.     if (menusChanged && DWfile.write(FILE_menuFile, menuDOM.body.innerHTML)) {
  74.       DWfile.write(FILE_menuMarker, MSG_menuMarkerContents);
  75.     } else if (menusChanged) {
  76.       alert(MSG_menuFileUpdateFailed.replace(/%s/, MMNotes.localURLToFilePath(FILE_menuFile)));
  77.     } else {
  78.       // re-write the marker file
  79.       DWfile.write(FILE_menuMarker, MSG_menuMarkerContents);
  80.     }
  81.     dw.releaseDocument(menuDOM);
  82.   }
  83. }
  84.  
  85.  
  86. function menuInsert(menuDOM, menuId, insertAfterIdOrIndex, data) {
  87.   var menuList, insertList, index, insertAfterId, retVal=false; 
  88.   var insertItem='', insertBefore=false;
  89.   var startLabel = LABEL_menuItemStart.replace(/%s/g, menuId);
  90.   var stopLabel  = LABEL_menuItemStop.replace(/%s/g, menuId);
  91.   var insertData = startLabel + NEWLINE + data + NEWLINE + stopLabel + NEWLINE;
  92.   MSG_menuMarkerContents += insertData + NEWLINE + NEWLINE;
  93.   if (menuDOM.body.innerHTML.indexOf(startLabel) == -1) {
  94.     menuList = menuDOM.getElementsByTagName("MENU");
  95.     for (var i=0; !retVal && i < menuList.length; i++) {
  96.       if (menuList[i].getAttribute("ID") == menuId) {
  97.         if (insertAfterIdOrIndex == parseInt(insertAfterIdOrIndex).toString()) {
  98.           index = insertAfterIdOrIndex;
  99.           if (index > 0) {
  100.             insertItem = menuList[i].childNodes[index];
  101.           } else if (index < 0) {
  102.             insertItem = menuList[i].childNodes[menuList[i].childNodes.length + index];
  103.           } else {
  104.             insertItem = menuList[i].childNodes[0];
  105.             insertBefore = true;
  106.           }
  107.         } else {
  108.           insertAfterId = insertAfterIdOrIndex;
  109.           insertList = menuList[i].getElementsByTagName("MENUITEM");
  110.           for (var j=0; !insertItem && j < insertList.length; j++) {
  111.             if (insertList[j].getAttribute("ID") == insertAfterId)
  112.               insertItem = insertList[j];
  113.           }
  114.           if (!insertItem) {
  115.             insertList = menuList[i].getElementsByTagName("MENU");
  116.             for (var j=0; !insertItem && j < insertList.length; j++) {
  117.               if (insertList[j].getAttribute("ID") == insertAfterId)
  118.                 insertItem = insertList[j];
  119.           } }
  120.         }
  121.         if (insertItem) {
  122.           if (insertBefore)
  123.             insertItem.outerHTML = insertData + insertItem.outerHTML;
  124.           else
  125.             insertItem.outerHTML = insertItem.outerHTML + insertData;
  126.           retVal = true;
  127.   } } } }
  128.   return retVal;
  129. }
  130.  
  131.  
  132. function clearMenus() {
  133.   var retVal = true;
  134.   var menuInfoOrig, menuInfo;
  135.   if (DWfile.exists(FILE_menuFile)) {
  136.     menuInfoOrig = DWfile.read(FILE_menuFile);
  137.     menuInfo = menuInfoOrig;
  138.     
  139.     // insert the removal statements here
  140.     menuInfo = clearMenu(menuInfo, "DWMenu_Insert");
  141.     menuInfo = clearMenu(menuInfo, "DWMenu_Modify");
  142.     menuInfo = clearMenu(menuInfo, "DWMenu_Help");
  143.     menuInfo = clearMenu(menuInfo, "DWMenu_MainSite_Help");
  144.     
  145.     if (menuInfo != menuInfoOrig) {
  146.       if (DWfile.write(FILE_menuFile, menuInfo)) {
  147.         if (DWfile.exists(FILE_menuMarker)) DWfile.remove(FILE_menuMarker);
  148.       } else {
  149.         retVal = false;
  150.         alert(MSG_menuFileDeleteFailed.replace(/%s/, MMNotes.localURLToFilePath(FILE_menuFile)));
  151.       }
  152.     }
  153.   }
  154.   return retVal;
  155. }
  156.  
  157. function clearMenu(menuInfo, menuId) {
  158.   var startIndex, stopIndex;
  159.   var startLabel = LABEL_menuItemStart.replace(/%s/g, menuId);
  160.   var stopLabel  = LABEL_menuItemStop.replace(/%s/g, menuId);
  161.   startIndex = menuInfo.indexOf(startLabel);
  162.   stopIndex = menuInfo.indexOf(stopLabel);
  163.   if (startIndex != -1 && stopIndex != -1 && startIndex < stopIndex) {
  164.     stopIndex += stopLabel.length;
  165.     menuInfo = menuInfo.substring(0, startIndex) + menuInfo.substring(stopIndex);
  166.   }
  167.   return menuInfo;
  168. }
  169.  
  170.  
  171.  
  172. function updateProfiles() {
  173.   if (!DWfile.exists(FILE_profileMarker)) {
  174.   
  175.     // insert the file edit statements here
  176.     fileInsert(FILE_profileDir + "Navigator_3.0.txt", CB_PROFILE);
  177.     fileInsert(FILE_profileDir + "Navigator_4.0.txt", CB_PROFILE);
  178.     fileInsert(FILE_profileDir + "Internet_Explorer_3.0.txt", CB_PROFILE);
  179.     fileInsert(FILE_profileDir + "Internet_Explorer_4.0.txt", CB_PROFILE);
  180.     fileInsert(FILE_profileDir + "Internet_Explorer_5.0.txt", CB_PROFILE);
  181.  
  182.     MSG_profileMarkerContents = CB_PROFILE;
  183.     DWfile.write(FILE_profileMarker, MSG_profileMarkerContents);
  184.   }
  185. }
  186.  
  187. function fileInsert(fileName, data) {
  188.   var retVal = false;
  189.   if (DWfile.write(fileName, data, "append")) retVal = true;
  190.   return retVal;
  191. }
  192.  
  193. function clearProfiles(fileInfo) {
  194.   var retVal = true;
  195.   
  196.   // insert the file clear statements here
  197.   fileClear(FILE_profileDir + "Navigator_3.0.txt", LABEL_profileStart, LABEL_profileStop);
  198.   fileClear(FILE_profileDir + "Navigator_4.0.txt", LABEL_profileStart, LABEL_profileStop);
  199.   fileClear(FILE_profileDir + "Internet_Explorer_3.0.txt", LABEL_profileStart, LABEL_profileStop);
  200.   fileClear(FILE_profileDir + "Internet_Explorer_4.0.txt", LABEL_profileStart, LABEL_profileStop);
  201.   fileClear(FILE_profileDir + "Internet_Explorer_5.0.txt", LABEL_profileStart, LABEL_profileStop);
  202.  
  203.   if (DWfile.exists(FILE_profileMarker)) DWfile.remove(FILE_profileMarker);
  204.   return retVal;
  205. }
  206.  
  207. function fileClear(fileName, labelStart, labelStop) {
  208.   var retVal = false;
  209.   var startIndex, stopIndex;
  210.   var fileInfo = DWfile.read(fileName);
  211.   startIndex = fileInfo.indexOf(labelStart);
  212.   stopIndex = fileInfo.indexOf(labelStop);
  213.   if (startIndex != -1 && stopIndex != -1 && startIndex < stopIndex) {
  214.     stopIndex += labelStop.length;
  215.     fileInfo = fileInfo.substring(0, startIndex) + fileInfo.substring(stopIndex);
  216.     if (DWfile.write(fileName, fileInfo)) retVal = true;
  217.   }
  218.   return retVal;
  219. }
  220.  
  221.  
  222. function removeFiles() {
  223.   if (DWfile.exists(FILE_configPath + "/Startup/CourseBuilderInit.htm")) {
  224.     if (DWfile.write(FILE_configPath + "/Startup/CourseBuilderInit.htm", "<HTML><HEAD></HEAD><BODY></BODY></HTML>")) {
  225.       if (DWfile.exists(FILE_configPath + "/Startup/CourseBuilderInit.js"))
  226.         DWfile.remove(FILE_configPath + "/Startup/CourseBuilderInit.js");
  227.   } }
  228. }