Advertisement
andrewb

json-xml.html

Feb 6th, 2015
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="ISO-8859-1"/>
  5. <title>JS Experiment</title>
  6. <script src="http://pics.mytrapster.com/yvonne-list.php?type=json" type="text/javascript"></script>
  7. <script type="text/javascript">
  8. // <![CDATA[
  9. var Yvonne = (function () {
  10.  function Yvonne(list, display) {
  11.    this.list = list;
  12.    this.display = display;
  13.  }
  14.  Yvonne.prototype.clearNode = function(node) {
  15.    while(node.hasChildNodes()) {
  16.      node.removeChild(node.firstChild);
  17.    }
  18.  };
  19.  Yvonne.prototype.makeHtml = function(thumb, full) {
  20.    var divA = document.createElement("div");
  21.    var divB = document.createElement("div");
  22.    var link = document.createElement("a");
  23.    var image = document.createElement("img");
  24.    divA.setAttribute("style", "text-align:center;width:100%;");
  25.    divB.setAttribute("style", "margin:auto;");
  26.    link.setAttribute("href", full);
  27.    link.setAttribute("target", "_blank");
  28.    image.setAttribute("src", thumb);
  29.    image.setAttribute("style", "border:none;")
  30.    link.appendChild(image);
  31.    divB.appendChild(link);
  32.    divA.appendChild(divB);
  33.    return divA;
  34.  };
  35.  Yvonne.prototype.randomPic = function() {
  36.    var rnd = Math.floor((Math.random()*this.list.length)+1);
  37.    return this.list[rnd];
  38.  };
  39.  Yvonne.prototype.start = function() {
  40.    url = this.randomPic();
  41.    el = document.getElementById(this.display);
  42.    this.clearNode(el);
  43.    el.appendChild(this.makeHtml(url.thumb, url.full));
  44.  };
  45.  return Yvonne;
  46. })();
  47. // ]]>
  48. </script>
  49. </head>
  50. <body>
  51. <div id="content">One moment.</div>
  52. <script type="text/javascript">
  53. var y = new Yvonne(Trapster.pics, "content");
  54. setInterval(function () { y.start(); }, 15000);
  55. </script>
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement