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

  1. //form field names:
  2. //metaAttribute - drop down menu - name is [0] and http is [1]
  3. //metaValue - text field
  4. //metaContent - text field
  5.  
  6. // *********** GLOBAL VARS *****************************
  7.  
  8. var helpDoc = "html/204.creatingdocuments.fm20.html";
  9.  
  10. // ******************** API ****************************
  11. function canInspectSelection(){
  12.   metaObj = getSelectedObj();
  13.   return (metaObj.tagName && metaObj.tagName=="META");
  14. }
  15.  
  16. function inspectSelection(){
  17.  
  18.   var metaObj = getSelectedObj();
  19.   var metaValue = findObject("metaValue");
  20.   var metaAttribute = findObject("metaAttribute");
  21.   var metaContent = findObject("metaContent");
  22.   var useNameAttr = metaObj.getAttribute("name") || metaObj.getAttribute("name")=="";
  23.   var thisContent = metaObj.getAttribute("content");
  24.   var thisAttribute;
  25.   
  26.  
  27.  //fill in PI
  28.   metaAttribute.selectedIndex = (useNameAttr)?0:1;
  29.   if (useNameAttr){
  30.     thisAttribute = metaObj.getAttribute("name");
  31.     findObject("metaImage").src="name.gif";
  32.   }
  33.   else{
  34.     thisAttribute = metaObj.getAttribute("http-equiv");    
  35.     findObject("metaImage").src="http.gif";
  36.   }    
  37.     
  38.   //fill in attribute value if present, otherwise fill text field with empty string    
  39.   findObject("metaValue").value = thisAttribute;    
  40.   //fill in meta content if present, otherwise fill text field with empty string
  41.   if (metaObj.getAttribute("content") || metaObj.getAttribute("content")=="")
  42.     metaContent.value = (thisContent)?thisContent:"";
  43.      
  44. }
  45.  
  46.  
  47.  
  48.  
  49. // ******************** LOCAL FUNCTIONS ****************************
  50.  
  51. function setMetaTag(){
  52.   var metaObj=getSelectedObj();
  53.   var metaValue = findObject("metaValue").value;
  54.  
  55.  
  56.   if (findObject("metaAttribute").selectedIndex==0){
  57.     metaObj.removeAttribute("http-equiv");
  58.     metaObj.setAttribute("name",metaValue);
  59.   } else {
  60.     metaObj.removeAttribute("name");
  61.     metaObj.setAttribute("http-equiv",metaValue);
  62.   }
  63.    //attribute is removed and then re-applied so that content attribute
  64.    //always appears after name and http-equiv attributes
  65.    metaObj.removeAttribute("content"); 
  66.    metaObj.setAttribute("content",findObject("metaContent").value);
  67.  
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74. // ******************** GENERIC FUNCTIONS ****************************
  75.  
  76.  
  77. function findObject(objName,  parentObj) {
  78.   var i,tempObj="",found=false,curObj = "";
  79.   var NS = (navigator.appName.indexOf("Netscape") != -1);
  80.   if (!NS && document.all) curObj = document.all[objName]; //IE4
  81.   else {
  82.     parentObj = (parentObj != null)? parentObj.document : document;
  83.     if (parentObj[objName] != null) curObj = parentObj[objName]; //at top level
  84.     else { //if in form
  85.       if (parentObj.forms) for (i=0; i<parentObj.forms.length; i++) {  //search level for form object
  86.         if (parentObj.forms[i][objName]) {
  87.           curObj = parentObj.forms[i][objName];
  88.           found = true; break;
  89.       } }
  90.       if (!found && NS && parentObj.layers && parentObj.layers.length > 0) {
  91.         parentObj = parentObj.layers;
  92.         for (i=0; i<parentObj.length; i++) { //else search for child layers
  93.           tempObj = findObject(objName,parentObj[i]); //recurse
  94.           if (tempObj) { curObj = tempObj; break;} //if found, done
  95.   } } } }
  96.   return curObj;
  97. }
  98.  
  99. // ******************** GENERIC DOM MANIPULATION FUNCTIONS ****************************
  100.  
  101. //Returns the selected object
  102. function getSelectedObj() {
  103.   var selArr=dreamweaver.getSelection();
  104.   return dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  105. }
  106.