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

  1.  
  2. //form field names (all text fields):
  3. //Href
  4. //ID
  5. //Title
  6. //Rel
  7. //Rev
  8.  
  9. // *********** GLOBAL VARS *****************************
  10.  
  11. var helpDoc = "html/204.creatingdocuments.fm26.html";
  12.  
  13. // ******************** API ****************************
  14. function canInspectSelection(){
  15.   return true;
  16. }
  17.  
  18. function inspectSelection(){
  19.   var Href = findObject("Href");
  20.   var Title = findObject("Title");
  21.   var ID = findObject("ID");
  22.   var Rel = findObject("Rel");
  23.   var Rev = findObject("Rev");
  24.   var linkObj = getSelectedObj();
  25.  
  26.   if (linkObj.getAttribute("href"))
  27.     Href.value=linkObj.getAttribute("href");
  28.   else
  29.     Href.value = "";    
  30.   if (linkObj.getAttribute("id"))
  31.     ID.value=linkObj.getAttribute("id");
  32.   else
  33.     ID.value = "";    
  34.   if (linkObj.getAttribute("title"))  
  35.     Title.value=linkObj.getAttribute("title");
  36.   else
  37.     Title.value="";    
  38.   if (linkObj.getAttribute("rel"))
  39.     Rel.value=linkObj.getAttribute("rel");
  40.   else
  41.     Rel.value = "";    
  42.   if (linkObj.getAttribute("rev"))
  43.     Rev.value=linkObj.getAttribute("rev");
  44.   else
  45.     Rev.value ="";        
  46. }
  47.  
  48.  
  49.  
  50. // ******************** LOCAL FUNCTIONS ****************************
  51.  
  52. function setLinkTag(){
  53.   var linkObj = getSelectedObj();
  54.   var relValue = findObject("Rel").value;
  55.   var bRelEqualsStylesheet = relValue &&
  56.                              relValue.toLowerCase().indexOf("stylesheet")!=-1;
  57.   if (findObject("Href").value)
  58.     linkObj.setAttribute("href",findObject("Href").value);
  59.   else
  60.     linkObj.removeAttribute("href");
  61.   if (findObject("ID").value)
  62.     linkObj.setAttribute("id",findObject("ID").value);
  63.   else
  64.     linkObj.removeAttribute("id");
  65.   if (findObject("Title").value)
  66.     linkObj.setAttribute("title",findObject("Title").value);
  67.   else
  68.     linkObj.removeAttribute("title");
  69.   if (findObject("Rel").value)
  70.     linkObj.setAttribute("rel",findObject("Rel").value);
  71.   else
  72.     linkObj.removeAttribute("rel");
  73.   if (findObject("Rev").value)
  74.     linkObj.setAttribute("rev",findObject("Rev").value);
  75.   else
  76.     linkObj.removeAttribute("rev");
  77.   setTypeAttr(bRelEqualsStylesheet);//set type attribute based on rel value    
  78. }
  79.  
  80. function browseForFile(){
  81.   var fileName=browseForFileURL();
  82.   if (fileName) 
  83.     findObject("Href").value=fileName;
  84. }
  85.  
  86. function setTypeAttr(bStyle){
  87.   var linkObj = getSelectedObj();
  88.   var typeAttr = linkObj.getAttribute("type");
  89.   if (bStyle) //set type to text/css if applicable
  90.     linkObj.setAttribute("type","text/css");
  91.   //otherwise, remove it    
  92.   else if (typeAttr && typeAttr.toLowerCase() == "text/css")
  93.     linkObj.removeAttribute("type");
  94. }
  95. // ******************** GENERIC FUNCTIONS ****************************
  96.  
  97.  
  98. function findObject(objName,  parentObj) {
  99.   var i,tempObj="",found=false,curObj = "";
  100.   var NS = (navigator.appName.indexOf("Netscape") != -1);
  101.   if (!NS && document.all) curObj = document.all[objName]; //IE4
  102.   else {
  103.     parentObj = (parentObj != null)? parentObj.document : document;
  104.     if (parentObj[objName] != null) curObj = parentObj[objName]; //at top level
  105.     else { //if in form
  106.       if (parentObj.forms) for (i=0; i<parentObj.forms.length; i++) {  //search level for form object
  107.         if (parentObj.forms[i][objName]) {
  108.           curObj = parentObj.forms[i][objName];
  109.           found = true; break;
  110.       } }
  111.       if (!found && NS && parentObj.layers && parentObj.layers.length > 0) {
  112.         parentObj = parentObj.layers;
  113.         for (i=0; i<parentObj.length; i++) { //else search for child ayers
  114.           tempObj = findObject(objName,parentObj[i]); //recurse
  115.           if (tempObj) { curObj = tempObj; break;} //if found, done
  116.   } } } }
  117.   return curObj;
  118. }
  119.  
  120. // ******************** GENERIC DOM MANIPULATION FUNCTIONS ****************************
  121.  
  122. //Returns the selected object
  123. function getSelectedObj() {
  124.   var selArr=dreamweaver.getSelection();
  125.   return dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  126. }
  127.  
  128.