home *** CD-ROM | disk | FTP | other *** search
/ Beginning Direct3D Game Programming / Direct3D.iso / directx / dxf / extras / documentation / directx7 / directx7.chm / dxmedia / foundation / d3drm / js / dynamicload.js < prev    next >
Text File  |  2000-09-22  |  3KB  |  99 lines

  1. public_description = new DataBuffer()
  2.  
  3. function URLElement(fileName,filePath,dirBack,dirLevel,isValid){
  4.     this.fileName      =     fileName;    
  5.     this.filePath      =     filePath;
  6.     this.dirBack     =     dirBack;
  7.     this.dirLevel      =     dirLevel;
  8.     this.isValid   =     isValid;
  9. }
  10.  
  11. function DataBuffer(){
  12.     this.getInnerText = getInnerText;
  13.     this.getInnerHTML = getInnerHTML;
  14. }
  15.  
  16. function getInnerText(sObjID){
  17.     if (typeof(ID = eval("window." + sObjID)) != "undefined")
  18.         return ID.innerText;
  19.     else
  20.         return '<FONT COLOR="RED">Text range for <B>sDataID = "' + sObjID + '"</B> was not found!</FONT>';
  21. }
  22.  
  23. function getInnerHTML(sObjID){
  24.     if (typeof(ID = eval("window." + sObjID)) != "undefined")
  25.         return ID.innerHTML;
  26.     else
  27.         return '<FONT COLOR="RED">Text range for <B>sDataID = "' + sObjID + '"</B> was not found!</FONT>';
  28. }
  29.  
  30. function setHREF(sRoot){
  31.     sRoot = sRoot.toLowerCase()
  32.     var winLoc = analizePath(window.location.href.toLowerCase(), sRoot);
  33.      
  34.     //Display error message if can't determine project root directory
  35.     if (!winLoc.isValid){
  36.         alert("This project is expected to reside in a directory named \"" + sRoot +"\" !\nUnable to insert dynamic contents.");
  37.         return false;
  38.     }
  39.     
  40.     //Restore HREF location for A link objects
  41.     var i=0;
  42.     var elemLnk = document.links;
  43.     for (i=0; i< elemLnk.length; i++){
  44.       var lnkPath = analizePath(elemLnk[i].href.toLowerCase(), sRoot);
  45.       elemLnk[i].href = winLoc.dirBack + lnkPath.filePath + lnkPath.fileName;
  46.     }
  47.  
  48.     //Restore SRC path for IMG image objects
  49.     var i=0;
  50.     var elemImg = document.images;
  51.     for (i=0;i<elemImg.length;i++){
  52.       var imgPath = analizePath(elemImg[i].src.toLowerCase(), sRoot);
  53.       elemImg[i].src = winLoc.dirBack + imgPath.filePath + imgPath.fileName;
  54.     }
  55. return true;
  56. }
  57.  
  58. function analizePath(sPath, sRoot){
  59.     var arrPath = sPath.split("/")
  60.     var newObj = new URLElement();
  61.     
  62.     //Init newObj of type URLElement
  63.     newObj.fileName = newObj.filePath = newObj.dirBack = "" ;
  64.     newObj.isValid  = false  ; newObj.dirLevel = 0;
  65.     
  66.     //Reverse Path array
  67.     arrPath.reverse();
  68.     
  69.     //Get file name, element 0 is now the file name
  70.     newObj.fileName = arrPath[0];
  71.     
  72.     //Get all other element values
  73.     var i=0;
  74.     var len = arrPath.length;
  75.     for (i=1;i<len;i++){
  76.         //test each array element for the provided root directory
  77.         if (arrPath[i]== sRoot){
  78.             newObj.isValid = true;
  79.             i=len;
  80.         }
  81.         else if (!newObj.isValid){
  82.             newObj.filePath = arrPath[i] + "/" + newObj.filePath;
  83.             newObj.dirBack = newObj.dirBack + "../";
  84.             newObj.dirLevel++;
  85.         }
  86.     }
  87.     return newObj;
  88. }
  89. // 
  90. function window.onload(){
  91.     var sRoot = "d3drm" ;
  92.     var oFileInfo = analizePath(window.location.href.toLowerCase(), sRoot);
  93.  
  94.     if(oFileInfo.fileName.indexOf("gloss_") == -1){
  95.         if (typeof(window.external.frozen) != "undefined") {
  96.             if (setHREF(sRoot)) window.external.raiseEvent("evt_DocComplete", window.document);
  97.         }
  98.     }
  99. }