home *** CD-ROM | disk | FTP | other *** search
/ Minami 79 / MINAMI79.iso / Extra / MPSetup.exe / 1033 / RCDATA / CABINET / wmploc.DLL / HTML / DATALOAD.HTC < prev    next >
Text File  |  2002-12-14  |  10KB  |  412 lines

  1. <PUBLIC:COMPONENT lightWeight=true>
  2. <PUBLIC:METHOD NAME="getDataAsync" />
  3. <PUBLIC:METHOD NAME="getDataAsyncAlbum" />
  4. <PUBLIC:METHOD NAME="getDataAsyncAlbumList" />
  5. <PUBLIC:METHOD NAME="getDataAsyncHeadline" />
  6. <PUBLIC:METHOD NAME="getDataAsyncHeadlineList" />
  7. <PUBLIC:METHOD NAME="getNodeText" />
  8. <PUBLIC:METHOD NAME="getSubNode" />
  9. <PUBLIC:METHOD NAME="saveIDs" />
  10. <PUBLIC:METHOD NAME="Stop" />
  11. <PUBLIC:METHOD NAME="setNoData" />
  12. <PUBLIC:METHOD NAME="setNoMedia" />
  13. <PUBLIC:METHOD NAME="buildNoData" />
  14. <PUBLIC:METHOD NAME="getUrl" />
  15.  
  16. <PUBLIC:PROPERTY NAME="AID" />
  17. <PUBLIC:PROPERTY NAME="PID" />
  18. <PUBLIC:PROPERTY NAME="MSIDAlbum" />
  19. <PUBLIC:PROPERTY NAME="MSIDPerson" />
  20.  
  21. <SCRIPT LANGUAGE="JScript">
  22. var sPID, sAID;
  23.  
  24. var aDataCache = new Array();
  25. var aPreCacheList = new Array('info_home', 'info_artistinfo', 'info_albuminfo_bcd', 'info_relatedalbums', 'info_artistbio', 'info_latestreleases', 'info_albumreview', 'info_relatedartists', 'info_relatedradio');
  26. var sPreCacheKey = '', iPreCacheCurrent = 0;
  27.  
  28. function getDataAsync2(sPage, sPageForCache, fnCallback, sParam)
  29.     var sTOC = element.document.all('toc').innerText, sContentID = element.document.all('contentid').innerText, sCollectionID, sGenre;
  30.     sCollectionID = element.document.all('collectionid').innerText;
  31.     sGenre = element.document.all('genretext').innerText;
  32.     
  33.     if (sTOC.length || sContentID.length)
  34.         getDataExAsync(sPage, sPageForCache,
  35.             '&toc=' + sTOC + '&content_id=' + sContentID + '&a_id=' + AID + '&p_id=' + PID + '&msid_person=' + MSIDPerson + '&msid_album=' + MSIDAlbum + '&genre=' + sGenre + sParam, 
  36.             fnCallback,
  37.             sTOC + ':' + sCollectionID + ':' + sParam);
  38.     else
  39.     {
  40.         var p = element.document.all('player')
  41.         if (!p.currentMedia) 
  42.             setNoMedia();
  43.         else
  44.             setToclessMedia();
  45.     }
  46. }
  47.  
  48. function getDataAsyncAlbum(sPage, fnCallback, sParam)
  49.     getDataExAsync(sPage, sPage, '&a_id=' + sParam, fnCallback, '');
  50. }
  51.  
  52. function getDataAsyncAlbumList(sPage, fnCallback, sParam)
  53.     getDataAsync2(sPage, sPage + sParam, fnCallback, '&type=' + sParam);
  54. }
  55.  
  56. function getDataAsyncHeadline(sPage, fnCallback, sParam)
  57.     getDataExAsync(sPage, sPage, '&article_id=' + sParam, fnCallback, sParam);
  58. }
  59.  
  60. function getDataAsyncHeadlineList(sPage, fnCallback)
  61.     getDataAsync2(sPage, sPage, fnCallback, '');
  62. }
  63.  
  64. function getDataAsync(sPage, fnCallback)
  65.     getDataAsync2(sPage, sPage, fnCallback, '');
  66. }
  67.  
  68.  
  69. function saveIDs(oXML)
  70. {
  71.     var sTemp;
  72.     
  73.     sTemp = getNodeText(oXML, 'a_id');
  74.     if (sTemp.length > 0)
  75.         AID = sTemp;
  76.         
  77.     sTemp = getNodeText(oXML, 'p_id');
  78.     if (sTemp.length > 0)
  79.         PID = sTemp;
  80.         
  81.     sTemp = getNodeText(oXML, 'msid_person');
  82.     if (sTemp.length > 0)
  83.         MSIDPerson = sTemp;
  84.  
  85.     sTemp = getNodeText(oXML, 'msid_album');
  86.     if (sTemp.length > 0)
  87.         MSIDAlbum = sTemp;
  88.  
  89. }
  90.  
  91.  
  92. var oXMLCurrent = null, oCurrentData = null, iBadUrl = 0, iNoCallback = 0, fStartPreCache = false;
  93. function Callback()
  94. {
  95.     if (oXMLCurrent)
  96.     {        
  97.         if (oXMLCurrent.readyState == 4)
  98.         {
  99.             if (oCurrentData && oCurrentData.pfn)
  100.             {
  101.                 if (oXMLCurrent.parseError.errorCode != 0)
  102.                     setServerError(oXMLCurrent.parseError);
  103.                 else
  104.                 {
  105.                     oCurrentData.pfn(oXMLCurrent);
  106.                     addAttribution(oXMLCurrent);
  107.                 }
  108. //                if (fStartPreCache)
  109. //                {
  110. //                    fStartPreCache = false;
  111. //                    window.setTimeout(nextPreCache, 2000);
  112. //                }
  113.             }
  114.             else
  115.                 setInternalError();
  116.         }
  117.     }
  118. }
  119.  
  120. function addAttribution(oXML)
  121. {
  122.     var aProviders = oXML.getElementsByTagName('Attribution'), i, oP, oFooter = element.document.all('footer');
  123.     for (i = 0; i < aProviders.length; i++)
  124.         oFooter.addProvider(getNodeText(aProviders[i], 'ProviderName'));
  125. }
  126.  
  127. function Stop()
  128. {
  129.     oCurrentData = null;
  130.     oXMLCurrent = null;
  131. }
  132.  
  133. function getXMLUrl(sPage, sParams, sVersion)
  134. {
  135.     return 'http://windowsmedia.com/redir/servedocument.asp?locale=' + L_CurrentLocale_Text + '&version=' + sVersion + '&doc=' + sPage + sParams;
  136. }
  137.  
  138. var sVersion = '';
  139. function IsDataAccessAllowed()
  140. {
  141.     var fGetData = false;
  142.     p = element.document.all('player')
  143.     if (p && p.isOnline)
  144.     {
  145.         ex = window.external;
  146.         if (ex)
  147.         {
  148.             if (ex.appColorMedium)
  149.             {
  150.                 if (ex.IsAutoMetadataDownloadAllowed())
  151.                     fGetData = true;
  152.                 else
  153.                     setPrivacy()
  154.             }
  155.             else
  156.                 fGetData = true;
  157.         }
  158.         if (!p.currentMedia) setNoMedia();
  159.         if (sVersion == '')    sVersion = p.versionInfo;
  160.     }
  161.     else
  162.         setOffline();
  163.     return fGetData
  164. }
  165.  
  166. var iCacheCount = 0, iNoCache = 0;
  167. function getDataExAsync(sPage, sPageForCache, sParams, fnCallback, sCacheKey)
  168. {
  169.     var oXML, oCache, fDoDownload;
  170.  
  171.     Stop();
  172.     if (IsDataAccessAllowed())
  173.     {
  174.         var sUrl = getXMLUrl(sPage, sParams, sVersion);
  175.  
  176.         oCache = aDataCache[sPageForCache];
  177.         fDoDownload = true;
  178.         if (oCache)
  179.         {
  180.             if (!IsVAGUID(MSIDPerson))
  181.             {
  182.                 if (sCacheKey.length && (oCache.key == sCacheKey))
  183.                 {
  184.                     if (oCache.xml)
  185.                     {
  186.                         oXML = oCache.xml;
  187.                         oCache.url = oXML.url;
  188.                         fDoDownload = false;
  189.                     }
  190.                 }
  191.             }
  192.         }
  193.  
  194.         if (fDoDownload)
  195.         {        
  196.             iNoCache++;
  197.             oXMLCurrent = getXMLData(sUrl, Callback);
  198.  
  199.             oCache = CreateCacheEntry(sCacheKey, oXMLCurrent, sUrl, fnCallback)
  200.             if (sCacheKey.length)
  201.                 aDataCache[sPageForCache] = oCache;
  202.                 
  203.             oCurrentData = oCache;
  204.         }
  205.         else
  206.         {
  207.             oCache.pfn = fnCallback;
  208.             oCurrentData = oCache;
  209.             iCacheCount++;
  210.             oXMLCurrent = oXML;
  211.             if (oXML.readyState == 4)
  212.                 window.setTimeout(Callback, 0);
  213.         }
  214.     }
  215. }
  216.  
  217. var sPreCacheKey = '', iCurrentPreCache = 0, sPreCacheParams;
  218. function startPreCache(sCacheKey, sParams)
  219. {
  220.     if (sCacheKey != sPreCacheKey)
  221.     {
  222.         iCurrentPreCache = 0;
  223.         sPreCacheKey = sCacheKey;
  224.         sPreCacheParams = sParams;
  225.         fStartPreCache = true;
  226.     }
  227. }
  228.  
  229. function nextPreCache()
  230. {
  231.     if (iCurrentPreCache < aPreCacheList.length)
  232.     {
  233.         window.status = 'Pre: ' + aPreCacheList[iCurrentPreCache];
  234.         getDataForCache(aPreCacheList[iCurrentPreCache], sPreCacheParams, sPreCacheKey);
  235.         window.setTimeout(nextPreCache, 2000);
  236.         iCurrentPreCache++;
  237.     }
  238. }
  239.  
  240. var oCurrentPreCache = null, sCurrentPreCachePage;
  241. function PreCacheCallback()
  242. {
  243.     if (oCurrentPreCache)
  244.     {
  245.         var oXML = oCurrentPreCache.xml
  246.         if (oXML && oXML.readyState == 4)
  247.         {
  248.             if (oXML.parseError.errorCode == 0)
  249.             {
  250. //                alert(sCurrentPreCachePage);
  251.                 
  252.                 aDataCache[sCurrentPreCachePage] = oCurrentPreCache;
  253.                 window.setTimeout(nextPreCache, 2000);
  254.             }
  255.         }
  256.     }
  257. }
  258.  
  259. function getDataForCache(sPage, sParams, sCacheKey)
  260. {
  261.     var oXML, oCache, fDoDownload;
  262.  
  263.     Stop();
  264.     if (IsDataAccessAllowed())
  265.     {
  266.         var sUrl = getXMLUrl(sPage, sParams, sVersion);
  267.         oXML = getXMLData(sUrl, PreCacheCallback);
  268.  
  269.         oCurrentPreCache = CreateCacheEntry(sCacheKey, oXML, sUrl, null)
  270.         sCurrentPreCachePage = sPage;
  271.     }
  272. }
  273.  
  274. function getXMLData(sUrl, fnCallback)
  275. {
  276.     var oXML = new ActiveXObject('Microsoft.XMLDOM');
  277.  
  278.     element.innerText = sUrl;
  279.     oXML.async = true;
  280.     oXML.onreadystatechange = fnCallback;
  281.     oXML.load(sUrl);
  282. //    window.open(sUrl, "new");
  283.     return oXML;
  284. }
  285.  
  286. function CreateCacheEntry(sKey, oXML, sUrl, pfnCallback)
  287. {
  288.     var oCache = new Object();
  289.     oCache.key = sKey;
  290.     oCache.xml = oXML;
  291.     oCache.url = sUrl;
  292.     oCache.pfn = pfnCallback;
  293.     return oCache;
  294. }
  295.  
  296. function setOffline()
  297. {
  298.     setNoData(L_Offline_Text, 'images\\album-review.gif', false);
  299. }
  300.  
  301. function setPrivacy()
  302. {
  303.     setNoData(L_NetAccessOff_Text, 'images\\album-review.gif', false);
  304. }
  305.  
  306. function setNoMedia()
  307. {
  308.     setNoData(L_NoMediaSelected_Text, 'images\\album-review.gif', false);
  309. }
  310.  
  311. function setToclessMedia()
  312. {
  313.     if (IsMediaStream())
  314.         setNoMedia();
  315.     else
  316.         setNoData(L_NoDataAvailable_Text, 'images\\album-review.gif', true);
  317. }
  318.  
  319. function setServerError(oError)
  320. {
  321.     setNoData(L_ServerError_Text + '<br><br>' + oError.reason, 'images\\album-review.gif', false);
  322. }
  323.  
  324. function setInternalError()
  325. {
  326.     setNoData(L_ServerError_Text, 'images\\album-review.gif', false);
  327. }
  328.  
  329. function buildNoData(sText, sImage, fDoWizard)
  330. {
  331.     var s = '<table border=0 cellpadding=0 cellspacing=0><tr>';
  332.     s += '<td width=140 valign=top><img border=0 src="' + sImage + '"></td><td width=8></td><td valign=top class=nodata>';
  333.     if (fDoWizard && IsWizardAvailable())
  334.         s += '<A href="X" class=nodata onclick="window.external.EditMetadata(); return false;">' + sText + '</A></td>';
  335.     else
  336.         s += sText + '<td>';
  337.     return s + '</tr></table>';
  338. }
  339.  
  340. var sHTML;
  341. function sendNoData()
  342. {
  343.     var oP = getCurrentPage();
  344.  
  345.     if (oP && (oP.readyState == 'complete'))
  346.         oP.noData(sHTML);
  347. }
  348.  
  349. function setNoData(sText, sImage, fDoWizard)
  350. {
  351.     sHTML = buildNoData(sText, sImage, fDoWizard);
  352.     window.setTimeout(sendNoData, 1);
  353. }
  354.  
  355. function getNodeText(oXML, sNode)
  356. {
  357.     if (oXML)
  358.     {
  359.         var oObj = oXML.getElementsByTagName(sNode);
  360.         if (oObj.length > 0)
  361.             return oObj[0].text
  362.     }
  363.     return '';
  364. }
  365.  
  366. function getSubNode(oXML, sNode)
  367. {
  368.     var oObj = oXML.getElementsByTagName(sNode);
  369.     return oObj;
  370. }
  371.  
  372. var aTokens = new Array();
  373. aTokens[0] = '';
  374. aTokens[1] = 'file://';
  375. aTokens[2] = 'ftp://';
  376. aTokens[3] = 'http://';
  377. aTokens[4] = 'https://';
  378. aTokens[5] = 'http://www.';
  379. aTokens[6] = 'https://www.';
  380. aTokens[7] = 'news://';
  381. aTokens[8] = 'res://';
  382. aTokens[9] = 'mms://';
  383.  
  384. function getUrl(o)
  385. {
  386.     var iToken, sSite, sPath, sPre;
  387.  
  388.     sSite = getNodeText(o, 'Server');
  389.     if (sSite.length)
  390.     {
  391.         iToken = parseInt(getNodeText(o, 'Token'));
  392.         if ((iToken < 0) || (iToken >= aTokens.length))
  393.             iToken = 0;
  394.             
  395.         sPre = getNodeText(o, 'PrePath');
  396.         sSite = getNodeText(o, 'Server');
  397.         sPath = getNodeText(o, 'FilePath');
  398.         
  399.         return aTokens[iToken] + sPre + sSite + sPath;
  400.     }
  401.     else
  402.         return '';
  403. }
  404. </SCRIPT>
  405. </PUBLIC:COMPONENT>
  406.