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

  1.  
  2.  
  3. //form field names:
  4. //Description - text field
  5.  
  6. // *********** GLOBAL VARS *****************************
  7.  
  8. var helpDoc = "html/204.creatingdocuments.fm23.html";
  9.  
  10. // ******************** API ****************************
  11. function canInspectSelection(){
  12.  
  13.   var metaObj = getSelectedObj();
  14.   return (metaObj.tagName && metaObj.tagName == "META" &&
  15.           metaObj.getAttribute("name") && 
  16.           metaObj.getAttribute("name").toLowerCase()=="description");
  17. }
  18.  
  19. function inspectSelection(){
  20.   var inspectorState = arguments[0],currKeyVal;
  21.   var contentLayer = findObject("contentField");
  22.   var contentCell = contentLayer.getElementsByTagName("TD").item(0);
  23.   var minText= '<textarea name="Description" onBlur="setMetaTag()" '
  24.   + 'style="width:350;height:32" rows="2" wrap="virtual"></textarea>'
  25.   var maxText='<textarea name="Description" onBlur="setMetaTag()" '+
  26.   'style="width:350;height:76" rows="4" wrap="virtual"></textarea>';
  27.   //change inspector state if needed
  28.   //the rows=X check determines whether current state is min or max
  29.   if (inspectorState=="min"&& (findString('rows="4"',contentCell.innerHTML)||contentCell.innerHTML=="")){
  30.     currKeyVal = findObject("Description").value;
  31.     contentCell.innerHTML=minText;
  32.     findObject("Description").value = currKeyVal;
  33.   }    
  34.   else if (inspectorState=="max" && (findString('rows="2"',contentCell.innerHTML)||contentCell.innerHTML=="")){
  35.     currKeyVal = findObject("Description").value; 
  36.     contentCell.innerHTML=maxText; 
  37.     findObject("Description").value = currKeyVal;
  38.   }
  39.   if (getSelectedObj().getAttribute("content"))     
  40.     findObject("Description").value= getSelectedObj().getAttribute("content");
  41.   else
  42.     findObject("Description").value="";    
  43. }
  44.  
  45. function findString(stringToFind,stringToLookIn){
  46.   if (stringToLookIn.indexOf(stringToFind)==-1)
  47.     return false;
  48.   return true;    
  49. }
  50.  
  51.  
  52. // ******************** LOCAL FUNCTIONS ****************************
  53.  
  54. function setMetaTag(){
  55.   getSelectedObj().setAttribute("content",findObject("Description").value);
  56. }
  57.  
  58.  
  59. // ******************** GENERIC FUNCTIONS ****************************
  60.  
  61.  
  62. function findObject(objName,  parentObj) {
  63.   var i,tempObj="",found=false,curObj = "";
  64.   var NS = (navigator.appName.indexOf("Netscape") != -1);
  65.   if (!NS && document.all) curObj = document.all[objName]; //IE4
  66.   else {
  67.     parentObj = (parentObj != null)? parentObj.document : document;
  68.     if (parentObj[objName] != null) curObj = parentObj[objName]; //at top level
  69.     else { //if in form
  70.       if (parentObj.forms) for (i=0; i<parentObj.forms.length; i++) {  //search level for form object
  71.         if (parentObj.forms[i][objName]) {
  72.           curObj = parentObj.forms[i][objName];
  73.           found = true; break;
  74.       } }
  75.       if (!found && NS && parentObj.layers && parentObj.layers.length > 0) {
  76.         parentObj = parentObj.layers;
  77.         for (i=0; i<parentObj.length; i++) { //else search for child layers
  78.           tempObj = findObject(objName,parentObj[i]); //recurse
  79.           if (tempObj) { curObj = tempObj; break;} //if found, done
  80.   } } } }
  81.   return curObj;
  82. }
  83.  
  84. // ******************** GENERIC DOM MANIPULATION FUNCTIONS ****************************
  85.  
  86. //Returns the selected object
  87. function getSelectedObj() {
  88.   var selArr=dreamweaver.getSelection();
  89.   return dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  90. }
  91.