Advertisement
Guest User

Untitled

a guest
Nov 15th, 2011
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////////////////////////////////////////////
  2. // script by Daniel Lemire with some bits from   //
  3. // all over the web                              //
  4. // http://www.daniel-lemire.com/                 //
  5. ///////////////////////////////////////////////////
  6. function displayRSS(URI,displaytitle) {
  7. var xmlhttp=false;
  8. var mydiv = document.getElementById("rss");
  9. /*@cc_on @*/
  10. /*@if (@_jscript_version >= 5)
  11. // JScript gives us Conditional compilation, we can cope with old IE versions.
  12. // and security blocked creation of the objects.
  13.  try {
  14.   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  15.  } catch (e) {
  16.   try {
  17.    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  18.   } catch (E) {
  19.    xmlhttp = false;
  20.   }
  21.  }
  22. @end @*/
  23. if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  24.   xmlhttp = new XMLHttpRequest();
  25. }
  26. xmlhttp.open("GET", URI,true);
  27. ptag = document.createElement("p");
  28. ptag.appendChild(document.createTextNode("Loading RSS feed..."));
  29. mydiv.appendChild(ptag);
  30. xmlhttp.onreadystatechange=function() {
  31. if (xmlhttp.readyState==2) {
  32.  // mydiv.appendChild(ptag);
  33.   }
  34. if (xmlhttp.readyState==4) {
  35.  
  36.   xmlDoc=xmlhttp.responseXML;
  37.   items=xmlDoc;
  38.   formatRSS();
  39.   mydiv.removeChild(ptag);
  40.   }
  41.  }
  42.  xmlhttp.send(null);
  43.  
  44.     function formatRSS() {
  45.         var items_count=items.getElementsByTagName('item').length;
  46.                 if(items_count == 0) {
  47.                 ptag = document.createElement("p");
  48.                         ptag.appendChild(document.createTextNode("Empty RSS feed or unsupported feed format (Atom is not supported!)"));
  49.             mydiv.appendChild(ptag);
  50.             return;
  51.                 }
  52.         link=new Array(), title=new Array()
  53.         for(var i=0; i<items_count; i++) {
  54.             if(items.getElementsByTagName('item')[i].getElementsByTagName('link').length==1)
  55.                 link[i]=items.getElementsByTagName('item')[i].getElementsByTagName('link')[0];
  56.             if(items.getElementsByTagName('item')[i].getElementsByTagName('title').length==1)
  57.                 title[i]=items.getElementsByTagName('item')[i].getElementsByTagName('title')[0];
  58.         }
  59.         if(title.length==0) return false;
  60.         if(! displaytitle) {
  61.             h2=document.createElement("h2");
  62.             bloga = document.createElement("a");
  63.             bloga.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('title')[0].firstChild.nodeValue));
  64.             bloga.setAttribute("href",xmlDoc.getElementsByTagName("link")[0].firstChild.nodeValue);
  65.             h2.appendChild(bloga);
  66.             h2.appendChild(document.createTextNode(" "));
  67.                     rssa = document.createElement("a");
  68.             h2.appendChild(rssa);
  69.             rssa.setAttribute("href",URI);
  70.             rssa.setAttribute("class","RSS");
  71.             rssa.appendChild(document.createTextNode("RSS"));
  72.             mydiv.appendChild(h2);
  73.         }
  74.         ul = document.createElement("ul");
  75.         mydiv.appendChild(ul);
  76.         for(var i=0; i<items_count; i++) {
  77.             var title_w, link_w;
  78.             title_w=(title.length>0)?title[i].firstChild.nodeValue:"<i>Untitled</i>";
  79.             link_w=(link.length>0)?link[i].firstChild.nodeValue:"";
  80.             litag = document.createElement("li");
  81.                         linktag =document.createElement("a");
  82.             linktag.setAttribute("href",link_w);
  83.             linktag.appendChild(document.createTextNode(title_w));
  84.            
  85.             litag.appendChild(linktag);
  86.             ul.appendChild(litag);
  87.         }
  88.     }
  89. }
  90.  
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement