home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 August / Chip_2004-08_cd2.bin / avid_dvfree / info / limit_soubory / Detector.js < prev    next >
Text File  |  2004-06-17  |  16KB  |  573 lines

  1. /*********************************************************************
  2.  *
  3.  * Macromedia Flash Dispatcher -- a scriptable detector for Flash Player
  4.  *
  5.  *
  6.  * copyright (c) 2000 Macromedia, Inc.
  7.  *
  8.  *********************************************************************/
  9.  
  10.  
  11. /*
  12.  * URL of the Flash self-detecting movie ("sniffer").
  13.  *
  14.  * Reset this if you move the file out of the directory in which the
  15.  * document containing the script that calls MM_FlashDispatch() resides.
  16.  */
  17.  
  18. var MM_FlashSnifferURL = "detectFlash.swf";
  19.  
  20.  
  21. /*
  22.  * Latest available revisions of the Plug-in.
  23.  */
  24.  
  25. var MM_latestPluginRevision = new Object();
  26. MM_latestPluginRevision["5.0"] = new Object();
  27. MM_latestPluginRevision["4.0"] = new Object();
  28. MM_latestPluginRevision["3.0"] = new Object();
  29. MM_latestPluginRevision["2.0"] = new Object();
  30.  
  31. /*
  32.  * This table must be updated as new versions and revisions of the
  33.  * plug-in are released, in support of the 'requireLatestRevision'
  34.  * option in MM_FlashDispatch().
  35.  */
  36.  
  37. MM_latestPluginRevision["5.0"]["Windows"] = 30;
  38. MM_latestPluginRevision["5.0"]["Macintosh"] = 30;
  39.  
  40. MM_latestPluginRevision["4.0"]["Windows"] = 28;
  41. MM_latestPluginRevision["4.0"]["Macintosh"] = 27;
  42. MM_latestPluginRevision["4.0"]["Unix"] = 12;
  43.  
  44. MM_latestPluginRevision["3.0"]["Windows"] = 10;
  45. MM_latestPluginRevision["3.0"]["Macintosh"] = 10;
  46.  
  47. MM_latestPluginRevision["2.0"]["Windows"] = 11;
  48. MM_latestPluginRevision["2.0"]["Macintosh"] = 11;
  49.  
  50.  
  51. /*
  52.  * MM_FlashInfo() -- construct an object representing Flash Player status
  53.  *
  54.  * Constructor:
  55.  *
  56.  *    new MM_FlashInfo()
  57.  *
  58.  * Properties:
  59.  *
  60.  *    installed        true if player is installed
  61.  *                (undefined if undetectable)
  62.  *
  63.  *    implementation        the form the player takes in this
  64.  *                browser: "ActiveX control" or "Plug-in"
  65.  *
  66.  *    autoInstallable        true if the player can be automatically
  67.  *                installed/updated on this browser/platform
  68.  *
  69.  *    version            player version if installed
  70.  *
  71.  *    revision        revision if implementation is "Plug-in"
  72.  *
  73.  * Methods:
  74.  *
  75.  *    canPlay(contentVersion)    true if installed player is capable of
  76.  *                playing content authored with the
  77.  *                specified version of Flash software
  78.  *
  79.  * Description:
  80.  *
  81.  *    MM_FlashInfo() instantiates an object that contains as much
  82.  *    information about Flash Player--whether it is installed, what
  83.  *    version is installed, and so one--as is possible to collect.
  84.  *
  85.  *    Where Flash Player is implemented as a plug-in and the user's
  86.  *    browser supports plug-in detection, all properties are defined;
  87.  *    this includes Netscape on all platforms and Microsoft Internet
  88.  *    Explorer 5 on the Macintosh.  Where Flash Player is implemented
  89.  *    as an ActiveX control (MSIE on Windows), all properties except
  90.  *    'revision' are defined.
  91.  *
  92.  *    Prior to version 5, Microsoft Internet Explorer on the Macintosh
  93.  *    did not support plug-in detection.  In this case, no properties
  94.  *    are defined, unless the cookie 'MM_FlashDetectedSelf' has been
  95.  *    set, in which case all properties except 'version' and 'revision'
  96.  *    are set.
  97.  *
  98.  *    This object is primarily meant for use by MM_FlashDispatch(), but
  99.  *    may be of use in reporting the player version, etc. to the user.
  100.  */
  101.  
  102. var MM_FlashControlInstalled;    // is the Flash ActiveX control installed?
  103. var MM_FlashControlVersion;    // ActiveX control version if installed
  104.  
  105. function MM_FlashInfo()
  106. {
  107.     if (navigator.plugins && navigator.plugins.length > 0)
  108.     {
  109.     this.implementation = "Plug-in";
  110.     this.autoInstallable = false;    // until Netscape SmartUpdate supported
  111.  
  112.     // Check whether the plug-in is installed:
  113.  
  114.     if (navigator.plugins["Shockwave Flash"])
  115.     {
  116.         this.installed = true;
  117.  
  118.         // Get the plug-in version and revision:
  119.  
  120.         var words =
  121.         navigator.plugins["Shockwave Flash"].description.split(" ");
  122.  
  123.         for (var i = 0; i < words.length; ++i)
  124.         {
  125.         if (isNaN(parseInt(words[i])))
  126.         continue;
  127.  
  128.         this.version = words[i];
  129.  
  130.  
  131.         this.revision = parseInt(words[i + 1].substring(1));
  132.         }
  133.     }
  134.     else
  135.     {
  136.         this.installed = false;
  137.     }
  138.     }
  139.     else if (MM_FlashControlInstalled != null)
  140.     {
  141.     this.implementation = "ActiveX control";
  142.     this.installed = MM_FlashControlInstalled;
  143.     this.version = MM_FlashControlVersion;
  144.     this.autoInstallable = true;
  145.     }
  146.     else if (MM_FlashDetectedSelf())
  147.     {
  148.     this.installed = true;
  149.     this.implementation = "Plug-in";
  150.     this.autoInstallable = false;
  151.     }
  152.  
  153.     this.canPlay = MM_FlashCanPlay;
  154. }
  155.  
  156.  
  157. /*
  158.  * MM_FlashDispatch() -- get Flash Player status and redirect appropriately
  159.  *
  160.  * Synopsis:
  161.  *
  162.  *    MM_FlashDispatch(contentURL, contentVersion, requireLatestRevision,
  163.  *             upgradeURL, install, installURL, altURL,
  164.  *             overridePluginsPage)
  165.  *
  166.  *    Arguments:
  167.  *
  168.  *        contentURL            URL of document containing Flash content
  169.  *
  170.  *        contentVersion        version of Flash software used to
  171.  *                    author content
  172.  *
  173.  *        requireLatestRevision    Boolean indicating whether to require
  174.  *                    latest revision of player (plug-in only)
  175.  *
  176.  *        upgradeURL            document to load if player must be
  177.  *                    upgraded to play content and automated
  178.  *                    updating is not supported on the user's
  179.  *                    browser & platform
  180.  *
  181.  *        install            Boolean indicating whether to install
  182.  *                    if player is not installed
  183.  *
  184.  *        installURL            document to load if 'install' is true
  185.  *                    and automated installation is not
  186.  *                    supported on user's browser & platform
  187.  *
  188.  *        altURL            document to load if 'install' is false
  189.  *
  190.  *        overridePluginsPage        Boolean indicating whether to set the
  191.  *                    PLUGINSPAGE attribute for the embedded
  192.  *                    Flash Player sniffer to `installURL'
  193.  *
  194.  *    Returns:
  195.  *
  196.  *        Normally, never returns; changes window.location.
  197.  *        Returns with no value when called improperly.
  198.  *
  199.  * Description:
  200.  *
  201.  *    MM_FlashDispatch() detects whether the user's Web browser has the
  202.  *    Flash plug-in or ActiveX control installed, and what version is
  203.  *    installed if so. It then takes appropriate action based on whether
  204.  *    Flash Player is installed and is compatible with 'contentVersion':
  205.  *    load a document containing Flash content, load alternate content,
  206.  *    or oversee the updating or installation of the player.
  207.  *
  208.  *    There are three possible outcomes of the detection process: 
  209.  *
  210.  *        1. A version of Flash Player has been detected that is
  211.  *           suitable for playing the requested content version.
  212.  *           MM_FlashDispatch() will load 'contentURL'.
  213.  *
  214.  *        2. An unsuitable version of Flash Player has been detected.
  215.  *           MM_FlashDispatch() will load 'contentURL' if automated
  216.  *           updating is supported on the user's browser & platform;
  217.  *           otherwise, it will load 'upgradeURL'.
  218.  *
  219.  *        3. Flash Player is not installed.  If 'install' is set to
  220.  *           true, MM_FlashDispatch() will load 'contentURL' if the
  221.  *           user's browser supports automated installation; otherwise,
  222.  *           it will load 'installURL'.  If 'install' is false,
  223.  *           MM_FlashDispatch() will load 'altURL'.
  224.  *
  225.  *    When script-based detection of Flash Player is not possible,
  226.  *    MM_FlashDispatch() attempts to load a Flash movie to carry out
  227.  *    the detection. If Flash Player is not installed, there is presently
  228.  *    no choice but to let the browser redirect the user via the
  229.  *    PLUGINSPAGE attribute of the EMBED tag. In this case, 'install'
  230.  *    is ignored, but setting 'overridePluginsPage' to true will
  231.  *    set PLUGINSPAGE to 'installURL', overriding its default value
  232.  *    (the URL for the Macromedia Flash download center). If this flag
  233.  *    is set, 'installURL' must be absolute, not relative.
  234.  */
  235.  
  236. var MM_FlashPluginsPage = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
  237.  
  238. function MM_FlashDispatch(contentURL, contentVersion, requireLatestRevision,
  239.               upgradeURL, install, installURL, altURL,
  240.               overridePluginsPage)
  241. {
  242.     if (overridePluginsPage == null)
  243.     {
  244.     alert("ERROR: MM_FlashDispatch() called with too few arguments.");
  245.     return false;
  246.     }
  247.  
  248.  
  249.     if (overridePluginsPage && installURL.substring(0, 7) != "http://")
  250.     {
  251.     alert("ERROR: MM_FlashDispatch() called with relative URL" +
  252.         " for PLUGINSPAGE (" + installURL + ")");
  253.  
  254.     return false;
  255.     }
  256.  
  257.     var player = new MM_FlashInfo();
  258.     //alert(player);
  259.  
  260.     if (player.installed)
  261.     {
  262.         //queryString+="&flv="+player.version;
  263.         //contentURL+="?"+queryString;
  264.         if (player.canPlay(contentVersion, requireLatestRevision))
  265.             {
  266.                 //location = contentURL;
  267.                 //alert('returning true');
  268.                 return true;
  269.             }
  270.     //else
  271.     //{
  272.         //location = player.autoInstallable ? contentURL : upgradeURL;
  273.         //return player.autoInstallable ? true : false;
  274.     //}
  275.    // }
  276.     //else if (install)
  277.     //{
  278.         //location = player.autoInstallable ? contentURL : installURL;
  279.         //return player.autoInstallable ? true : false;
  280.  
  281.     //}
  282.             else
  283.             {
  284.             //location = altURL;
  285.             return false;
  286.             }
  287.     }
  288. }
  289.  
  290.  
  291. /*
  292.  * MM_FlashRememberIfDetectedSelf() -- record that Flash Player detected itself
  293.  *
  294.  * Synopsis:
  295.  *
  296.  *    MM_FlashRememberIfDetectedSelf()
  297.  *    MM_FlashRememberIfDetectedSelf(count)
  298.  *    MM_FlashRememberIfDetectedSelf(count, units)
  299.  *
  300.  *    Arguments:
  301.  *
  302.  *        count        length of time in units before re-checking
  303.  *                whether content can be played (default: 60)
  304.  *
  305.  *        units        unit(s) of time to count: "minute(s)," "hour(s)"
  306.  *                 or "day(s)" (default: "days")
  307.  *
  308.  *
  309.  * Description:
  310.  *
  311.  *    This function conditionally sets a cookie signifying that
  312.  *    the current document was referred via the Dispatcher using
  313.  *    Flash Player self-detection.  It is intended to spare the user
  314.  *    whose browser does not support script-based detection from the
  315.  *    process of Flash Player self-detection on each visit.
  316.  *    
  317.  *    The cookie persists for 60 days, or for the amount of time
  318.  *    specified by the 'count' and 'units' parameters.
  319.  *
  320.  *    If cookies are not being accepted, this function is a no-op;
  321.  *    the Dispatcher will simply attempt Flash Player self-detection
  322.  *    on subsequent visits.
  323.  *
  324.  *    This function must be called from a script embedded in the
  325.  *    document referenced by the 'contentURL' argument to
  326.  *    MM_FlashDispatch().
  327.  *
  328.  */
  329.  
  330. function MM_FlashRememberIfDetectedSelf(count, units)
  331. {
  332.     // the sniffer appends an empty search string to the URL
  333.     // to indicate that it is the referrer
  334.  
  335.     if (document.location.search.indexOf("?") != -1)
  336.     {
  337.     if (!count) count = 60;
  338.     if (!units) units = "days";
  339.  
  340.     var msecs = new Object();
  341.  
  342.     msecs.minute = msecs.minutes = 60000;
  343.     msecs.hour = msecs.hours = 60 * msecs.minute;
  344.     msecs.day = msecs.days = 24 * msecs.hour;
  345.  
  346.     var expires = new Date();
  347.  
  348.     expires.setTime(expires.getTime() + count * msecs[units]);
  349.  
  350.     document.cookie =
  351.         'MM_FlashDetectedSelf=true ; expires=' + expires.toGMTString();
  352.     }
  353. }
  354.  
  355.  
  356. /*
  357.  * MM_FlashDemur() -- record user's decision not to install Flash Player
  358.  *
  359.  * Synopsis:
  360.  *
  361.  *    MM_FlashDemur()
  362.  *    MM_FlashDemur(count)
  363.  *    MM_FlashDemur(count, units)
  364.  *
  365.  *    Arguments:
  366.  *
  367.  *        count    length of time in units to remember decision
  368.  *            (default: 60)
  369.  *
  370.  *        units    unit(s) of time to count: "minute(s)," "hour(s)"
  371.  *            or "day(s)" (default: "days")
  372.  *
  373.  *    Returns:
  374.  *
  375.  *        true if successful; false otherwise.
  376.  *
  377.  * Description:
  378.  *
  379.  *    MM_FlashDemur() sets a cookie signifying that the user requested
  380.  *    that the decision not to install Flash be remembered.
  381.  *
  382.  *    The cookie persists for 60 days, or for the amount of time
  383.  *    specified by the 'count' and 'units' parameters.
  384.  *
  385.  *    This function may be used as the handler for the 'onClick' event
  386.  *    associated with the user's selecting a link to alternate content.
  387.  *    If cookies are not being accepted, it will return false; this
  388.  *    may be used to control whether the link is followed.
  389.  */
  390.  
  391. function MM_FlashDemur(count, units)
  392. {
  393.     if (!count) count = 60;
  394.     if (!units) units = "days";
  395.  
  396.     var msecs = new Object();
  397.  
  398.     msecs.minute = msecs.minutes = 60000;
  399.     msecs.hour = msecs.hours = 60 * msecs.minute;
  400.     msecs.day = msecs.days = 24 * msecs.hour;
  401.  
  402.     var expires = new Date();
  403.  
  404.     expires.setTime(expires.getTime() + count * msecs[units]);
  405.  
  406.     document.cookie =
  407.     'MM_FlashUserDemurred=true ; expires=' + expires.toGMTString();
  408.  
  409.  
  410.     if (!MM_FlashUserDemurred())
  411.     {
  412.     alert("Your browser must accept cookies in order to " +
  413.           "save this information.  Try changing your preferences.");
  414.  
  415.     return false;
  416.     }
  417.     else
  418.     return true;
  419. }
  420.  
  421.  
  422. /*
  423.  * MM_FlashUserDemurred() -- recall user's decision not to install Flash Player
  424.  *
  425.  * Synopsis:
  426.  *
  427.  *    MM_FlashUserDemurred()
  428.  *
  429.  *    Returns:
  430.  *
  431.  *        true if a cookie signifying that the user declined to install
  432.  *        Flash Player is set; false otherwise.
  433.  *
  434.  * Description:
  435.  *
  436.  *    This function is useful in determining whether to set the 'install'
  437.  *    flag when calling MM_FlashDispatch().  If true, it means that the
  438.  *    user's previous decision not to install Flash Player should be
  439.  *    honored, i.e., 'install' should be set to false.
  440.  */
  441.  
  442. function MM_FlashUserDemurred()
  443. {
  444.     return (document.cookie.indexOf("MM_FlashUserDemurred") != -1);
  445. }
  446.  
  447.  
  448. /*********************************************************************
  449.  * THE FOLLOWING FUNCTIONS ARE NOT PUBLIC.  DO NOT CALL THEM DIRECTLY.
  450.  *********************************************************************/
  451.  
  452. /*
  453.  * MM_FlashLatestPluginRevision() -- look up latest Flash Player plug-in
  454.  *                     revision for this platform
  455.  *
  456.  * Synopsis:
  457.  *
  458.  *    MM_FlashLatestPluginRevision(playerVersion)
  459.  *
  460.  *    Arguments:
  461.  *
  462.  *        playerVersion    plug-in version to look up revision of
  463.  *
  464.  *    Returns:
  465.  *
  466.  *        The latest available revision of the specified version of
  467.  *        the Flash Player plug-in on this platform, as an integer;
  468.  *        undefined for versions before 2.0.
  469.  *
  470.  * Description:
  471.  *
  472.  *    This look-up function is only intended to be called internally.
  473.  */
  474.  
  475. function MM_FlashLatestPluginRevision(playerVersion)
  476. {
  477.     var latestRevision;
  478.     var platform;
  479.  
  480.     if (navigator.appVersion.indexOf("Win") != -1)
  481.     platform = "Windows";
  482.     else if (navigator.appVersion.indexOf("Macintosh") != -1)
  483.     platform = "Macintosh";
  484.     else if (navigator.appVersion.indexOf("X11") != -1)
  485.     platform = "Unix";
  486.  
  487.     latestRevision = MM_latestPluginRevision[playerVersion][platform];
  488.  
  489.     return latestRevision;
  490. }
  491.  
  492.  
  493. /*
  494.  * MM_FlashCanPlay() -- check whether installed Flash Player can play content
  495.  *
  496.  * Synopsis:
  497.  *
  498.  *    MM_FlashCanPlay(contentVersion, requireLatestRevision)
  499.  *
  500.  *    Arguments:
  501.  *
  502.  *        contentVersion        version of Flash software used to
  503.  *                    author content
  504.  *
  505.  *        requireLatestRevision    Boolean indicating whether latest
  506.  *                    revision of plug-in should be required
  507.  *
  508.  *    Returns:
  509.  *
  510.  *        true if the installed player can play the indicated content;
  511.  *        false otherwise.
  512.  *
  513.  * Description:
  514.  *
  515.  *    This function is not intended to be called directly, only
  516.  *    as an instance method of MM_FlashInfo.
  517.  */
  518.  
  519. function MM_FlashCanPlay(contentVersion, requireLatestRevision)
  520. {
  521.     var canPlay;
  522.     //alert((this.version) < contentVersion);
  523.     //alert(this.version);
  524.  
  525.     if (this.version)
  526.     {
  527.     canPlay = (parseInt(contentVersion) <= this.version);
  528.     //alert(canPlay);
  529.  
  530.     //if (requireLatestRevision)
  531.     //{
  532.         //if (this.revision &&
  533.         //this.revision < MM_FlashLatestPluginRevision(this.version))
  534.         //{
  535.         //canPlay = false;
  536.         //}
  537.     //}
  538.     if ((this.version) < contentVersion) {
  539.         //alert('setting canPlay to false');
  540.         canPlay = false;
  541.     }
  542.     }
  543.     else
  544.     {
  545.     canPlay = MM_FlashDetectedSelf();
  546.     }
  547.     //alert('canPlay returning as ' + canPlay);
  548.     return canPlay;
  549. }
  550.  
  551.  
  552. /*
  553.  * MM_FlashDetectedSelf() -- recall whether Flash Player has detected itself
  554.  *
  555.  * Synopsis:
  556.  *
  557.  *    MM_FlashDetectedSelf()
  558.  *
  559.  *    Returns:
  560.  *
  561.  *        true if a cookie signifying that Flash Player has detected itself
  562.  *        is set; false otherwise.
  563.  *
  564.  * Description:
  565.  *
  566.  *    This function is only meant to be called internally.
  567.  */
  568.  
  569. function MM_FlashDetectedSelf()
  570. {
  571.     return (document.cookie.indexOf("MM_FlashDetectedSelf") != -1);
  572. }
  573.