home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / mac / SuperCD / FP.JS < prev    next >
Text File  |  2002-12-16  |  11KB  |  255 lines

  1. /* fp.js
  2.  * Scripts common to Future Publishing installer pages
  3.  * Matt Kynaston (kynaston@yahoo.com), December 2000
  4.  * functions starting with MM_ are from Macromedia Dreamweaver
  5. */
  6.  
  7. /* fp_swapAnchors()
  8.  * if browser is IE4+ goes through document finding anchors pointing to executables
  9.  * and substitutes calls to launch() so IntraLaunch works
  10. */
  11. function fp_swapAnchors() { //v1.0
  12.     if (document.ie4plus) {
  13.         if (document.IntraLaunch) {
  14.             var lnks = document.links;
  15.             for(var i=0;i<lnks.length;i++) { 
  16.                 var href = lnks[i].href;
  17.                 if(href.toLowerCase().indexOf(".exe") == href.length-4) {
  18.                     lnks[i].href = "javascript:launch('"+fp_pathFromRoot(href)+"')";
  19.         }    }    }
  20.         else alert("Alert! The IntraLaunch object is missing from this page. Installing software by clicking links will not work.");
  21. }    }
  22.  
  23. /* fp_pathFromRoot(fileName)
  24.  * returns path from root of CD
  25. */
  26. function fp_pathFromRoot(fn) { //v1.0
  27.     return fn.substring(fn.lastIndexOf("//")+5,fn.length);
  28. }
  29.  
  30. /* launch(fileName)
  31.  * calls VBScript to run file (if IE4+)
  32. */
  33. function launch(fn) { //v1.0
  34.     if (document.ie4plus) {
  35.         fp_LaunchFile(fp_getILPath(fn)); // call to VBScript - make sure it's on doc!
  36. }    }
  37.  
  38. /* fp_getILPath(fileName)
  39.  * return IntraLaunch-style backslashed file path
  40. */
  41. function fp_getILPath(fn) { //v1.0
  42.     return "*:\\" + fp_forwardToBackSlash(fn);              
  43. }
  44.  
  45. /* fp_forwardToBackSlash(fileName)
  46.  * returns string with forward slashes converted to backslashes
  47. */
  48. function fp_forwardToBackSlash(fn) { //v1.0
  49.     return fn.split("/").join("\\");
  50. }
  51.  
  52. /* fp_swapArrow(origImage, newImage)
  53.  * Searches for origImage in the index that is linked to the current documnet
  54.  * and changes it to newImage. Used to highlight the current document
  55.  * in the index. Requires fp_relToAbsolutePath() function.
  56. */
  57. function fp_swapArrow(origImage, newImage) { //v1.0
  58.     var doesDOM = document.getElementsByTagName;
  59.     if (document.ie4plus || doesDOM) {
  60.         var ancs = (doesDOM) ? document.getElementsByTagName("a") : document.all.tags("a");
  61.         var found = false;
  62.         var absOrigPath = fp_relToAbsolutePath(origImage);
  63.         for(var i=0;i<ancs.length && !found;i++) {
  64.             if (document.location.toString().indexOf(ancs[i].href) == 0) {
  65.                 var imgs = (doesDOM) ? ancs[i].getElementsByTagName("img") : ancs[i].all.tags("img");
  66.                 for(var j=0;j<imgs.length && !found;j++) {
  67.                     var imgsrc = imgs[j].src;
  68.                     if (imgsrc.indexOf(absOrigPath) != -1) {
  69.                         imgs[j].src = newImage;
  70.                         found = true; break;
  71. }    }    }    }    }    }
  72.  
  73. function fp_relToAbsolutePath(relPath) {
  74.     var locArr = document.location.toString().split("/");
  75.     var locLen = locArr.length-1;
  76.     var pathArr = relPath.split("/");
  77.     var outArr = new Array;
  78.     var pathStart;
  79.  
  80.     for (var i=0;i<pathArr.length;i++) {
  81.         if (pathArr[i] == "..") {
  82.             locLen--;
  83.         }
  84.         else {
  85.             pathStart = i;
  86.             break;
  87.         }
  88.     }
  89.     for (var i=0;i<locLen;i++) {
  90.         outArr[i] = locArr[i];
  91.     }
  92.     for (var i=0;i<pathArr.length-pathStart;i++) {
  93.         outArr[locLen+i] = pathArr[i+pathStart];
  94.     }
  95.     return outArr.join("/");
  96. }
  97.  
  98. /* fp_checkBrowser()
  99.  * Determine browser and OS
  100.  * should be in body's onload
  101. */
  102. function fp_checkBrowser() { //v1.0
  103.     var bname = navigator.appName.toLowerCase();
  104.     var bVersion = navigator.appVersion.toLowerCase();
  105.     var bVer = parseInt(bVersion);
  106.     var userAgent = navigator.userAgent.toLowerCase();
  107.     
  108.     (bname == "netscape" && bVer >=4) ? document.ns4plus=true : document.ns4plus=false;
  109.     (bname == "microsoft internet explorer" && bVer >= 4) ? document.ie4plus = true : document.ie4plus = false;
  110.     (bVersion.indexOf("msie 5") != -1) ? document.ie5plus = true : document.ie5plus = false;
  111.     (bname.indexOf("netscape") != -1 && bVer >= 6) ? document.ns6plus = true : document.ns6plus = false;
  112.     
  113.     // Opera spoofs IE4 in appName!!
  114.     if (userAgent.indexOf("opera 5") != -1){
  115.         document.op5plus = true;
  116.         document.ie4plus = false;
  117.         document.ns4plus = false;
  118.     }
  119.     else document.op5plus = false;
  120.     
  121.     // Konqueror??
  122.     
  123.     // determine operating system of viewer
  124.     (userAgent.indexOf("linux") != -1) ? document.linux = true : document.linux = false;
  125.     (userAgent.indexOf("Win16") != -1) ? document.win16 = true : document.win16 = false;
  126. }
  127.  
  128. /* fp_runWarning()
  129.  * alerts browsers not capable of installing software to the fact
  130.  * and prevents them proceding
  131. */
  132. function fp_runWarning(){ //v1.0
  133.     var d = document, retVal = false
  134.     if (d.ie4plus) retVal = true;
  135.     else if (d.op5plus) {
  136.         retVal = confirm("Alert! To run files directly from Opera you must choose 'Run file'\nin the next dialog box. If you choose 'Save to disk' the installation\nwill not work.\n\nContinue?");    
  137.     }
  138.     else if (d.ns4plus && fp_getCookie('PCPLUS_CDN') != null) {
  139.         retVal = confirm("Alert! To run files directly from Netscape you must have\nthe Netscape Open/Save dialog enabled. If it is,\nyou will get a 'Security Hazard' dialog box next. Choose 'Open'\nto run the file.\n\nIf you just get a 'Save to disk' dialog, you will not be able to use Netscape\nto install this software.\n\nSee the Netscape page under 'Help' for more information.\n\nDo you wish to continue?");    
  140.     }
  141.     else {
  142.         alert('Alert! This will not work.\n\nYour browser does not allow the execution of files\ndirectly from the SuperDisc. If you do not understand\nthis, click OK, go to the Help section on the SuperDisc\nand read the instructions.');
  143.         retVal = false;
  144.     }
  145.     document.MM_returnValue = retVal;
  146. }
  147.  
  148. /* fp_emailWarning()
  149.  * Warns users that they must have an email client configured to access the mailto link,
  150.  * unless they've set the PCPLUS_CD3 cookie (on the help.htm page). Now why doesn't cancelling 
  151.  * work in NS? Have tried everything, I think...
  152. */
  153. function fp_emailWarning() { //v1.0
  154.     var d = document;
  155.     var retVal = true;
  156.     if (fp_getCookie('PCPLUS_CD3') == null) {
  157.          if (d.ie4plus || d.ns4plus || d.op5plus) {
  158.             retVal = confirm('Accessing this link will require you to have an\ne-mail client set up and integrated correctly.\n\nIf it is you will be taken to a New Message window\nwhere you can type in your message and then send it.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup and\nswitched on.\n\nDo you wish to continue?');
  159.         }
  160.         else {
  161.             alert('Accessing this link will require you to have an\ne-mail client set up and integrated correctly.\n\nIf it is you will be taken to a New Message window\nwhere you can type in your message and then send it.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup and\nswitched on.');
  162.         }
  163.     }
  164.     document.MM_returnValue = retVal;
  165. }
  166.  
  167. /* fp_webWarning()
  168.  * Alerts users they are accessing a remote link that requires an Internet connection.
  169.  * Disabled with the PCPLUS_CD1 cookie, set on the help.htm page
  170. */
  171. function fp_webWarning() { //v1.0
  172.     var d = document, retVal = true;
  173.     if (fp_getCookie('PCPLUS_CD1') == null) {
  174.         if (d.ie4plus || d.ns4plus || d.op5plus) {
  175.             retVal = confirm('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on. Do you wish to continue?');
  176.         }
  177.         else {
  178.             alert('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on.');
  179.         }
  180.     }
  181.     document.MM_returnValue = retVal;
  182. }
  183.  
  184. /* fp_linkWarning()
  185.  * Alerts users they are entering pages authored by a 3rd party, which may contain links
  186.  * to the Internet that will require an Internet connection. Disabled by the PCPLUS_CD5
  187.  * cookie
  188. */
  189. function fp_linkWarning() { //v1.0
  190.     if (fp_getCookie('PCPLUS_CD5') == null) {
  191.         alert('This link takes you to pages authored by a third party.\n\nThey may contain links that lead onto the internet.\nIf you are not connected to a network, you will\nneed a modem and Internet account setup\nand switched on in order to follow them.');
  192.     }
  193. }
  194.  
  195. /* functions to get, set, delete and toggle cookies
  196.  * original stuff written by Dave Taylor - now that's going back a way!
  197.  * Cookies PCPLUS_CD2 & PCPLUS_CD4 were used to supress warnings no longer used
  198.  *     - don't be tempted to use them in case they're still lurking around
  199. */
  200. function fp_setCookie(name, value) { //v1.0
  201.     var exp = new Date();                                          // make new date object
  202.     exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 1000));     // set it 1000 days ahead
  203.     document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString();
  204. }
  205.  
  206. function fp_getCookie(name) { //v1.0
  207.     var cname = name + "=";               
  208.     var dc = document.cookie;             
  209.         if (dc.length > 0) {              
  210.         begin = dc.indexOf(cname);       
  211.             if (begin != -1) {           
  212.             begin += cname.length;       
  213.             end = dc.indexOf(";", begin);
  214.                 if (end == -1) end = dc.length;
  215.                 return unescape(dc.substring(begin, end));
  216.             }
  217.         }
  218.     return null;
  219. }
  220.  
  221. function fp_delCookie(name) { //v1.0
  222.     document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
  223. }
  224.  
  225. function fp_toggle_cookie(num,value) { //v1.0
  226.     if (fp_getCookie('PCPLUS_CD'+num)) fp_delCookie('PCPLUS_CD'+num);
  227.     else fp_setCookie('PCPLUS_CD'+num,value);
  228. }
  229.  
  230.  
  231. /* Macromedia image swapping functions
  232.  * (glad I didn't have to write these 'cause they're dead ugly :)
  233. */
  234. function MM_swapImgRestore() { //v3.0
  235.   var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  236. }
  237.  
  238. function MM_preloadImages() { //v3.0
  239.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  240.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  241.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  242. }
  243.  
  244. function MM_findObj(n, d) { //v4.0
  245.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  246.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  247.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  248.   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  249.   if(!x && document.getElementById) x=document.getElementById(n); return x;
  250. }
  251.  
  252. function MM_swapImage() { //v3.0
  253.   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  254.    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  255. }