Advertisement
Guest User

City Evolution Snapshotter 2.0

a guest
Jun 2nd, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 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.  
  113. //city evolution snapshotter 1: a89e0ee56e4ab0f5c87eeac4ac8f4b98
  114. //city evolution snapshotter 2: e33e408470f7201732d7ffc14339c170
  115. //city evolution snapshotter 4: 00cb3b7a776f55c2c2866b5dd27effa6
  116.  
  117. var requestId = pipesrpc.run('00cb3b7a776f55c2c2866b5dd27effa6',null,
  118. function(data) {
  119. var b = document.getElementById('backgroundDiv');
  120. data.value.items = shuffle(data.value.items);
  121. for(i=0;i<data.count;i++){
  122. var img = img_create(data.value.items[i].content,'','');
  123. b.appendChild(img);
  124. }
  125. },
  126. function(errorMessage,errorCode) {
  127. alert("Problem running pipe: "+errorMessage);
  128. }
  129. );
  130.  
  131.  
  132.  
  133. function img_create(src, alt, title) {
  134. /*modified from: http://stackoverflow.com/questions/226847/what-is-the-best-javascript-code-to-create-an-img-element*/
  135. var img = document.createElement('img');
  136. img.src = src;
  137. img.width = 180;
  138. img.height = 180;
  139. //img.style.opacity = 0.25;
  140. if (alt!=null) img.alt = alt;
  141. if (title!=null) img.title = title;
  142. return img;
  143. }
  144.  
  145.  
  146.  
  147. function shuffle(o){ //v1.0
  148. /*code from: http://snippets.dzone.com/posts/show/849*/
  149. //+ Jonas Raoni Soares Silva
  150. //@ http://jsfromhell.com/array/shuffle [v1.0]
  151. for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  152. return o;
  153. };
  154. </script>
  155.  
  156. </head>
  157. <body onload='requestId'>
  158. <div id='time'>Time will appear here.</div>
  159. <div id='backgroundDiv'/>
  160. </body>
  161. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement