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

  1.  
  2. //form field names:
  3. //fileURL - text field where URL appears
  4. //Delay - form field for delay number
  5. //Action - radio buttons: radioURL is Go To another document
  6. //                        radioThisDoc is stay at current document
  7.  
  8. // *********** GLOBAL VARS *****************************
  9.  
  10. var helpDoc = "html/204.creatingdocuments.fm24.html";
  11.  
  12. // ******************** API ****************************
  13. function canInspectSelection(){
  14.  
  15.   var metaObj = getSelectedObj();
  16.   return (metaObj.tagName && metaObj.tagName=="META" &&
  17.           metaObj.getAttribute("http-equiv") && 
  18.           metaObj.getAttribute("http-equiv").toLowerCase()=="refresh");
  19.    
  20. }
  21.  
  22. function inspectSelection(){
  23.   var refreshObj = getSelectedObj()
  24.   var tagContent = refreshObj.getAttribute("content"); 
  25.   var Delay = findObject("Delay");
  26.   var radioURL = findObject("radioURL");var radioThisDoc = findObject("radioThisDoc");
  27.   var contentArray;
  28.   
  29.   
  30.   //fill in PI form fields
  31.   //check to see if the refresh applies to the current document by doing
  32.   // an integer check - URL will have a ; 
  33.   if (tagContent == parseInt(tagContent)){ 
  34.     //fill in the Delay value and check the correct radio button:
  35.     Delay.value = tagContent; 
  36.     radioThisDoc.checked = true;     radioURL.checked = false;
  37.   } else {               // else refresh is used to go to another document
  38.      contentArray = getTokens(tagContent,";"); //create 2-member array
  39.      //fill in the Delay value
  40.      Delay.value = (parseInt(contentArray[0])==contentArray[0])?contentArray[0]:""; 
  41.      //check correct radio button:
  42.      radioURL.checked = true;     radioThisDoc.checked = false;
  43.      //strip "URL=" before placing into PI
  44.      if (contentArray[1] && contentArray[1].indexOf("URL=")==0) 
  45.        contentArray[1] = contentArray[1].substring(4);  
  46.      //fill in correct URL value  
  47.      if (contentArray[1])
  48.        findObject("fileURL").value = contentArray[1];
  49.      else
  50.        findObject("fileURL").value="";  
  51.   }
  52. }
  53.  
  54.  
  55. // ******************** LOCAL FUNCTIONS ****************************
  56.  
  57. function clearField(){
  58.   findObject("fileURL").value="";
  59.  
  60. }
  61.  
  62. function setMetaTag(whichButton){
  63.   //if whichButton is 0, go to URL just checked. If 1, refresh this doc just checked
  64.   //if 2, this function called from a form field other than a checkbox
  65.   var fileName="",refreshContent="";
  66.   var radioURL = findObject("radioURL");
  67.   var radioThisDoc = findObject("radioThisDoc");
  68.   var fileURL = findObject("fileURL");
  69.   var Delay = findObject("Delay");
  70.   var refreshDelay = (parseInt(Delay.value) == Delay.value)?Delay.value:"";
  71.   
  72.   if (whichButton == 0 || (whichButton == 2 && radioURL.checked && !radioThisDoc.checked)){
  73.   //if going to another doc
  74.     fileName=(fileURL.value)?fileURL.value:"";
  75.     refreshContent=refreshDelay + ";URL=" + fileName;
  76.     //set checkboxes correctly
  77.     radioThisDoc.checked = false;
  78.     radioURL.checked=true;
  79.   }
  80.   else { //refresh current doc
  81.     refreshContent=refreshDelay;
  82.     //set checkboxes correctly
  83.     radioURL.checked = false;
  84.     radioThisDoc=true;
  85.   }
  86.   
  87.   getSelectedObj().setAttribute("content",refreshContent);
  88.   
  89. }
  90.  
  91.  
  92. function browseForFile(){
  93.   var File = browseForFileURL(); 
  94.   if (File)
  95.     findObject("fileURL").value = File;
  96. }
  97.  
  98. // ******************** GENERIC FUNCTIONS ****************************
  99.  
  100. function findObject(objName,  parentObj) {
  101.   var i,tempObj="",found=false,curObj = "";
  102.   var NS = (navigator.appName.indexOf("Netscape") != -1);
  103.   if (!NS && document.all) curObj = document.all[objName]; //IE4
  104.   else {
  105.     parentObj = (parentObj != null)? parentObj.document : document;
  106.     if (parentObj[objName] != null) curObj = parentObj[objName]; //at top level
  107.     else { //if in form
  108.       if (parentObj.forms) for (i=0; i<parentObj.forms.length; i++) {  //search level for form object
  109.         if (parentObj.forms[i][objName]) {
  110.           curObj = parentObj.forms[i][objName];
  111.           found = true; break;
  112.       } }
  113.       if (!found && NS && parentObj.layers && parentObj.layers.length > 0) {
  114.         parentObj = parentObj.layers;
  115.         for (i=0; i<parentObj.length; i++) { //else search for child layers
  116.           tempObj = findObject(objName,parentObj[i]); //recurse
  117.           if (tempObj) { curObj = tempObj; break;} //if found, done
  118.   } } } }
  119.   return curObj;
  120. }
  121.  
  122.  
  123. // ******************** GENERIC DOM MANIPULATION FUNCTIONS ****************************
  124.  
  125. //Returns the selected object
  126. function getSelectedObj() {
  127.   var selArr=dreamweaver.getSelection();
  128.   return dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  129. }
  130.