home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 192 / dpcs0204.iso / Internet / AOL / comp01.000 / %MAINDIR% / ShopAssist / Apps / toolbar / js / toolbarscpt.js < prev   
Encoding:
JavaScript  |  2003-10-24  |  3.4 KB  |  151 lines

  1. // core callback for mlist
  2. function cbGetShopMList(status, mlist)
  3. {
  4.     if (status==objCoreGlobal.GET_APPDATA_SUCCEED)
  5.     {
  6.         mlist = mlist.substr(mlist.indexOf("var ")+4);
  7.         eval(mlist);
  8.         return true;
  9.     }
  10.     if (status==objCoreGlobal.GET_APPDATA_TIMEOUT)
  11.     {}
  12.     return false;
  13. }
  14.  
  15. function shouldDisplayToolbar( url ) 
  16. {
  17.   if ( gState == false)
  18.         return false;
  19.  
  20.   var newSite = getHostName( url );
  21.   if ( isShoppingSite( newSite ) ) 
  22.   {
  23.         if(newSite.indexOf("kavamedia.com")>0)
  24.             if(!(url.indexOf("kavamedia.com/philips")>0))
  25.                 return false;
  26.         return true;
  27.   }
  28.   else
  29.         return false;
  30. }
  31.  
  32. function isShoppingSite( site  ) 
  33. {
  34.   if ( shoppingSites.indexOf(" " + site + " " ) >= 0  )
  35.     return true;
  36.  
  37.   var ind = site.indexOf(".");
  38.   var truncatedSite = site.substr( ind+1, site.length );
  39.  
  40.   if ( shoppingSites.indexOf(" " + truncatedSite + " " ) >= 0  )
  41.     return true;
  42.   return false;
  43. }
  44.  
  45. function onAolBeforeNavigate(newURL) 
  46. {
  47.   nonQCPPURL = stripQCPP( newURL );
  48.     var newDomain = getURLDomain(nonQCPPURL);
  49.     // ignore javascript: urls
  50.     if ( newURL.indexOf("javascript:") == 0 )
  51.         return true;
  52.     
  53.     if ( newDomain != gActiveDomain ) 
  54.     {
  55.         if ( shouldDisplayToolbar( newURL ) ) 
  56.             return true; // don't change the state of the bar. If it's still showing, keep showing it
  57.         showBar( false); // hide it
  58.   }
  59.     return true; // keep showing it
  60. }
  61. function onAolNavigateComplete(newURL){}
  62. function onAolFrameNavigateComplete(newURL){}
  63. function onAolFrameDocumentComplete(newURL) {}
  64. function onAolDocumentComplete(newURL) 
  65. {
  66.   if ( objCoreGlobal.WinX < SA_MIN_WIN_WIDTH || objCoreGlobal.WinY < SA_MIN_WIN_HEIGHT ) 
  67.     {
  68.         gState = false;
  69.         showBar( false);
  70.         return false;
  71.     }
  72.   else 
  73.         gState = true;    
  74.         
  75.     nonQCPPURL = stripQCPP( newURL );
  76.     gActiveURL = nonQCPPURL;
  77.     gActiveDomain = getURLDomain( nonQCPPURL );
  78.     
  79.     if ( shouldDisplayToolbar( nonQCPPURL ) ) 
  80.         showBar( true);
  81.     else 
  82.         showBar( false);
  83. }
  84.  
  85. function stripQCPP( url ) 
  86. {
  87.     if ( url == null || url == "" )
  88.         return "";
  89.   var  re = new RegExp("http://qcpp.aol.com/[^/]+/", "gi" );
  90.   var newURL = url.replace(re, "http://" );
  91.   return newURL;
  92. }
  93.  
  94. function getURLDomain(url)
  95. {
  96.   url = stripQCPP(url);
  97.   var ind = url.indexOf("://");
  98.   if (ind == -1)
  99.     ind = 0;
  100.     else
  101.     ind += 3;
  102.  
  103.   var suburl = url.substr(ind);
  104.   // get host from suburl
  105.   var hostInd = suburl.indexOf(":");
  106.   var hostIndSlash = suburl.indexOf("/");
  107.  
  108.   if ( (hostInd > 0)  && (hostInd < hostIndSlash) ) 
  109.   {}
  110.   else
  111.         hostInd = hostIndSlash;
  112.   
  113.   var host = (hostInd == -1) ? suburl : suburl.substring(0, hostInd);
  114.   var firstDot = host.lastIndexOf(".");
  115.   if ((firstDot != -1) && (firstDot != 0)) 
  116.   {
  117.     var secondDot = host.lastIndexOf(".", firstDot - 1);
  118.     if (secondDot != -1) 
  119.       return host.substr(secondDot + 1, host.length);
  120.   }
  121.   return host;
  122. }
  123.  
  124. function getHostName(url)
  125. {  
  126.   url = stripQCPP(url);
  127.   var ind = url.indexOf("://");
  128.   if (ind == -1)
  129.     ind = 0;
  130.   else
  131.     ind += 3;
  132.  
  133.   var suburl = url.substr(ind);
  134.   var hostInd = suburl.indexOf(":");
  135.   var hostIndSlash = suburl.indexOf("/");
  136.   if ( (hostInd > 0)  && (hostInd < hostIndSlash) ) 
  137.   {
  138.   }
  139.   else
  140.         hostInd = hostIndSlash;
  141.   var host = (hostInd == -1) ? suburl : suburl.substring(0, hostInd);
  142.   return host;
  143. }
  144.  
  145. function showBar(show) 
  146. {
  147.     if ( ! show )
  148.         objCoreGlobal.ShowBar(false, 0, "");
  149.     else
  150.         objCoreGlobal.ShowBar(true, HEIGHT_WINDOW, "../toolbar/channels/shop/shop.html");
  151. }