home *** CD-ROM | disk | FTP | other *** search
/ internet.au CDrom 42 / NETCD42.iso / web / w95 / dream2.exe / data1.cab / Program_Files / Configuration / Behaviors / Actions / Swap Image.js < prev    next >
Encoding:
JavaScript  |  1998-11-30  |  21.2 KB  |  539 lines

  1. //*************** GLOBALS VARS *****************
  2.  
  3.  
  4. //******************* BEHAVIOR FUNCTIONS **********************
  5.  
  6. //Changes multiple images at once. Accepts a variable number of args in triplets as follows:
  7. //  objStrNS - Javascript object ref for Netscape (ex: document.layers['foo'].document.myImage)
  8. //  objStrIE - JScript object reference for Internet Explorer (ex: document.all['myImage'])
  9. //  imgURL   - an image filename, URL encoded. (ex: file.gif, http://www.x.com/y.gif)
  10. //
  11. //Tests for browser, and uses the first object string for NS, the second for IE.
  12. //Sets the image src property to the new filename: document.myImage.src = file.gif.
  13. //Fails gracefully on older browsers by ensuring the the object exists.
  14. //If the image is in a layer, fixes the reference so it works. It doesn't hurt
  15. //to set image.src in a browser (IE3) even if nothing changes.
  16. //The rest of the code is to support another Action, Swap Image Restore.
  17. //Builds an array of the original src values and saves it to a global property,
  18. //in the form of theObj,theObj.src,.... Prevents overwriting these values if called
  19. //repeatedly, to ensure we use the original src file set in the HTML.
  20.  
  21. function MM_swapImage() { //v2.0
  22.   var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  23.   for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
  24.     objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
  25.     if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
  26.         (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
  27.       objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
  28.     obj = eval(objStr);
  29.     if (obj != null) {
  30.       swapArray[j++] = obj;
  31.       swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
  32.       obj.src = MM_swapImage.arguments[i+2];
  33.   } }
  34.   document.MM_swapImgData = swapArray; //used for restore
  35. }
  36.  
  37.  
  38.  
  39. //Restores a set of images to their previous source files.
  40. //Accepts a variable number of params, in pairs read from a global property:
  41. //  objStr - Javascript object ref for an image (ex: document.myImage)
  42. //  imgURL - original image filename, URL encoded. (ex: file.gif, http://www.x.com/y.gif)
  43. //
  44. //This is the companion Action to Swap Image. Swap Image gathers the original
  45. //image src filenames, and writes document.MM_swapImageData before changing the images.
  46. //This sets the images src properties back to their original filenames:
  47. //  document.myImage.src = file.gif.
  48.  
  49. function MM_swapImgRestore() { //v2.0
  50.   if (document.MM_swapImgData != null)
  51.     for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
  52.       document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
  53. }
  54.  
  55.  
  56.  
  57. //Preloads multiple images files in order. Accepts a variable number of args
  58. //(each should be quoted):
  59. //  imgURL   - an image filename, URL encoded. (ex: file.gif, http://www.x.com/y.gif)
  60. //
  61. //Creates a new array of Image objects. With each one, it assigns an image source
  62. //from the argument list. These are downloaded essentially simultaneously into the
  63. //client cache. When the user needs a new image file (for example: they go to the
  64. //next web page), the browser should quickly find this image in the cache.
  65. //!!! IMPORTANT !!! This function is also defined in file "Preload Images.htm".
  66. //Any edits must be made there as well as here.
  67.  
  68. function MM_preloadImages() { //v2.0
  69.   if (document.images) {
  70.     var imgFiles = MM_preloadImages.arguments;
  71.     if (document.preloadArray==null) document.preloadArray = new Array();
  72.     var i = document.preloadArray.length;
  73.     with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
  74.       preloadArray[i] = new Image;
  75.       preloadArray[i++].src = imgFiles[j];
  76.   } }
  77. }
  78.  
  79. //******************* API **********************
  80.  
  81.  
  82. //Checks for the existence of images.
  83. //If none exist, returns false so this Action is grayed out.
  84.  
  85. function canAcceptBehavior(){
  86.  
  87.   var retVal = "";
  88.   if (createObjRefs()) {
  89.     retVal = "onMouseOver";
  90.   }
  91.   if (retVal)
  92.     return retVal;
  93.   return false;
  94. }
  95.  
  96.  
  97.  
  98. //Returns Javascript functions to be inserted in HTML head with script tags.
  99.  
  100. function behaviorFunction(){       
  101.   return "MM_preloadImages,MM_swapImgRestore,MM_swapImage"
  102. }
  103.  
  104.  
  105.  
  106. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  107. //Gets list of imgSrcs from doc attribute. With each imgSrc, it gets the parallel
  108. //img name from select 'menu'. Each imgSrc & imgObj are embedded as args.
  109. function applyBehavior() {
  110.   var retVal="",i,j,argList="",imgList="",fnArray,imgSrcArray,imgSrc,imgObj,imgObjIE,newName;
  111.   var imgArray = new Array(),imgObjsArray=document.MM_imgObjsArray;
  112.  
  113.   imgSrcArray = document.MM_myImgSrcs;      //get global list of imgSrcs
  114.   for (i=0; i<imgSrcArray.length; i++) {    //with each imgSrc
  115.     imgSrc = imgSrcArray[i];
  116.     if (imgSrc) {      //if not empty
  117.       if (argList) argList += ",";    //if stuff already in list, add comma
  118.       if (document.MM_NS_REFS[i].indexOf(REF_UNNAMED)==0){  //if the image is unnamed
  119.         //from this array, get unique image name
  120.         newName = getUniqueName("IMG","Image",imgObjsArray); 
  121.         imgObjsArray[i].setAttribute("name",newName); //rename image in document
  122.         createObjRefs(); //re-create refs based on new image name
  123.       }
  124.       imgObjIE = document.MM_IE_REFS[i]; // get IE ref
  125.       imgObjNS = document.MM_NS_REFS[i]; //get NS ref
  126.       argList += "'"+escQuotes(imgObjNS)+"','"+escQuotes(imgObjIE)+"','"+escape(imgSrc)+"'";
  127.       imgList += (imgList?",":"")+"'"+escape(imgSrc)+"'";
  128.       imgArray[imgArray.length] = "'"+escape(imgSrc)+"'"; //add string to list
  129.     }
  130.   }
  131.   if (!argList) retVal = MSG_NoImgsSelected;
  132.   else { //OK
  133.     //Add or remove MM_swapImgRestore() based on checkbox setting
  134.     selObj = dreamweaver.getBehaviorElement();
  135.     if (!selObj){
  136.       selArr = dreamweaver.getSelection();
  137.       selObj = dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  138.     
  139.     }
  140.      if (document.theForm.restore) {
  141.       if (document.theForm.restore.checked) { //add restore to onMouseOut handler
  142.         setHandler(selObj,'onMouseOut','MM_swapImgRestore()');
  143.       } else { //remove it
  144.         delHandler(selObj,'onMouseOut','MM_swapImgRestore');
  145.       }
  146.     }
  147.  
  148.     //Add or remove MM_preloadImages() based on checkbox setting
  149.     var obj = dreamweaver.getDocumentDOM("document").body;
  150.     if (document.theForm.preload.checked) { //add preload call to onLoad handler
  151.       argList += ",\'"+document.preloadId+"\'"; //add uniqueName to main fn call
  152.       setHandler(obj,"onLoad","MM_preloadImages("+imgList+",'"+document.preloadId+"')",document.preloadId);
  153.     } else {
  154.       delHandler(obj,"onLoad","MM_preloadImages",document.preloadId);
  155.     }
  156.  
  157.     retVal = "MM_swapImage("+argList+")";  //create correct function call
  158.   }
  159.   return retVal
  160. }
  161.  
  162.  
  163. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  164. //call arguments. This information is used by DW to fixup behavior args when the
  165. //document is moved or changed.
  166. //
  167. //It is passed an actual function call string generated by applyBehavior(), which
  168. //may have a variable list of arguments, and this should return a matching mask.
  169. //
  170. //The return values are:
  171. //  URL     : argument could be a file path, which DW will update during Save As...
  172. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  173. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  174. //  other...: argument is ignored
  175.  
  176. function identifyBehaviorArguments(fnCallStr) {
  177.   var argList, argArray, numArgGroups, i;
  178.  
  179.   argList = "";
  180.   argArray = extractArgs(fnCallStr);
  181.   numArgGroups = (argArray.length - 1) / 3; //args come in triplets
  182.   for (i=0; i<numArgGroups; i++) {          //with each NSobj,IEobj,URL triplet
  183.     argList += ((argList)?",":"")+"NS4.0ref,IE4.0ref,DEP";
  184.   }
  185.   return argList;
  186. }
  187.  
  188.  
  189.  
  190. //Given the original function call, this parses out the args and updates
  191. //the UI. Loops through each imgObj,imgSrc pair.
  192. //If imgObj already present in menu, stuff imgSrc in imgSrcArray. If imgObj
  193. //doesn't exist, add to menu, and extend imgSrcArray.
  194.  
  195. function inspectBehavior(behFnCallStr){
  196.   var argArray,imgSrcArray,found,numImgs,i,imgObj,imgSrc,j,imgObjNum;
  197.  
  198.   argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
  199.   imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
  200.   numImgs = document.MM_NS_REFS.length;
  201.   for (i=1; i<(argArray.length-2); i+=3){ //with each imgObj,imgSrc pair
  202.     imgObj=unescQuotes(argArray[i]);
  203.     imgSrc=unescape(argArray[i+2]);
  204.     found = false;
  205.     for (j=0; j<numImgs; j++){  //check if imgObj is in ref list
  206.       if (document.MM_NS_REFS[j] == imgObj) { //if imgObj there
  207.         imgSrcArray[j] = imgSrc;              //store imgSrc at that pos
  208.         if (imgSrc) addStarToMenuItem(document.theForm.menu,j);//if non-empty, mark with  *
  209.         found = true;
  210.         break;
  211.       }
  212.     }
  213.     if (!found) alert(errMsg(MSG_ImgNotFound,imgObj,imgSrc)); //if image name not found
  214.   }
  215.   document.MM_myImgSrcs = imgSrcArray; //save updated imageSrc list
  216.   displayImgSrc();         //load the imageSrc for selected image
  217.  
  218.   //Determine if preloading, get id
  219.   if (i < argArray.length) document.preloadId = argArray[i]; //unique id exists, get it
  220.   document.theForm.preload.checked = (argArray.length > i); //if preload, check box
  221.  
  222.   //If restore checkbox is available, see if MM_swapImgRestore() exists, and check the box
  223.   var theObj = findObject("restoreOption");
  224.   if (theObj) { //restore checkbox is a possibility
  225.     var selObj=dreamweaver.getBehaviorElement();
  226.     if (selObj && selObj.tagName != "A") selObj = selObj.parentNode; //move out to A tag if needed
  227.     if (selObj && selObj.tagName == "A") if (document.theForm.restore) {
  228.       document.theForm.restore.checked = getHandler(selObj,'onMouseOut','MM_swapImgRestore');
  229.     }
  230.   }
  231. }
  232.  
  233.  
  234.  
  235. //Given the original function call, this parses out the args and updates
  236. //the code. If there's a preload id at the end of the arglist, deletes
  237. //the preload handler. If there's a swap restore call, deletes that.
  238.  
  239. function deleteBehavior(behFnCallStr){
  240.   var argArray,obj,selArr,selObj;
  241.  
  242.   //Maybe remove preload handler
  243.   argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
  244.   if ((argArray.length-1)%3 == 1) { //if extra arg
  245.     document.preloadId = argArray[argArray.length-1]; //unique id exists, get it
  246.     obj = dreamweaver.getDocumentDOM("document").body;
  247.     if (obj.innerHTML.indexOf(document.preloadId) == -1) // if swap image not just moved
  248.       delHandler(obj,"onLoad","MM_preloadImages",document.preloadId);
  249.   }
  250.  
  251.   //Maybe remove swap restore handler
  252.   selObj=dreamweaver.getBehaviorElement();
  253.   if (selObj && selObj.tagName != "A") selObj = selObj.parentNode; //move out to A tag if needed
  254.   if (selObj && selObj.tagName == "A") if (selObj.outerHTML.indexOf("MM_swapImage(") == -1) {
  255.     delHandler(selObj,'onMouseOut','MM_swapImgRestore');
  256.   }
  257. }
  258.  
  259.  
  260.  
  261. //***************** LOCAL FUNCTIONS  ******************
  262.  
  263. //Load the select menu with image names.
  264. //Also sets the global property MM_myImgSrcs to the right num of items.
  265.  
  266. function initializeUI(){
  267.   var niceNameSrcArray, nameArray, i, selTag="";
  268.   var imgSrcArray = new Array();
  269.  
  270.   //Determine if RESTORE is an option. If not, remove UI for it
  271.   //the dreamweaver.getBehaviorTag() check ensures the checkbox
  272.   //is not available if a behavior is attached to a timeline
  273.       var removeCheckbox = false;
  274.       if (!dreamweaver.getBehaviorTag() )  //if behavior is in a timeline
  275.         removeCheckbox = true;
  276.       else{
  277.         if (dreamweaver.getBehaviorElement()) selTag = dreamweaver.getBehaviorElement().tagName;
  278.         if (!selTag) selTag = getSelectionTag();
  279.         if (selTag!="A" && selTag!="IMG")  //if sel not A or IMG
  280.           removeCheckbox = true;
  281.       }  
  282.       if (removeCheckbox){
  283.         var theObj = findObject("restoreOption");
  284.         if (theObj) theObj.outerHTML = ""; //remove restoreOption checkbox
  285.       }
  286.   
  287.  
  288.   //Create unique ID in case of preload
  289.   document.preloadId = "#"+((new Date()).getTime());
  290.  
  291.   //Build and load picklist of images
  292.   createObjRefs();
  293.   niceNameSrcArray = document.MM_NS_REFS;
  294.   //Search for unreferenceable objects. <DIV id="foo"> is IE only, <LAYER> is NS only.
  295.   //if REF_CANNOT found, return empty string, and use IE refs for nice namelist.
  296.   for (i=0; i<document.MM_NS_REFS.length; i++) {
  297.     if (document.MM_IE_REFS[i].indexOf(REF_CANNOT) == 0) {
  298.       document.MM_IE_REFS[i] = ""; //blank it out
  299.     }
  300.     if (document.MM_NS_REFS[i].indexOf(REF_CANNOT) == 0) {
  301.       document.MM_NS_REFS[i] = ""; //blank it out
  302.       niceNameSrcArray = document.MM_IE_REFS; //use the IE list
  303.     }
  304.   }
  305.   nameArray = niceNames(niceNameSrcArray,TYPE_Image);
  306.   for (i=0; i<nameArray.length; i++){
  307.     document.theForm.menu.options[i]=new Option(nameArray[i]); //load menu
  308.     imgSrcArray[i] = "";
  309.   }
  310.   pickSelectedImage(); //if an image is selected, selects it in the picklist
  311.   document.MM_myImgSrcs = imgSrcArray; //set global
  312.  
  313.   document.theForm.imgSrc.focus(); //set focus on textbox
  314.   document.theForm.imgSrc.select(); //set insertion point into textbox
  315. }
  316.  
  317.  
  318.  
  319. //Creates arrays of all images, including those in other frames.
  320. //If none found, returns false.
  321.  
  322. function createObjRefs(){
  323.   document.MM_NS_REFS = getAllObjectRefs("NS 4.0","IMG");
  324.   document.MM_IE_REFS = getAllObjectRefs("IE 4.0","IMG");
  325.  
  326.   return (document.MM_NS_REFS.length >0)
  327. }
  328.  
  329.  
  330.  
  331. //Given imageSrc in form, looks up the menu's selection number, and stores the
  332. //new imageSrc at that position in the global document property "MM_myImgSrcs".
  333.  
  334. function storeImgSrc(){
  335.   var newImgSrc, imgSrcArray, menuIndex, newMenuText;
  336.  
  337.   newImgSrc = document.theForm.imgSrc.value;
  338.   imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
  339.   menuIndex = document.theForm.menu.selectedIndex; //get index to swap
  340.   imgSrcArray[menuIndex] = newImgSrc;   //swap
  341.   document.MM_myImgSrcs = imgSrcArray;   //rewrite list
  342.   if (newImgSrc) {  //if non-empty, mark with  *
  343.     addStarToMenuItem(document.theForm.menu, menuIndex);
  344.   } else { //nothing to store, strip off any previous star
  345.     newMenuText = stripStar(document.theForm.menu.options[menuIndex].text); //remove if old star
  346.     document.theForm.menu.options[menuIndex]=new Option(newMenuText); //add new line to menu
  347.   }
  348.   document.theForm.menu.selectedIndex = menuIndex; //reset selection index
  349. }
  350.  
  351.  
  352.  
  353. //Looks at the menu of names, and returns the imgSrc associated with the
  354. //selected item. Example: if the 2nd menu item's selected, returns 2nd item
  355. //stored in property "MM_myImgSrcs".
  356.  
  357. function displayImgSrc(){
  358.   var imgSrcArray, curImageSrcNum, imgSrc;
  359.  
  360.   imgSrcArray = document.MM_myImgSrcs; //get the list of imgSrcs
  361.   curImageSrcNum = document.theForm.menu.selectedIndex; //get index selected
  362.   imgSrc = imgSrcArray[curImageSrcNum];   //lookup imgSrc
  363.   document.theForm.imgSrc.value= imgSrc;    //write into text field
  364. }
  365.  
  366.  
  367.  
  368. //Invokes dialog to allow user to select filename. Puts value in text input.
  369.  
  370. function browseFileAndStore(){
  371.   var fileName;
  372.   fileName = browseForFileURL("select", "", true);  //returns a local filename
  373.   if (fileName) {
  374.     document.theForm.imgSrc.value = fileName;
  375.     storeImgSrc();
  376.   }
  377. }
  378.  
  379.  
  380. function pickSelectedImage(){
  381.   var imgsArray = document.MM_imgObjsArray = createObjsArray("IMG");
  382.   var arrLen = imgsArray.length;
  383.   var selArr = dreamweaver.getSelection();
  384.   var selObj = dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  385.   
  386.   for (i=0;i<arrLen;i++){
  387.     if (imgsArray[i]==selObj)
  388.       document.theForm.menu.selectedIndex=i;  
  389.   }
  390. }
  391.  
  392.  
  393.  
  394. //Creates a unique name for objs of tagName, using tagString
  395. //for instance: if tagString = Image, returns a name like Image1
  396. function getUniqueName(tagName,tagString,tagNameObjsArray){ 
  397.   var frameListSize,objName,dupe=true,counter=1;
  398.   var objsArray=arguments[2],objsArrayLen = objsArray.length;
  399.   
  400.     while (dupe==true){ //check new name against name of all other tagName objs
  401.         dupe=false;
  402.         objName = tagString + counter++; 
  403.         //iterates through possible names: tagName1, then tagName2, etc.
  404.         for (i=0;dupe==false && i<objsArrayLen;i++){
  405.           //if another object of this type has the same name
  406.           if (objsArray[i].getAttribute("name") == objName) 
  407.             dupe=true; //then repeat the loop, trying a new name
  408.         }
  409.     }
  410.     return objName; //return new name 
  411.     
  412. }
  413.  
  414. //Returns an array of objects of tagName
  415. //If doc is in a frameset, searches all frames in parent
  416. function createObjsArray(tagName){
  417.   var frameListLen,objsArray=new Array(),thisFrame;
  418.   if (dreamweaver.getDocumentDOM('parent')){//if frames
  419.     frameListLen = dreamweaver.getDocumentDOM('parent').getElementsByTagName('frame').length;
  420.     for (i=0;i<frameListLen;i++){
  421.       thisFrame = 'parent.frames[' + i + ']';
  422.       objsArray = objsArray.concat(dreamweaver.getDocumentDOM(thisFrame).getElementsByTagName(tagName));
  423.     }
  424.   } else //if no frames
  425.     objsArray = dreamweaver.getDocumentDOM("document").getElementsByTagName(tagName);
  426.   return objsArray;     
  427. }
  428.  
  429. //*************** GENERIC DOM MANIPULATION FNS *****************
  430.  
  431. //Returns a function call if exists in event handler.
  432. //  obj       - DOM object, such as dreamweaver.getDocumentDOM().body
  433. //  eventName - "onLoad", "onClick" etc (not case sensitive)
  434. //  fnName    - "MM_preloadImages" etc.
  435. //  optStr    - (optional) function call must contain this string to be found
  436. //Given <TAG onEvent="aaa();bbb();ccc()">,
  437. //calling getHandler(tagObj,'onEvent','bbb') will
  438. //return "bbb()". Returns empty if event or fn don't exist.
  439.  
  440. function getHandler(obj,eventName,fnName, optStr) {
  441.   var eventStr,fnArray,i,theChunk,retVal = "";
  442.   eventStr = obj.getAttribute(eventName);
  443.   if (eventStr) { //find previous call, or add it
  444.     fnArray = dreamweaver.getTokens(eventStr,";");
  445.     for (i=0; i<fnArray.length; i++) { //look at each code chunk
  446.       if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr ||  //fn call found
  447.           fnArray[i].indexOf(optStr) != -1)) {
  448.         retVal = fnArray[i]; break;
  449.     } }
  450.   }
  451.   return retVal
  452. }
  453.  
  454.  
  455.  
  456. //Replaces or adds a fn call to an event handler
  457. //  obj       - DOM object, such as dreamweaver.getDocumentDOM().body
  458. //  eventName - "onLoad", "onClick" etc (not case sensitive)
  459. //  fnCall    - "myFun('arg1','arg2')" etc.
  460. //  optStr    - (optional) function call must contain this string to be found
  461. //Given <TAG onEvent="aaa();bbb();ccc()">,
  462. //calling setHandler(tagObj,'onEvent','bbb(1,2)') will
  463. //replace "bbb()" with the altered fn call. If the event
  464. //does not exist, adds it. It fn didn't exist, adds it to the
  465. //end of the list.
  466.  
  467. function setHandler(obj,eventName,fnCall, optStr) {
  468.   var eventStr,fnName,fnArray=new Array(),i=0;
  469.   eventStr = obj.getAttribute(eventName);
  470.   if (eventStr) { //if event exists
  471.     fnName = fnCall.substring(0,fnCall.indexOf("("));
  472.     fnArray = dreamweaver.getTokens(eventStr,";");
  473.     for (i; i<fnArray.length; i++) //search for fnName
  474.       if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr ||  //fn call found
  475.           fnArray[i].indexOf(optStr) != -1)) break;
  476.   }
  477.   fnArray[i] = fnCall;
  478.   obj.setAttribute(eventName,fnArray.join(";"));
  479.   return true
  480. }
  481.  
  482.  
  483.  
  484. //Deletes a fn call from an event handler
  485. //  obj       - DOM object, such as dreamweaver.getDocumentDOM().body
  486. //  eventName - "onLoad", "onClick" etc (not case sensitive)
  487. //  fnName    - "MM_preloadImages" etc.
  488. //  optStr    - (optional) function call must contain this string to be found
  489. //Given <TAG onEvent="aaa();bbb();ccc()">,
  490. //calling delHandler(tagObj,'onEvent','bbb') will
  491. //remove "bbb();". If it is the last fn in the handler,
  492. //removes the event entirely.
  493.  
  494. function delHandler(obj,eventName,fnName, optStr) {
  495.   var eventStr,fnArray=new Array(),i=0,j;
  496.   eventStr = obj.getAttribute(eventName);
  497.   if (eventStr) { //if event exists
  498.     fnArray = dreamweaver.getTokens(eventStr,";");
  499.     for (i; i<fnArray.length; i++) { //look at each code chunk
  500.       if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr ||  //fn call found
  501.           fnArray[i].indexOf(optStr) != -1)) { //and, if given, optStr exists
  502.         if (fnArray.length == 1) { //if last one, remove attribute
  503.           obj.removeAttribute(eventName);
  504.         } else { //pull out
  505.           for (j=i; j<fnArray.length; j++) fnArray[j] = fnArray[j+1]; //shift array
  506.           fnArray.length--;
  507.           obj.setAttribute(eventName,fnArray.join(';'));
  508.         }
  509.         break;
  510.     } }
  511.   }
  512.   return true
  513. }
  514.  
  515.  
  516.  
  517. //Returns the tag for the current selection, such as
  518. //IMG, A, DIV etc. Always uppercase.
  519.  
  520. function getSelectionTag() {
  521.   var retVal = "";
  522.   var selArr = dreamweaver.getSelection()
  523.   var selObj=dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  524.     if (selObj && selObj.tagName) retVal = selObj.tagName;
  525.   return retVal
  526. }
  527.  
  528. //**************** GENERIC FUNCTIONS ****************
  529.  
  530. //function extractArgs(behFnCallStr){
  531. //function stripStar(theStr) {
  532. //function addStarToMenuItem(theSelect,menuIndex) {
  533. //function escQuotes(theStr){
  534. //function unescQuotes(theStr){
  535. //function niceNames(objRefArray,objTypeStr) {
  536. //function nameReduce (objName) {
  537. //function errMsg() {
  538. //function findObject(objName,  parentObj) {
  539.