home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Utility / 5-11_xp-2k_dd_ccc_wdm_enu_27345.exe / Data1.cab / _D85B6780E4D647218EC41FA0E4D58555 < prev    next >
Text File  |  2003-09-15  |  16KB  |  657 lines

  1. // Copyright (c) 2000-2003 Quadralay Corporation.  All rights reserved.
  2. //
  3.  
  4. function  WWHBrowserUtilities_SearchReplace(ParamString,
  5.                                             ParamSearchString,
  6.                                             ParamReplaceString)
  7. {
  8.   var  ResultString;
  9.   var  Index;
  10.  
  11.  
  12.   ResultString = ParamString;
  13.  
  14.   if ((ParamSearchString.length > 0) &&
  15.       (ResultString.length > 0))
  16.   {
  17.     Index = 0;
  18.     while ((Index = ResultString.indexOf(ParamSearchString, Index)) != -1)
  19.     {
  20.       ResultString = ResultString.substring(0, Index) + ParamReplaceString + ResultString.substring(Index + ParamSearchString.length, ResultString.length);
  21.       Index += ParamReplaceString.length;
  22.     }
  23.   }
  24.  
  25.   return ResultString;
  26. }
  27.  
  28. function  WWHBrowserUtilities_EscapeURLForJavaScriptAnchor(ParamURL)
  29. {
  30.   var  EscapedURL = ParamURL;
  31.  
  32.  
  33.   // Escape problematic characters
  34.   // \ " ' < >
  35.   //
  36.   EscapedURL = WWHBrowserUtilities_SearchReplace(EscapedURL, "\\", "\\\\");
  37.   EscapedURL = WWHBrowserUtilities_SearchReplace(EscapedURL, "\"", "\\u0022");
  38.   EscapedURL = WWHBrowserUtilities_SearchReplace(EscapedURL, "'", "\\u0027");
  39.   EscapedURL = WWHBrowserUtilities_SearchReplace(EscapedURL, "<", "\\u003c");
  40.   EscapedURL = WWHBrowserUtilities_SearchReplace(EscapedURL, ">", "\\u003e");
  41.  
  42.   return EscapedURL;
  43. }
  44.  
  45. function  WWHBrowser_Object()
  46. {
  47.   this.mLocale                 = "en";
  48.   this.mPlatform               = 0;      // Shorthand for Unknown
  49.   this.mBrowser                = 0;      // Shorthand for Unknown
  50.   this.mCookiePath             = "/";
  51.   this.mbCookiesEnabled        = null;
  52.   this.mbSupportsFocus         = false;
  53.   this.mbSupportsPopups        = true;
  54.   this.mbSupportsFrameRenaming = true;
  55.   this.mbWindowIE40            = false;  // Needed for special case handling
  56.   this.mbMacIE45               = false;  // Needed for special case handling
  57.   this.mbMacIE50               = false;  // Needed for special case handling
  58.   this.mbUnescapeHREFs         = true;   // Needed for special case handling
  59.   this.mbWindowsIE60           = false;  // Needed for special case handling
  60.   this.mbUnsupported           = false;
  61.   this.mbJavaCapable           = false;
  62.   this.mbJavaEnabled           = false;
  63.  
  64.   this.fInitialize           = WWHBrowser_Initialize;
  65.   this.fNormalizeURL         = WWHBrowser_NormalizeURL;
  66.   this.fRestoreEscapedSpaces = WWHBrowser_RestoreEscapedSpaces;
  67.   this.fSetLocation          = WWHBrowser_SetLocation;
  68.   this.fReplaceLocation      = WWHBrowser_ReplaceLocation;
  69.   this.fReloadLocation       = WWHBrowser_ReloadLocation;
  70.   this.fSetCookiePath        = WWHBrowser_SetCookiePath;
  71.   this.fCookiesEnabled       = WWHBrowser_CookiesEnabled;
  72.   this.fSetCookie            = WWHBrowser_SetCookie;
  73.   this.fGetCookie            = WWHBrowser_GetCookie;
  74.   this.fDeleteCookie         = WWHBrowser_DeleteCookie;
  75.   this.fFocus                = WWHBrowser_Focus;
  76.  
  77.   // Initialize object
  78.   //
  79.   this.fInitialize();
  80. }
  81.  
  82. function  WWHBrowser_Initialize()
  83. {
  84.   var  Agent;
  85.   var  MajorVersion = 0;
  86.   var  VersionString;
  87.   var  Version = 0.0;
  88.  
  89.  
  90.   // Reset locale to correct language value
  91.   //
  92.   if ((typeof(navigator.language) != "undefined") &&
  93.       (navigator.language != null))
  94.   {
  95.     this.mLocale = navigator.language;
  96.   }
  97.   else if ((typeof(navigator.userLanguage) != "undefined") &&
  98.            (navigator.userLanguage != null))
  99.   {
  100.     this.mLocale = navigator.userLanguage;
  101.   }
  102.  
  103.   // Convert everything to lowercase
  104.   //
  105.   this.mLocale = this.mLocale.toLowerCase();
  106.  
  107.   // Replace '-'s with '_'s
  108.   //
  109.   this.mLocale = WWHBrowserUtilities_SearchReplace(this.mLocale, "-", "_");
  110.  
  111.   // Get browser info
  112.   //
  113.   Agent = navigator.userAgent.toLowerCase();
  114.  
  115.   // Determine platform
  116.   //
  117.   if ((Agent.indexOf("win") != -1) ||
  118.       (Agent.indexOf("16bit") != -1))
  119.   {
  120.     this.mPlatform = 1;  // Shorthand for Windows
  121.   }
  122.   else if (Agent.indexOf("mac") != -1)
  123.   {
  124.     this.mPlatform = 2;  // Shorthand for Macintosh
  125.   }
  126.  
  127.   // Determine browser
  128.   //
  129.   if ((Agent.indexOf("mozilla") != -1) &&
  130.       (Agent.indexOf("spoofer") == -1) &&
  131.       (Agent.indexOf("compatible") == -1))
  132.   {
  133.     MajorVersion = parseInt(navigator.appVersion)
  134.  
  135.     if (MajorVersion >= 5)
  136.     {
  137.       this.mBrowser = 4;  // Shorthand for Netscape 6.0
  138.       this.mbSupportsFocus = true;
  139.  
  140.       // Netscape 6.0 is unsupported
  141.       //
  142.       if (navigator.userAgent.indexOf("m18") != -1)
  143.       {
  144.         this.mbUnsupported = true;
  145.       }
  146.     }
  147.     else if (MajorVersion >= 4)
  148.     {
  149.       this.mBrowser = 1;  // Shorthand for Netscape
  150.  
  151.       this.mbSupportsFrameRenaming = false;
  152.     }
  153.   }
  154.   else if (Agent.indexOf("msie") != -1)
  155.   {
  156.     MajorVersion = parseInt(navigator.appVersion)
  157.     if (MajorVersion >= 4)
  158.     {
  159.       this.mBrowser = 2;  // Shorthand for IE
  160.       this.mbSupportsFocus = true;
  161.  
  162.       // Additional info needed for popups
  163.       //
  164.       VersionString = navigator.appVersion.toLowerCase();
  165.       MSIEVersionString = VersionString.substring(VersionString.indexOf("msie") + 4);
  166.       Version = parseFloat(MSIEVersionString);
  167.       if ((Version >= 4.0) &&
  168.           (Version < 4.1))
  169.       {
  170.         if (this.mPlatform == 1)  // Shorthand for Windows
  171.         {
  172.           this.mbWindowsIE40 = true;
  173.         }
  174.       }
  175.       else if ((Version >= 4.5) &&
  176.                (Version < 4.6))
  177.       {
  178.         if (this.mPlatform == 2)  // Shorthand for Macintosh
  179.         {
  180.           this.mbMacIE45 = true;
  181.         }
  182.       }
  183.       else if ((Version >= 5.0) &&
  184.                (Version < 5.1))
  185.       {
  186.         if (this.mPlatform == 2)  // Shorthand for Macintosh
  187.         {
  188.           this.mbMacIE50 = true;
  189.         }
  190.       }
  191.       else if (Version >= 6.0)
  192.       {
  193.         this.mbWindowsIE60 = true;
  194.       }
  195.     }
  196.   }
  197.   else if (Agent.indexOf("icab") != -1)
  198.   {
  199.     this.mBrowser = 3;  // Shorthand for iCab
  200.  
  201.     this.mbSupportsPopups = false;
  202.   }
  203.  
  204.   // Safari may spoof as just about anything
  205.   //
  206.   if (Agent.indexOf("safari") != -1)
  207.   {
  208.     this.mBrowser = 5;  // Shorthand for Safari
  209.  
  210.     this.mbSupportsPopups = true;
  211.     this.mbSupportsFocus = false;
  212.   }
  213.  
  214.   // Set mbUnescapeHREFs boolean
  215.   //
  216.   if ((this.mBrowser == 2) &&  // Shorthand for IE
  217.       (this.mPlatform == 1))   // Shorthand for Windows
  218.   {
  219.     if (MajorVersion >= 5)
  220.     {
  221.       this.mbUnescapeHREFs = false;
  222.     }
  223.   }
  224.  
  225.   // Determine if platform can support Java
  226.   //
  227.   this.mbJavaCapable = false;
  228.   if (this.mBrowser == 1)  // Shorthand for Netscape
  229.   {
  230.     if (this.mPlatform == 1)  // Shorthand for Windows
  231.     {
  232.       this.mbJavaCapable = true;  // Java works on NS for Windows
  233.     }
  234.     else if (this.mPlatform == 2)  // Shorthand for Macintosh
  235.     {
  236.       this.mbJavaCapable = false;  // Java doesn't work on NS for Macintosh
  237.     }
  238.     else
  239.     {
  240.       this.mbJavaCapable = true;  // Java is slow on UNIX
  241.     }
  242.   }
  243.   else if (this.mBrowser == 2)  // Shorthand for IE
  244.   {
  245.     if (this.mPlatform == 1)  // Shorthand for Windows
  246.     {
  247.       this.mbJavaCapable = true;  // Java works on IE for Windows
  248.     }
  249.     else if (this.mPlatform == 2)  // Shorthand for Macintosh
  250.     {
  251.       this.mbJavaCapable = true;  // May work
  252.     }
  253.     else
  254.     {
  255.       this.mbJavaCapable = false;  // Java doesn't work on IE for UNIX
  256.     }
  257.   }
  258.   else if (this.mBrowser == 4)  // Shorthand for Mozilla
  259.   {
  260.     if (this.mPlatform == 1)  // Shorthand for Windows
  261.     {
  262.       this.mbJavaCapable = true;  // May work
  263.     }
  264.     else if (this.mPlatform == 2)  // Shorthand for Macintosh
  265.     {
  266.       this.mbJavaCapable = false;  // Hangs in Mozilla 1.2.1
  267.     }
  268.     else
  269.     {
  270.       this.mbJavaCapable = true;  // Java unreliable under UNIX (works?)
  271.     }
  272.   }
  273.   else
  274.   {
  275.     this.mbJavaCapable = true;  // May work
  276.   }
  277.  
  278.   // Determine if Java is enabled
  279.   //
  280.   if ((typeof(navigator) != "undefined") &&
  281.       (navigator != null))
  282.   {
  283.     this.mbJavaEnabled = navigator.javaEnabled();
  284.   }
  285. }
  286.  
  287. function  WWHBrowser_NormalizeURL(ParamURL)
  288. {
  289.   var  URL = ParamURL;
  290.   var  Parts;
  291.   var  MaxIndex;
  292.   var  Index;
  293.   var  DrivePattern;
  294.   var  DrivePatternMatch;
  295.  
  296.  
  297.   // Unescape URL for most browsers
  298.   //
  299.   if (this.mbUnescapeHREFs)
  300.   {
  301.     URL = unescape(URL);
  302.   }
  303.   else  // IE unescapes everything automatically, except &
  304.   {
  305.     URL = WWHBrowserUtilities_SearchReplace(URL, "%26", "&");
  306.   }
  307.  
  308.   // Standardize protocol case
  309.   //
  310.   if (URL.indexOf(":") != -1)
  311.   {
  312.     Parts = URL.split(":");
  313.  
  314.     URL = Parts[0].toLowerCase();
  315.     for (MaxIndex = Parts.length, Index = 1 ; Index < MaxIndex ; Index++)
  316.     {
  317.       URL += ":" + Parts[Index];
  318.     }
  319.   }
  320.  
  321.   // Handle drive letters under Windows
  322.   //
  323.   if (this.mPlatform == 1)  // Shorthand for Windows
  324.   {
  325.     DrivePattern = new RegExp("^file:[/]+([a-zA-Z])[:\|][/](.*)$", "i");
  326.     DrivePatternMatch = DrivePattern.exec(URL);
  327.     if (DrivePatternMatch != null)
  328.     {
  329.       URL = "file:///" + DrivePatternMatch[1] + ":/" + DrivePatternMatch[2];
  330.     }
  331.   }
  332.  
  333.   return URL;
  334. }
  335.  
  336. function  WWHBrowser_RestoreEscapedSpaces(ParamURL)
  337. {
  338.   // Workaround for stupid Netscape 4.x bug
  339.   //
  340.   var  StringWithSpace = "x x";
  341.   var  EscapedURL = ParamURL;
  342.  
  343.  
  344.   if (this.mbUnescapeHREFs)
  345.   {
  346.     EscapedURL = WWHBrowserUtilities_SearchReplace(EscapedURL, StringWithSpace.substring(1, 2), "%20");
  347.   }
  348.  
  349.   return EscapedURL;
  350. }
  351.  
  352. function  WWHBrowser_SetLocation(ParamFrameReference,
  353.                                  ParamURL)
  354. {
  355.   var  EscapedURL;
  356.  
  357.  
  358.   EscapedURL = WWHBrowserUtilities_EscapeURLForJavaScriptAnchor(ParamURL);
  359.   setTimeout(ParamFrameReference + ".location = \"" + EscapedURL + "\";", 1);
  360. }
  361.  
  362. function  WWHBrowser_ReplaceLocation(ParamFrameReference,
  363.                                      ParamURL)
  364. {
  365.   var  EscapedURL;
  366.  
  367.  
  368.   EscapedURL = WWHBrowserUtilities_EscapeURLForJavaScriptAnchor(ParamURL);
  369.   setTimeout(ParamFrameReference + ".location.replace(\"" + EscapedURL + "\");", 1);
  370. }
  371.  
  372. function  WWHBrowser_ReloadLocation(ParamFrameReference)
  373. {
  374.   var  VarFrame;
  375.  
  376.  
  377.   VarFrame = eval(ParamFrameReference);
  378.   this.fReplaceLocation(ParamFrameReference, VarFrame.location.href);
  379. }
  380.  
  381. function  WWHBrowser_SetCookiePath(ParamURL)
  382. {
  383.   var  Pathname;
  384.   var  WorkingURL;
  385.   var  Parts;
  386.   var  Index;
  387.   var  Protocol = "";
  388.  
  389.  
  390.   // Initialize return value
  391.   //
  392.   Pathname = "/";
  393.  
  394.   // Remove URL parameters
  395.   //
  396.   WorkingURL = ParamURL;
  397.   if (WorkingURL.indexOf("?") != -1)
  398.   {
  399.     Parts = WorkingURL.split("?");
  400.     WorkingURL = Parts[0];
  401.   }
  402.  
  403.   // Remove last entry if path does not end with /
  404.   //
  405.   Index = WorkingURL.lastIndexOf("/");
  406.   if ((Index + 1) < WorkingURL.length)
  407.   {
  408.     WorkingURL = WorkingURL.substring(0, Index);
  409.   }
  410.  
  411.   // Remove protocol
  412.   //
  413.   Index = -1;
  414.   if (WorkingURL.indexOf("http:/") == 0)
  415.   {
  416.     Index = WorkingURL.indexOf("/", 6);
  417.     Protocol = "http";
  418.   }
  419.   else if (WorkingURL.indexOf("ftp:/") == 0)
  420.   {
  421.     Index = WorkingURL.indexOf("/", 5);
  422.     Protocol = "ftp";
  423.   }
  424.   else if (WorkingURL.indexOf("file:///") == 0)
  425.   {
  426.     Index = 7;
  427.     Protocol = "file";
  428.   }
  429.  
  430.   // Set base URL pathname
  431.   //
  432.   if (Index != -1)
  433.   {
  434.     Pathname = WorkingURL.substring(Index, WorkingURL.length);
  435.  
  436.     // Clean up pathname
  437.     //
  438.     if (Protocol == "file")
  439.     {
  440.       if (this.mPlatform == 1)  // Shorthand for Windows
  441.       {
  442.         if (this.mBrowser == 2)  // Shorthand for IE
  443.         {
  444.           // file URLs must have slashes replaced with backslashes, except the first one
  445.           //
  446.           if (Pathname.length > 1)
  447.           {
  448.             Pathname = unescape(Pathname);
  449.             Pathname = WWHBrowserUtilities_SearchReplace(Pathname, "/", "\\");
  450.             if (Pathname.indexOf("\\") == 0)
  451.             {
  452.               Pathname = "/" + Pathname.substring(1, Pathname.length);
  453.             }
  454.           }
  455.         }
  456.       }
  457.     }
  458.     else
  459.     {
  460.       // Trim server info
  461.       //
  462.       Index = Pathname.indexOf("/", Index);
  463.       if (Index != -1)
  464.       {
  465.         Pathname = Pathname.substring(Index, Pathname.length);
  466.       }
  467.       else
  468.       {
  469.         Pathname = "/";
  470.       }
  471.     }
  472.   }
  473.  
  474.   // Set cookie path
  475.   //
  476.   this.mCookiePath = Pathname;
  477. }
  478.  
  479. function  WWHBrowser_CookiesEnabled()
  480. {
  481.   // Cache result
  482.   //
  483.   if (this.mbCookiesEnabled == null)
  484.   {
  485.     // Default to disabled
  486.     //
  487.     this.mbCookiesEnabled = false;
  488.  
  489.     // Try setting a cookie
  490.     //
  491.     this.fSetCookie("WWHBrowser_CookiesEnabled", "True");
  492.  
  493.     // Retrieve the cookie
  494.     //
  495.     if (this.fGetCookie("WWHBrowser_CookiesEnabled") != null)
  496.     {
  497.       // Delete the test cookie
  498.       //
  499.       this.fDeleteCookie("WWHBrowser_CookiesEnabled");
  500.  
  501.       // Success!
  502.       //
  503.       this.mbCookiesEnabled = true;
  504.     }
  505.   }
  506.  
  507.   return this.mbCookiesEnabled;
  508. }
  509.  
  510. function  WWHBrowser_SetCookie(ParamName,
  511.                                ParamValue,
  512.                                ParamExpiration)
  513. {
  514.   var  VarFormattedCookie;
  515.   var  VarPath;
  516.   var  VarExpirationDate;
  517.  
  518.  
  519.   // Format the cookie
  520.   //
  521.   VarFormattedCookie = escape(ParamName) + "=" + escape(ParamValue);
  522.  
  523.   // Add path
  524.   //
  525.   VarFormattedCookie += "; path=" + this.mCookiePath;
  526.  
  527.   // Add expiration day, if specified
  528.   //
  529.   if ((typeof(ParamExpiration) != "undefined") &&
  530.       (ParamExpiration != null) &&
  531.       (ParamExpiration != 0))
  532.   {
  533.     VarExpirationDate = new Date();
  534.     VarExpirationDate.setTime(VarExpirationDate.getTime() + (ParamExpiration * 1000 * 60 * 60 * 24));
  535.     VarFormattedCookie += "; expires=" + VarExpirationDate.toGMTString();
  536.   }
  537.  
  538.   // Set the cookie for the specified document
  539.   //
  540.   document.cookie = VarFormattedCookie
  541. }
  542.  
  543. function  WWHBrowser_GetCookie(ParamName)
  544. {
  545.   var  VarValue;
  546.   var  VarCookies;
  547.   var  VarKey;
  548.   var  VarStartIndex;
  549.   var  VarEndIndex;
  550.  
  551.  
  552.   // Initialize return value
  553.   //
  554.   VarValue = null;
  555.  
  556.   // Get document cookies
  557.   //
  558.   VarCookies = document.cookie;
  559.  
  560.   // Parse out requested cookie
  561.   //
  562.  
  563.   // Try first position
  564.   //
  565.   VarKey = escape(ParamName) + "=";
  566.   VarStartIndex = VarCookies.indexOf(VarKey);
  567.   if (VarStartIndex != 0)
  568.   {
  569.     // Try any other position
  570.     //
  571.     VarKey = "; " + escape(ParamName) + "=";
  572.     VarStartIndex = VarCookies.indexOf(VarKey);
  573.   }
  574.  
  575.   // Match found?
  576.   //
  577.   if (VarStartIndex != -1)
  578.   {
  579.     // Advance past cookie key
  580.     //
  581.     VarStartIndex += VarKey.length;
  582.  
  583.     // Find end
  584.     //
  585.     VarEndIndex = VarCookies.indexOf(";", VarStartIndex);
  586.     if (VarEndIndex == -1)
  587.     {
  588.       VarEndIndex = VarCookies.length;
  589.     }
  590.     VarValue = unescape(VarCookies.substring(VarStartIndex, VarEndIndex));
  591.   }
  592.  
  593.   return VarValue;
  594. }
  595.  
  596. function  WWHBrowser_DeleteCookie(ParamName)
  597. {
  598.   // Set cookie to expire yesterday
  599.   //
  600.   this.fSetCookie(ParamName, "", -1);
  601. }
  602.  
  603. function  WWHBrowser_Focus(ParamFrameReference,
  604.                            ParamAnchorName)
  605. {
  606.   var  VarFrame;
  607.   var  VarAnchor;
  608.   var  VarMaxIndex;
  609.   var  VarIndex;
  610.  
  611.  
  612.   if (this.mbSupportsFocus)
  613.   {
  614.     if (ParamFrameReference.length > 0)
  615.     {
  616.       // Access frame
  617.       //
  618.       VarFrame = eval(ParamFrameReference);
  619.  
  620.       // Focus frame
  621.       //
  622.       VarFrame.focus();
  623.  
  624.       // Focusing anchor?
  625.       //
  626.       if ((typeof(ParamAnchorName) != "undefined") &&
  627.           (ParamAnchorName != null) &&
  628.           (ParamAnchorName.length > 0))
  629.       {
  630.         // Focus anchor
  631.         //
  632.         VarAnchor = VarFrame.document.anchors[ParamAnchorName];
  633.         if ((typeof(VarAnchor) != "undefined") &&
  634.             (VarAnchor != null))
  635.         {
  636.           VarAnchor.focus();
  637.         }
  638.         else
  639.         {
  640.           VarAnchorArray = VarFrame.document.anchors;
  641.           for (VarMaxIndex = VarFrame.document.anchors.length, VarIndex = 0 ; VarIndex < VarMaxIndex ; VarIndex++)
  642.           {
  643.             if (VarFrame.document.anchors[VarIndex].name == ParamAnchorName)
  644.             {
  645.               VarFrame.document.anchors[VarIndex].focus();
  646.  
  647.               // Exit loop
  648.               //
  649.               VarIndex = VarMaxIndex;
  650.             }
  651.           }
  652.         }
  653.       }
  654.     }
  655.   }
  656. }
  657.