home *** CD-ROM | disk | FTP | other *** search
/ internet.au CDrom 42 / NETCD42.iso / web / w95 / dream2.exe / data1.cab / Program_Files / Configuration / Inspectors / base.js < prev    next >
Encoding:
JavaScript  |  1998-11-30  |  3.8 KB  |  113 lines

  1. // *********** GLOBAL VARS *****************************
  2.  
  3. var helpDoc = "html/204.creatingdocuments.fm25.html";
  4.  
  5. // ******************** API ****************************
  6. function canInspectSelection(){
  7.   return true;
  8. }
  9.  
  10. //look at target
  11. //if in list of targets, set to list item
  12. //if not, add to bottom of list and set it
  13.  
  14.  
  15. function inspectSelection(){
  16.   var frameName,counter,frameList,listLen,counter,bTargetFound=false;
  17.   var baseObj = getSelectedObj(),targetVal;
  18.   var hrefVal = baseObj.getAttribute("href");
  19.   var Href = findObject("Href");
  20.   var frameTarget = findObject("frameTarget");
  21.   var counter=5; //add frame names to picklist after standard frame targets
  22.   //populate frame target picklist
  23.   frameList=getObjectRefs("NS 4.0","parent","frame"); //get list of frames
  24.   if (frameList && frameList.length>0) { //if frames
  25.   //if the frame has a name, add name to target picklist
  26.     for (i=0; i<frameList.length; i++) {
  27.       if (frameList[i].indexOf('unnamed')==-1){ //if the frame has a name
  28.         frameName=frameList[i].substring(frameList[i].indexOf("['")+2,frameList[i].indexOf("']"));
  29.         frameTarget.options[counter++] = new Option(frameName); 
  30.   }}}
  31.  
  32.   //if base target value exists and matches choice in target picklist, set it
  33.   //otherwise, add to bottom of picklist and select it
  34.   if (baseObj.getAttribute("target")){
  35.      targetVal = baseObj.getAttribute("target");
  36.      for (i=0;i<counter&&!bTargetFound;i++){  //look for existing match in frame picklist
  37.        if (targetVal==frameTarget.options[i].text){
  38.          frameTarget.selectedIndex=i;
  39.          bTargetFound=true;
  40.        }
  41.      }
  42.      if (!bTargetFound){ //if no match found
  43.      //dynamically add the frame target value to bottom of picklist
  44.        frameTarget.options[counter] = new Option(targetVal);
  45.        frameTarget.selectedIndex = counter;
  46.      }
  47.   }
  48.   
  49.   //fill in href value
  50.   if (hrefVal)
  51.     Href.value = hrefVal;
  52.   else
  53.     Href.value = "";
  54.     
  55. }
  56.  
  57. // ******************** LOCAL FUNCTIONS ****************************
  58.  
  59. function setBaseTag(){
  60.   var baseObj = getSelectedObj(),Attributes;
  61.   var Href=findObject("Href").value;
  62.   var frameTarget=findObject("frameTarget");
  63.   var frameIndex = frameTarget.selectedIndex
  64.   
  65.   if (frameIndex!=0)
  66.     baseObj.setAttribute("target",findObject("frameTarget").options[frameIndex].text)
  67.   else
  68.     baseObj.removeAttribute("target");    
  69.     
  70.   if (Href)
  71.     baseObj.setAttribute("href",Href);   
  72. }
  73.  
  74. function browseForFile(){
  75.   var fileName=browseForFileURL();
  76.   if (fileName) 
  77.     findObject("Href").value=fileName;
  78. }
  79.  
  80.  
  81. // ******************** GENERIC FUNCTIONS ****************************
  82.  
  83. function findObject(objName,  parentObj) {
  84.   var i,tempObj="",found=false,curObj = "";
  85.   var NS = (navigator.appName.indexOf("Netscape") != -1);
  86.   if (!NS && document.all) curObj = document.all[objName]; //IE4
  87.   else {
  88.     parentObj = (parentObj != null)? parentObj.document : document;
  89.     if (parentObj[objName] != null) curObj = parentObj[objName]; //at top level
  90.     else { //if in form
  91.       if (parentObj.forms) for (i=0; i<parentObj.forms.length; i++) {  //search level for form object
  92.         if (parentObj.forms[i][objName]) {
  93.           curObj = parentObj.forms[i][objName];
  94.           found = true; break;
  95.       } }
  96.       if (!found && NS && parentObj.layers && parentObj.layers.length > 0) {
  97.         parentObj = parentObj.layers;
  98.         for (i=0; i<parentObj.length; i++) { //else search for child layers
  99.           tempObj = findObject(objName,parentObj[i]); //recurse
  100.           if (tempObj) { curObj = tempObj; break;} //if found, done
  101.   } } } }
  102.   return curObj;
  103. }
  104.  
  105. // ******************** GENERIC DOM MANIPULATION FUNCTIONS ****************************
  106.  
  107. //Returns the selected object
  108. function getSelectedObj() {
  109.   var selArr=dreamweaver.getSelection();
  110.   return dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  111. }
  112.  
  113.