home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1999 Macromedia, Inc. All rights reserved.
-
- //*************** GLOBALS *****************
-
-
- var NEWLINE = (navigator.platform != "Win32") ? "\x0D" : "\x0D\x0A";
-
- var LABEL_profileStart = "-- CourseBuilder Start";
- var LABEL_profileStop = "-- CourseBuilder Stop";
-
- var CB_PROFILE = NEWLINE +
- LABEL_profileStart + NEWLINE +
- '<!ELEMENT INTERACTION >' + NEWLINE +
- '<!ATTLIST INTERACTION name object template includeSrc >' + NEWLINE +
- '<!ELEMENT CBI-SELECT >' + NEWLINE +
- '<!ATTLIST CBI-SELECT object >' + NEWLINE +
- LABEL_profileStop + NEWLINE;
-
- var LABEL_menuItemStart = "<!-- CourseBuilder Start: %s -->";
- var LABEL_menuItemStop = "<!-- CourseBuilder Stop: %s -->";
-
- var FILE_configPath = dw.getConfigurationPath();
- var FILE_commandPath = FILE_configPath + "/Commands/";
- var FILE_prefFile = FILE_configPath.substring(0, FILE_configPath.lastIndexOf('/')) + "/CourseBuilder/Config/Preferences.txt";
-
- var FILE_menuMarker = FILE_configPath + "/Menus/CourseBuilder.txt";
- var FILE_menuFile = FILE_configPath + "/Menus/menus.xml";
- var FILE_menuBackup = FILE_menuFile + ".preCourseBuilder";
-
- var FILE_profileMarker = FILE_configPath + "/BrowserProfiles/CourseBuilder.txt";
- var FILE_profileDir = FILE_configPath + "/BrowserProfiles/";
-
- var MSG_menuMarkerContents = '';
- var MSG_profileMarkerContents = '';
-
-
- //******************* API **********************
-
- function initialize() {
- if (DWfile.exists(FILE_prefFile)) {
- // update menu items and register for events
- updateMenus();
- updateProfiles();
-
- if (DWfile.exists(FILE_commandPath + 'Paste Interaction.htm'))
- MM.event.registerFnCall('dw.clipPaste()', 'Paste Interaction.htm');
- if (DWfile.exists(FILE_commandPath + 'Cut Interaction.htm'))
- MM.event.registerFnCall('dw.clipCut()', 'Cut Interaction.htm');
- if (DWfile.exists(FILE_commandPath + 'Clear Interaction.htm'))
- MM.event.registerFnCall('dw.deleteSelection()', 'Clear Interaction.htm');
- } else {
- // Remove menu items and delete this file
- if (clearMenus() && clearProfiles())
- removeFiles();
- }
- }
-
-
- //***************** LOCAL FUNCTIONS ******************
-
- function updateMenus() {
- var menuDOM, menusChanged = false;
- if (!DWfile.exists(FILE_menuMarker)) {
- menuDOM = dw.getDocumentDOM(FILE_menuFile);
- DWfile.write(FILE_menuBackup, menuDOM.body.innerHTML); // backup menus.xml
-
- // insert the edit statements here
- menusChanged = menuInsert(menuDOM, "DWMenu_Insert", 0, CB_INSERT) || menusChanged;
- menusChanged = menuInsert(menuDOM, "DWMenu_Modify", "DWMenu_Modify_Timeline", CB_MODIFY) || menusChanged;
- menusChanged = menuInsert(menuDOM, "DWMenu_Help", "DWMenu_Help_ExtendingDW", CB_HELP) || menusChanged;
- menusChanged = menuInsert(menuDOM, "DWMenu_MainSite_Help", "DWMenu_MainSite_Help_ExtendingDW", CB_SITEHELP) || menusChanged;
-
- if (menusChanged && DWfile.write(FILE_menuFile, menuDOM.body.innerHTML)) {
- DWfile.write(FILE_menuMarker, MSG_menuMarkerContents);
- } else if (menusChanged) {
- alert(MSG_menuFileUpdateFailed.replace(/%s/, MMNotes.localURLToFilePath(FILE_menuFile)));
- } else {
- // re-write the marker file
- DWfile.write(FILE_menuMarker, MSG_menuMarkerContents);
- }
- dw.releaseDocument(menuDOM);
- }
- }
-
-
- function menuInsert(menuDOM, menuId, insertAfterIdOrIndex, data) {
- var menuList, insertList, index, insertAfterId, retVal=false;
- var insertItem='', insertBefore=false;
- var startLabel = LABEL_menuItemStart.replace(/%s/g, menuId);
- var stopLabel = LABEL_menuItemStop.replace(/%s/g, menuId);
- var insertData = startLabel + NEWLINE + data + NEWLINE + stopLabel + NEWLINE;
- MSG_menuMarkerContents += insertData + NEWLINE + NEWLINE;
- if (menuDOM.body.innerHTML.indexOf(startLabel) == -1) {
- menuList = menuDOM.getElementsByTagName("MENU");
- for (var i=0; !retVal && i < menuList.length; i++) {
- if (menuList[i].getAttribute("ID") == menuId) {
- if (insertAfterIdOrIndex == parseInt(insertAfterIdOrIndex).toString()) {
- index = insertAfterIdOrIndex;
- if (index > 0) {
- insertItem = menuList[i].childNodes[index];
- } else if (index < 0) {
- insertItem = menuList[i].childNodes[menuList[i].childNodes.length + index];
- } else {
- insertItem = menuList[i].childNodes[0];
- insertBefore = true;
- }
- } else {
- insertAfterId = insertAfterIdOrIndex;
- insertList = menuList[i].getElementsByTagName("MENUITEM");
- for (var j=0; !insertItem && j < insertList.length; j++) {
- if (insertList[j].getAttribute("ID") == insertAfterId)
- insertItem = insertList[j];
- }
- if (!insertItem) {
- insertList = menuList[i].getElementsByTagName("MENU");
- for (var j=0; !insertItem && j < insertList.length; j++) {
- if (insertList[j].getAttribute("ID") == insertAfterId)
- insertItem = insertList[j];
- } }
- }
- if (insertItem) {
- if (insertBefore)
- insertItem.outerHTML = insertData + insertItem.outerHTML;
- else
- insertItem.outerHTML = insertItem.outerHTML + insertData;
- retVal = true;
- } } } }
- return retVal;
- }
-
-
- function clearMenus() {
- var retVal = true;
- var menuInfoOrig, menuInfo;
- if (DWfile.exists(FILE_menuFile)) {
- menuInfoOrig = DWfile.read(FILE_menuFile);
- menuInfo = menuInfoOrig;
-
- // insert the removal statements here
- menuInfo = clearMenu(menuInfo, "DWMenu_Insert");
- menuInfo = clearMenu(menuInfo, "DWMenu_Modify");
- menuInfo = clearMenu(menuInfo, "DWMenu_Help");
- menuInfo = clearMenu(menuInfo, "DWMenu_MainSite_Help");
-
- if (menuInfo != menuInfoOrig) {
- if (DWfile.write(FILE_menuFile, menuInfo)) {
- if (DWfile.exists(FILE_menuMarker)) DWfile.remove(FILE_menuMarker);
- } else {
- retVal = false;
- alert(MSG_menuFileDeleteFailed.replace(/%s/, MMNotes.localURLToFilePath(FILE_menuFile)));
- }
- }
- }
- return retVal;
- }
-
- function clearMenu(menuInfo, menuId) {
- var startIndex, stopIndex;
- var startLabel = LABEL_menuItemStart.replace(/%s/g, menuId);
- var stopLabel = LABEL_menuItemStop.replace(/%s/g, menuId);
- startIndex = menuInfo.indexOf(startLabel);
- stopIndex = menuInfo.indexOf(stopLabel);
- if (startIndex != -1 && stopIndex != -1 && startIndex < stopIndex) {
- stopIndex += stopLabel.length;
- menuInfo = menuInfo.substring(0, startIndex) + menuInfo.substring(stopIndex);
- }
- return menuInfo;
- }
-
-
-
- function updateProfiles() {
- if (!DWfile.exists(FILE_profileMarker)) {
-
- // insert the file edit statements here
- fileInsert(FILE_profileDir + "Navigator_3.0.txt", CB_PROFILE);
- fileInsert(FILE_profileDir + "Navigator_4.0.txt", CB_PROFILE);
- fileInsert(FILE_profileDir + "Internet_Explorer_3.0.txt", CB_PROFILE);
- fileInsert(FILE_profileDir + "Internet_Explorer_4.0.txt", CB_PROFILE);
- fileInsert(FILE_profileDir + "Internet_Explorer_5.0.txt", CB_PROFILE);
-
- MSG_profileMarkerContents = CB_PROFILE;
- DWfile.write(FILE_profileMarker, MSG_profileMarkerContents);
- }
- }
-
- function fileInsert(fileName, data) {
- var retVal = false;
- if (DWfile.write(fileName, data, "append")) retVal = true;
- return retVal;
- }
-
- function clearProfiles(fileInfo) {
- var retVal = true;
-
- // insert the file clear statements here
- fileClear(FILE_profileDir + "Navigator_3.0.txt", LABEL_profileStart, LABEL_profileStop);
- fileClear(FILE_profileDir + "Navigator_4.0.txt", LABEL_profileStart, LABEL_profileStop);
- fileClear(FILE_profileDir + "Internet_Explorer_3.0.txt", LABEL_profileStart, LABEL_profileStop);
- fileClear(FILE_profileDir + "Internet_Explorer_4.0.txt", LABEL_profileStart, LABEL_profileStop);
- fileClear(FILE_profileDir + "Internet_Explorer_5.0.txt", LABEL_profileStart, LABEL_profileStop);
-
- if (DWfile.exists(FILE_profileMarker)) DWfile.remove(FILE_profileMarker);
- return retVal;
- }
-
- function fileClear(fileName, labelStart, labelStop) {
- var retVal = false;
- var startIndex, stopIndex;
- var fileInfo = DWfile.read(fileName);
- startIndex = fileInfo.indexOf(labelStart);
- stopIndex = fileInfo.indexOf(labelStop);
- if (startIndex != -1 && stopIndex != -1 && startIndex < stopIndex) {
- stopIndex += labelStop.length;
- fileInfo = fileInfo.substring(0, startIndex) + fileInfo.substring(stopIndex);
- if (DWfile.write(fileName, fileInfo)) retVal = true;
- }
- return retVal;
- }
-
-
- function removeFiles() {
- if (DWfile.exists(FILE_configPath + "/Startup/CourseBuilderInit.htm")) {
- if (DWfile.write(FILE_configPath + "/Startup/CourseBuilderInit.htm", "<HTML><HEAD></HEAD><BODY></BODY></HTML>")) {
- if (DWfile.exists(FILE_configPath + "/Startup/CourseBuilderInit.js"))
- DWfile.remove(FILE_configPath + "/Startup/CourseBuilderInit.js");
- } }
- }