Advertisement
Guest User

City Evolution Snapshotter

a guest
Jun 1st, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.85 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style type='text/css'>
  4. *{
  5.     font-family:Verdana;
  6.     font-size:14px;
  7.     text-shadow:#000;
  8.     color:#777;
  9.     padding:0;
  10.     margin:0;
  11.     border:0;
  12. }
  13. #backgroundDiv{
  14.     position:absolute;
  15.     background-color:#000;
  16. }
  17. img{
  18.     opacity:0.5;
  19. }
  20. img:hover{
  21.     opacity:1;
  22. }
  23. </style>
  24.  
  25. <script type='text/javascript'>
  26. if(window.addEventListener) {
  27. window.addEventListener('load', function () {
  28.     var timeDiv = document.getElementById('time');
  29.    
  30.     function init(){
  31.         window.setInterval(updateTime,100);
  32.     }
  33.    
  34.     function updateTime() {
  35.         timeDiv.textContent = new Date();
  36.     }
  37.    
  38.     init();
  39. }, false); }
  40. </script>
  41.  
  42. <script>
  43. /* these calls are just the plumbing */
  44.  
  45. pipesrpc = {};
  46. pipesrpc._timeoutlength = 30000;  /* 30 seconds by default */
  47. pipesrpc._running = [];
  48.  
  49. pipesrpc._timeout = function(id,url) {
  50.     var cbo = pipesrpc._running[id];
  51.     pipesrpc._running[id]=null;
  52.     if (!cbo.callbackErr) return;
  53.     cbo.callbackErr("Timeout",-1,cbo.self);
  54. }
  55.  
  56. pipesrpc._buildurl = function(pipeid,params) {
  57.     var url = "http://pipes.yahoo.com/pipes/pipe.run?_id="+pipeid+"&_render=json";
  58.     if (params) {
  59.         for (var key in params) {
  60.             if (params[key]===null) continue;
  61.             url+="&"+encodeURIComponent(key)+"="+encodeURIComponent(params[key])
  62.         }
  63.     }
  64.    return url;
  65. }
  66.  
  67. pipesrpc._callbackhandler = function(o) {
  68.     var cbo = pipesrpc._running[callbackIndex];
  69.     if (!cbo) return;
  70.     pipesrpc._running[callbackIndex]=null;
  71.     window.clearTimeout(cbo.timeout);
  72.     if (!o || !o.count) {
  73.         if (!cbo.callbackErr) return;
  74.         cbo.callbackErr("Bad response",-2,cbo.self);
  75.         return;
  76.     }
  77.     if (!cbo.callbackOk) return;
  78.     cbo.callbackOk(o,cbo.self);
  79. }
  80.  
  81. pipesrpc._execute = function(url,callbackOk,callbackErr,timeoutlength) {
  82.     if (!timeoutlength) timeoutlength = pipesrpc._timeoutlength;
  83.     var id = pipesrpc._running.length;
  84.     url+="&_callback=pipesrpc._callbackhandler_"+id;
  85.     var s=document.createElement("script");
  86.     s.setAttribute("src",url);
  87.     var fn = ""+pipesrpc._callbackhandler;
  88.     fn = fn.replace(/callbackIndex/g,id);
  89.     eval("pipesrpc._callbackhandler_"+id+"="+fn);
  90.     pipesrpc._running.push({self:this,callbackOk:callbackOk,callbackErr:callbackErr,timeout:window.setTimeout(function() { pipesrpc._timeout(id,url); },timeoutlength)});    
  91.     document.getElementsByTagName("head")[0].appendChild(s);
  92.     return id;
  93. }
  94.  
  95. /* use these three calls to run and cancel Pipes calls */
  96. pipesrpc.cancelrequest = function(id) {
  97.     var cbo = pipesrpc._running[id];
  98.     window.clearTimeout(cbo.timeout);
  99.     pipesrpc._running[id]=null;
  100. }
  101.  
  102. pipesrpc.cancelallrequests = function() {
  103.     for (var i=0; i<pipesrpc._running.length; i++) {
  104.        pipesrpc._cancelrequest(i);
  105.     }  
  106. }
  107.  
  108. pipesrpc.run = function(pipeid,params,callbackOk,callbackErr,timeoutLength) {
  109.    return pipesrpc._execute(pipesrpc._buildurl(pipeid,params),callbackOk,callbackErr,timeoutLength);
  110. }
  111.  
  112. var requestId = pipesrpc.run('a89e0ee56e4ab0f5c87eeac4ac8f4b98',null,
  113.    function(data) {
  114.         var b = document.getElementById('backgroundDiv');
  115.         for(i=0;i<data.count;i++){
  116.             var img = img_create(data.value.items[i].content,'','Yahoo Pipes: '+data.value.title+' Image '+i);
  117.             b.appendChild(img);
  118.         }
  119.     },
  120.    function(errorMessage,errorCode) {
  121.        alert("Problem running pipe: "+errorMessage);
  122.    }
  123. );
  124.  
  125. function img_create(src, alt, title) {
  126.    /*modified from: http://stackoverflow.com/questions/226847/what-is-the-best-javascript-code-to-create-an-img-element*/
  127.    var img = document.createElement('img');
  128.    img.src = src;
  129.    img.width = 180;
  130.    img.height = 180;
  131.    //img.style.opacity = 0.25;
  132.    if (alt!=null) img.alt = alt;
  133.    if (title!=null) img.title = title;
  134.    return img;
  135. }
  136.  
  137. </script>
  138.  
  139. </head>
  140. <body onload='requestId'>
  141. <div id='time'>Time will appear here.</div>
  142. <div id='backgroundDiv'/>
  143. </body>
  144. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement