home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Swap Image.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  20.6 KB  |  493 lines

  1. //*************** GLOBALS VARS *****************
  2.  
  3. var helpDoc = MM.HELP_behSwapImage;
  4.  
  5. var OLD_PRELOAD_ID;
  6. var OLD_PRELOAD_ARRAY;
  7.  
  8. //******************* BEHAVIOR FUNCTIONS **********************
  9.  
  10. //Changes multiple images at once. Accepts a variable number of args in triplets as follows:
  11. //  objStrNS - simple object name ('image1'), or object ref for Netscape (ex: document.layers['foo'].document.myImage)
  12. //  x        - ignored (there for backward compatibility)
  13. //  imgURL   - an image filename, URL encoded. (ex: file.gif, http://www.x.com/y.gif)
  14. //
  15. //Uses MM_findObj() to resolve object references for the two browsers.
  16. //Sets the image src property to the new filename: document.myImage.src = file.gif.
  17. //Fails gracefully on older browsers by ensuring the the object exists.
  18. //If the image is in a layer, fixes the reference so it works. It doesn't hurt
  19. //to set image.src in a browser (IE3) even if nothing changes.
  20. //The rest of the code is to support another Action, Swap Image Restore.
  21. //Builds an array of the original src values and saves it to a global property,
  22. //in the form of theObj,theObj.src,.... Prevents overwriting these values if called
  23. //repeatedly, to ensure we use the original src file set in the HTML.
  24.  
  25. function MM_swapImage() { //v3.0
  26.   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  27.    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  28. }
  29.  
  30. document.VERSION_MM_swapImage = 3.0; //define latest version number for behavior inspector
  31.  
  32. //******************* API **********************
  33.  
  34.  
  35. //Checks for the existence of images.
  36. //If none exist, returns false so this Action is grayed out.
  37.  
  38. function canAcceptBehavior(){
  39.   var retVal = false;
  40.   if (getAllObjectRefs("NS 4.0","IMG").length)
  41.     retVal = "onMouseOver,(onMouseOver),onClick,(onClick)";
  42.   return retVal;
  43. }
  44.  
  45.  
  46.  
  47. //Returns Javascript functions to be inserted in HTML head with script tags.
  48.  
  49. function behaviorFunction(){
  50.   return "MM_preloadImages,MM_swapImgRestore,MM_findObj,MM_swapImage"
  51. }
  52.  
  53.  
  54.  
  55. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  56. //Gets list of imgSrcs from doc attribute. With each imgSrc, it gets the parallel
  57. //img name from select 'menu'. Each imgSrc & imgObj are embedded as args.
  58.  
  59. function applyBehavior() {
  60.   var retVal="",i,j,argList="",imgList="",fnArray,imgSrcArray,imgSrc,imgObj,newName;
  61.   var preloadArray = new Array(),imgObjsArray=document.MM_imgObjsArray;
  62.   var preload = document.theForm.preload.checked;
  63.   var endsWithAnyNum  = /\[\d+\]$/; //ref ends with num: [1], [2] etc.
  64.   var proceed = null;
  65.  
  66.   if (dw.isReapplyingBehaviors()) document.SILENT_MODE = true;
  67.  
  68.   imgSrcArray = document.MM_myImgSrcs;      //get global list of imgSrcs
  69.   for (i=0; i<imgSrcArray.length; i++) {    //with each imgSrc
  70.     imgSrc = imgSrcArray[i];
  71.     if (imgSrc) {      //if not empty
  72.       if (argList) argList += ",";    //if stuff already in list, add comma
  73.  
  74.       imgObjNS = document.MM_NS_REFS[i]; //get NS ref
  75.  
  76.       if (imgObjNS.indexOf(".")==-1 || endsWithAnyNum.test(imgObjNS)) { //found rename item, prompt user & fixup
  77.         newName = "";  //may need a new or unique name
  78.         if (imgObjNS.indexOf(REF_UNNAMED)==0) {                 //if the image is unnamed
  79.           newName = getUniqueName("IMG","Image",imgObjsArray);    //generate unique name
  80.         } else if (proceed==null) { //if first dupe, prompt user if the want renames
  81.           if (document.SILENT_MODE) proceed = true;
  82.           else {
  83.             proceed = confirm(MSG_ImagesMustBeRenamed); //ask user if they want to proceed
  84.             if (!proceed) return "";  //cancel applyBehavior
  85.         } }
  86.         if (endsWithAnyNum.test(imgObjNS)) {                //if ends with number > 0: foo[1], use name gen new one
  87.           newName = getUniqueName("IMG",imgObjsArray[i].getAttribute("name"),imgObjsArray);
  88.         }
  89.         if (newName) {  //if the image should be renamed
  90.           imgObjsArray[i].setAttribute("name",newName); //rename image in document
  91.           createObjRefs(); //re-create refs based on new image name
  92.           imgObjNS = document.MM_NS_REFS[i]; //get NS ref
  93.         }
  94.       }
  95.       argList += "'"+getNameFromRef(imgObjNS)+"','','"+dw.doURLEncoding(imgSrc)+"'";
  96.       if (preload) preloadArray.push(dw.doURLEncoding(imgSrc)); //add string to list
  97.     }
  98.   }
  99.  
  100.   if (!argList) retVal = MSG_NoImgsSelected;
  101.   else { //OK
  102.  
  103.     //Add or remove MM_swapImgRestore() based on checkbox setting
  104.     selObj = dreamweaver.getBehaviorElement();
  105.     if (!selObj) selObj = dreamweaver.getDocumentDOM().getSelectedNode()
  106.     if (selObj && document.theForm.restore) {
  107.       if (document.theForm.restore.checked) { //add restore to onMouseOut handler
  108.         setHandler(selObj,'onMouseOut','MM_swapImgRestore()');
  109.       } else { //remove it
  110.         delHandler(selObj,'onMouseOut','MM_swapImgRestore');
  111.       }
  112.     }
  113.  
  114.     //if existing swap function outdated, update them and all calls on page
  115.     updateBehaviorFns("MM_findObj","MM_swapImgRestore","MM_preloadImages","MM_swapImage");
  116.  
  117.     if (OLD_PRELOAD_ID && OLD_PRELOAD_ARRAY) {            //if previously preloaded, remove DW2 preloads
  118.       if (OLD_PRELOAD_ID.toString().indexOf("#") != -1) { //DW2 preload call, remove it
  119.         delHandler(dw.getDocumentDOM().body,"onLoad","MM_preloadImages",OLD_PRELOAD_ID);
  120.     } }
  121.     argList += ("," + ((preload)?1:0));    //1 means preload, 0 means don't preload
  122.     preloadUpdate(preloadArray,OLD_PRELOAD_ARRAY,1); //add and delete preload calls to onLoad handler
  123.  
  124.     retVal = "MM_swapImage("+argList+")";  //create correct function call
  125.   }
  126.   return retVal
  127. }
  128.  
  129.  
  130. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  131. //call arguments. This information is used by DW to fixup behavior args when the
  132. //document is moved or changed.
  133. //
  134. //It is passed an actual function call string generated by applyBehavior(), which
  135. //may have a variable list of arguments, and this should return a matching mask.
  136. //
  137. //The return values are:
  138. //  URL     : argument could be a file path, which DW will update during Save As...
  139. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  140. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  141. //  other...: argument is ignored
  142.  
  143. function identifyBehaviorArguments(fnCallStr) {
  144.   var argList, argArray, numArgGroups, i;
  145.  
  146.   argList = "";
  147.   argArray = extractArgs(fnCallStr);
  148.   numArgGroups = Math.floor((argArray.length - 1) / 3); //args come in triplets
  149.   for (i=0; i<numArgGroups; i++) {          //with each NSobj,IEobj,URL triplet
  150.     if (argList) argList += ",";
  151.     //if no dot in the name, return simple name; else, return NS/IE refs
  152.     argList += (argArray[3*i+1].indexOf(".")==-1)? "objName,other,DEP":"NS4.0ref,IE4.0ref,DEP";
  153.   }
  154.   return argList;
  155. }
  156.  
  157.  
  158.  
  159. //Given the original function call, this parses out the args and updates
  160. //the UI. Loops through each imgObj,imgSrc pair.
  161. //If imgObj already present in menu, stuff imgSrc in imgSrcArray. If imgObj
  162. //doesn't exist, add to menu, and extend imgSrcArray.
  163.  
  164. function inspectBehavior(behFnCallStr){
  165.   var argArray,imgSrcArray,found,numImgs,i,j,k,imgObj,imgSrc,imgObjNum,itemRef,pos;
  166.   var endsWithZero = /\[0\]$/;        //ref ends with [0]
  167.  
  168.   if (dw.isReapplyingBehaviors()) document.SILENT_MODE = true;
  169.  
  170.   argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
  171.   imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
  172.   numImgs = document.MM_NS_REFS.length;
  173.   for (i=1; i<(argArray.length-2); i+=3){ //with each imgObj,imgSrc pair
  174.     imgObj=getNameFromRef(unescQuotes(argArray[i]));
  175.     OLD_PRELOAD_ARRAY.push(argArray[i+2]);
  176.     imgSrc=unescape(argArray[i+2]);
  177.     found = false;
  178.     for (j=0; j<numImgs; j++){  //check if imgObj is in ref list (lop off [0] if there)
  179.       itemRef = document.MM_NS_REFS[j];
  180.       if (!document.SILENT_MODE) itemRef = itemRef.replace(endsWithZero,""); //if not silent, select first occurence
  181.       if (imgObj == getNameFromRef(itemRef)) { //if found
  182.         imgSrcArray[j] = imgSrc;              //store imgSrc at that pos
  183.         if (imgSrc) addStarToMenuItem(document.theForm.menu,j);//if non-empty, mark with  *
  184.         found = true; break;
  185.     } }
  186.     if (!found && (pos=imgObj.indexOf("?"))!=-1) { //if didn't find, and includes frame
  187.       imgObj = imgObj.substring(0,pos); //remove framename, look on local page
  188.       for (j=0; j<numImgs; j++){  //check if imgObj is in ref list
  189.         if (imgObj == getNameFromRef(document.MM_NS_REFS[j])) { //if found
  190.           imgSrcArray[j] = imgSrc;              //store imgSrc at that pos
  191.           if (imgSrc) addStarToMenuItem(document.theForm.menu,j);//if non-empty, mark with  *
  192.           found = true; break;
  193.     } } }
  194.  
  195.     //Special code in case object name appears twice on the page. Only run if silently
  196.     //reapplying (such as a copy/paste).
  197.     //Searches within the behavior selection for an image of the expected name.
  198.     //If found, and others found with same name, converts name to imageName[n],
  199.     //and checks if that version is in our list of images. If so, selects the right one.
  200.  
  201.     if (!found && dw.isReapplyingBehaviors()) { //if failed because it's a silent copy/paste
  202.       var selNode = dw.getBehaviorElement();
  203.       //if the behavior selection is an image, or contains an image, with the same name
  204.       if (selNode) {
  205.         //search within selection for IMG with that name
  206.         for (k=0; selNode.hasChildNodes() && k<selNode.childNodes.length; k++) with (selNode.childNodes[k]) {
  207.           if (nodeType==Node.ELEMENT_NODE && tagName=="IMG" && getAttribute("NAME")==imgObj)
  208.             { selNode = selNode.childNodes[k]; break; } }
  209.         if (selNode.nodeType==Node.ELEMENT_NODE && selNode.tagName=="IMG" && selNode.getAttribute("NAME")==imgObj) {
  210.           var DOM = dw.getDocumentDOM();
  211.           var allImages = DOM.getElementsByTagName("IMG");
  212.           for (k=0; k<allImages.length && allImages[k]!=selNode; k++);  //search for myself in list
  213.           if (allImages[k]==selNode) { //if found my image in list
  214.             j=0;
  215.             for (k--; k>=0; k--) if (allImages[k].getAttribute("NAME") == imgObj) j++; //count all w/ same name
  216.             itemRef = "."+imgObj+"["+j+"]";
  217.             for (j=0; j<numImgs; j++) {  //check if itemRef is in ref list
  218.               if (document.MM_NS_REFS[j].indexOf(itemRef)!=-1) {   //if found
  219.                 document.MM_NS_REFS[j] = imgObj+"[999]"; //mark for renaming
  220.                 imgSrcArray[j] = imgSrc;              //store imgSrc at that pos
  221.                 found = true; break;
  222.     } } } } } }
  223.  
  224.     if (!found && !document.SILENT_MODE) {
  225.       alert(errMsg(MSG_ImgNotFound,imgObj,imgSrc)); //if image name not found
  226.   } }
  227.   document.MM_myImgSrcs = imgSrcArray; //save updated imageSrc list
  228.   displayImgSrc();         //load the imageSrc for selected image
  229.  
  230.   //Determine if preloading, get id
  231.   OLD_PRELOAD_ID = (i < argArray.length)? argArray[i] : 0;  //if no former ID, OLD_PRELOAD_ID = 0
  232.   document.theForm.preload.checked = (OLD_PRELOAD_ID != 0); //set preload checkbox
  233.   if (OLD_PRELOAD_ID == 0) OLD_PRELOAD_ARRAY = new Array();      //if flag not set, forget about OLD_PRELOAD_ARRAY
  234.  
  235.   //If restore checkbox is available, see if MM_swapImgRestore() exists, and check the box
  236.   var theObj = findObject("restoreOption");
  237.   if (theObj) { //restore checkbox is a possibility
  238.     var selObj=dreamweaver.getBehaviorElement();
  239.     if (selObj && selObj.tagName != "A") selObj = selObj.parentNode; //move out to A tag if needed
  240.     if (selObj && selObj.tagName == "A") if (document.theForm.restore) {
  241.       document.theForm.restore.checked = getHandler(selObj,'onMouseOut','MM_swapImgRestore');
  242.     }
  243.   }
  244. }
  245.  
  246.  
  247.  
  248. //Given the original function call, this parses out the args and updates
  249. //the code. If there's a preload id at the end of the arglist, deletes
  250. //the preload handler. If there's a swap restore call, deletes that.
  251.  
  252. function deleteBehavior(behFnCallStr){
  253.   var i,argArray,obj,selArr,selObj,preloadImgs = new Array();
  254.  
  255.   //Maybe remove swap restore handler
  256.   if (!selObj) selObj = dw.getDocumentDOM().getSelectedNode()
  257.   if (selObj && selObj.tagName != "A") selObj = selObj.parentNode; //move out to A tag if needed
  258.   if (selObj && selObj.tagName == "A") if (selObj.outerHTML.indexOf("MM_swapImage(") == -1) {
  259.     delHandler(selObj,'onMouseOut','MM_swapImgRestore');
  260.   }
  261.  
  262.   //Maybe remove preload handler
  263.   argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
  264.   for (i=1; i<(argArray.length-2); i+=3){ //with each imgObj,imgSrc pair, build list of img srcs
  265.     imgSrc=unescape(argArray[i+2]);
  266.     if (imgSrc) preloadImgs.push(argArray[i+2]);
  267.   }
  268.   preloadFlag = (i < argArray.length)? argArray[i] : 0;  //if no former ID, preloadFlag = 0
  269.   if (preloadFlag && preloadImgs) {          //if previously preloaded, remove old preloads
  270.     if (preloadFlag.toString().indexOf("#") != -1) { //old preload call, remove it
  271.       delHandler(dw.getDocumentDOM().body,"onLoad","MM_preloadImages",preloadFlag);
  272.     } else { //previously preloaded, remove before adding new calls
  273.       preloadUpdate("",preloadImgs,0); //remove preload iff there are 0 users
  274.   } }
  275. }
  276.  
  277.  
  278.  
  279. //***************** LOCAL FUNCTIONS  ******************
  280.  
  281. //Load the select menu with image names.
  282. //Also sets the global property MM_myImgSrcs to the right num of items.
  283.  
  284. function initializeUI(){
  285.   var niceNameSrcArray=new Array(), nameArray, i, selTag="";
  286.   var imgSrcArray = new Array();
  287.   var endsWithZero = /\[0\]$/;        //ref ends with [0]
  288.  
  289.   //Determine if RESTORE is an option. If not, remove UI for it
  290.   //the dreamweaver.getBehaviorTag() check ensures the checkbox
  291.   //is not available if a behavior is attached to a timeline
  292.  
  293.   var removeCheckbox = false;
  294.   if (!dreamweaver.getBehaviorTag() )  //if behavior is in a timeline
  295.     removeCheckbox = true;
  296.   else {
  297.     if (dreamweaver.getBehaviorElement()) selTag = dreamweaver.getBehaviorElement().tagName;
  298.     if (!selTag) selTag = getSelectionTag();
  299.     if (selTag!="A" && selTag!="IMG" && selTag!="AREA")  //if sel not A or IMG
  300.       removeCheckbox = true;
  301.   }
  302.   if (removeCheckbox){
  303.     var theObj = findObject("restoreOption");
  304.     if (theObj) theObj.outerHTML = ""; //remove restoreOption checkbox
  305.   }
  306.  
  307.   //Default preload flag is 1 (preload);
  308.   OLD_PRELOAD_ID = 1;
  309.   OLD_PRELOAD_ARRAY = new Array();
  310.   document.theForm.preload.checked = (OLD_PRELOAD_ID != 0);
  311.  
  312.   createObjRefs();
  313.   //Search for unreferenceable objects. <DIV id="foo"> is IE only, <LAYER> is NS only.
  314.   //if REF_CANNOT found, return empty string, and use IE refs for nice namelist.
  315.   for (i=0; i<document.MM_NS_REFS.length; i++) {
  316.     if (document.MM_NS_REFS[i].indexOf(REF_CANNOT) == 0) document.MM_NS_REFS[i] = ""; //blank it out
  317.     niceNameSrcArray[i] = document.MM_NS_REFS[i].replace(endsWithZero,""); //if foo[0], display as foo
  318.   }
  319.   nameArray = niceNames(niceNameSrcArray,TYPE_Image);
  320.   for (i=0; i<nameArray.length; i++){
  321.     document.theForm.menu.options[i]=new Option(nameArray[i]); //load menu
  322.     imgSrcArray[i] = "";
  323.   }
  324.   pickSelectedImage(); //if an image is selected, selects it in the picklist
  325.   document.MM_myImgSrcs = imgSrcArray; //set global
  326.  
  327.   document.theForm.imgSrc.focus(); //set focus on textbox
  328.   document.theForm.imgSrc.select(); //set insertion point into textbox
  329. }
  330.  
  331.  
  332.  
  333. //Creates arrays of all images, including those in other frames.
  334. //Ensure that ones with duplicate names (per frame) are followed by an index.
  335. //If none found, returns false.
  336.  
  337. function createObjRefs(){
  338.   var i,j,lastDot,imageName,myFrame,index,refs;
  339.   var endsWithAnyNum  = /\[\d+\]$/; //ref ends with num: [1], [2] etc.
  340.  
  341.   refs = getAllObjectRefs("NS 4.0","IMG");
  342.  
  343.   for (i=0; i<refs.length; i++) { //strip off all indexing
  344.     refs[i] = refs[i].replace(endsWithAnyNum,""); //remove num
  345.   }
  346.   for (i=0; i<refs.length; i++) {
  347.     lastDot = refs[i].lastIndexOf(".");
  348.     if (lastDot != -1) {
  349.       imageName = refs[i].substring(lastDot+1);     //grab image name
  350.       if (refs[i].indexOf("document.")==0) myFrame = "document.";
  351.       else myFrame = refs[i].substring(0,refs[i].indexOf("]")+1);
  352.       index = 0;
  353.       for (j=i+1; j<refs.length; j++) if (refs[j].indexOf(myFrame)==0) { //if same frame, scan forward
  354.         lastDot = refs[j].lastIndexOf(".");
  355.         if (lastDot != -1 && refs[j].substring(lastDot+1)==imageName) { //if same name
  356.           refs[j] += "["+(++index)+"]";             //uniquely number it
  357.       } }
  358.       if (index) refs[i] += "[0]";                  //if anything numbered, number the first one
  359.   } }
  360.   document.MM_NS_REFS = refs;
  361.  
  362.   return (refs.length >0)
  363. }
  364.  
  365.  
  366.  
  367. //Given imageSrc in form, looks up the menu's selection number, and stores the
  368. //new imageSrc at that position in the global document property "MM_myImgSrcs".
  369.  
  370. function storeImgSrc(){
  371.   var newImgSrc, imgSrcArray, menuIndex, newMenuText;
  372.  
  373.   newImgSrc = document.theForm.imgSrc.value;
  374.   imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
  375.   menuIndex = document.theForm.menu.selectedIndex; //get index to swap
  376.   imgSrcArray[menuIndex] = newImgSrc;   //swap
  377.   document.MM_myImgSrcs = imgSrcArray;   //rewrite list
  378.   if (newImgSrc) {  //if non-empty, mark with  *
  379.     addStarToMenuItem(document.theForm.menu, menuIndex);
  380.   } else { //nothing to store, strip off any previous star
  381.     newMenuText = stripStar(document.theForm.menu.options[menuIndex].text); //remove if old star
  382.     document.theForm.menu.options[menuIndex]=new Option(newMenuText); //add new line to menu
  383.   }
  384.   document.theForm.menu.selectedIndex = menuIndex; //reset selection index
  385. }
  386.  
  387.  
  388.  
  389. //Looks at the menu of names, and returns the imgSrc associated with the
  390. //selected item. Example: if the 2nd menu item's selected, returns 2nd item
  391. //stored in property "MM_myImgSrcs".
  392.  
  393. function displayImgSrc(){
  394.   var imgSrcArray, curImageSrcNum, imgSrc;
  395.  
  396.   imgSrcArray = document.MM_myImgSrcs; //get the list of imgSrcs
  397.   curImageSrcNum = document.theForm.menu.selectedIndex; //get index selected
  398.   imgSrc = imgSrcArray[curImageSrcNum];   //lookup imgSrc
  399.   document.theForm.imgSrc.value= imgSrc;    //write into text field
  400. }
  401.  
  402.  
  403.  
  404. //Invokes dialog to allow user to select filename. Puts value in text input.
  405.  
  406. function browseFileAndStore(){
  407.   var fileName;
  408.   fileName = browseForFileURL("select", "", true);  //returns a local filename
  409.   if (fileName) {
  410.     document.theForm.imgSrc.value = fileName;
  411.     storeImgSrc();
  412.   }
  413. }
  414.  
  415.  
  416. function pickSelectedImage(){
  417.   var imgsArray = document.MM_imgObjsArray = createObjsArray("IMG");
  418.   var arrLen = imgsArray.length;
  419.   var selArr = dreamweaver.getSelection();
  420.   var selObj = dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  421.  
  422.   for (i=0;i<arrLen;i++){
  423.     if (imgsArray[i]==selObj)
  424.       document.theForm.menu.selectedIndex=i;
  425.   }
  426. }
  427.  
  428.  
  429.  
  430. //Creates a unique name for objs of tagName, using tagString
  431. //for instance: if tagString = Image, returns a name like Image1
  432. function getUniqueName(tagName,tagString,tagNameObjsArray){
  433.   var frameListSize,objName,dupe=true,counter=1;
  434.   var objsArray=arguments[2],objsArrayLen = objsArray.length;
  435.  
  436.     while (dupe==true){ //check new name against name of all other tagName objs
  437.         dupe=false;
  438.         objName = tagString + counter++;
  439.         //iterates through possible names: tagName1, then tagName2, etc.
  440.         for (i=0;dupe==false && i<objsArrayLen;i++){
  441.           //if another object of this type has the same name
  442.           if (objsArray[i].getAttribute("name") == objName)
  443.             dupe=true; //then repeat the loop, trying a new name
  444.         }
  445.     }
  446.     return objName; //return new name
  447.  
  448. }
  449.  
  450. //Returns an array of objects of tagName
  451. //If doc is in a frameset, searches all frames in parent
  452. function createObjsArray(tagName){
  453.   var frameListLen,objsArray=new Array(),thisFrame;
  454.   if (dreamweaver.getDocumentDOM('parent')){//if frames
  455.     frameListLen = dreamweaver.getDocumentDOM('parent').getElementsByTagName('frame').length;
  456.     for (i=0;i<frameListLen;i++){
  457.       thisFrame = 'parent.frames[' + i + ']';
  458.       objsArray = objsArray.concat(dreamweaver.getDocumentDOM(thisFrame).getElementsByTagName(tagName));
  459.     }
  460.   } else //if no frames
  461.     objsArray = dreamweaver.getDocumentDOM("document").getElementsByTagName(tagName);
  462.   return objsArray;
  463. }
  464.  
  465.  
  466. //Returns the tag for the current selection, such as
  467. //IMG, A, DIV etc. Always uppercase.
  468.  
  469. function getSelectionTag() {
  470.   var retVal = "";
  471.   var selObj = dw.getDocumentDOM().getSelectedNode();
  472.   if (selObj && selObj.nodeType == Node.ELEMENT_NODE) retVal = selObj.tagName;
  473.   return retVal
  474. }
  475.  
  476.  
  477. //Called by Attain to silently update behavior calls
  478. //Returns new call if ok, otherwise returns empty string
  479.  
  480. function reapplyBehavior(oldBehaviorCall) {
  481.   var newBehaviorCall = "";
  482.   var behName = "MM_swapImage";
  483.  
  484.   document.SILENT_MODE = true;
  485.   initializeUI();
  486.   inspectBehavior(oldBehaviorCall);
  487.   newBehaviorCall = applyBehavior();
  488.   if (newBehaviorCall.indexOf(behName) == -1) newBehaviorCall=""; //if not fn call, return ""
  489.   document.SILENT_MODE = false;
  490.  
  491.   return newBehaviorCall;
  492. }
  493.