src/lib/demo.js
function(num) {
    if(loading) {
      // Avoid sending too many requests to get new cells.
      return;
    }
    var xhrRequest = new XMLHttpRequest();
    var fragment = document.createDocumentFragment();
    var cells = [];
    var images;
    xhrRequest.open('GET', 'json.php?n=' + num, true);
    xhrRequest.onreadystatechange = function() {
      if(xhrRequest.readyState == 4 && xhrRequest.status == 200) {
        images = JSON.parse(xhrRequest.responseText);
        for(var j = 0, k = images.length; j < k; j++) {
          var cell = document.createElement('div');
          cell.className = 'cell pending';
          cell.tagLine = images[j].title;
          cells.push(cell);
          front(cellTemplate, images[j], cell);
          fragment.appendChild(cell);
        }
        cellsContainer.appendChild(fragment);
        loading = false;
        adjustCells(cells);
      }
    };
    loading = true;
    xhrRequest.send(null);
  }
function(num) {
    if(loading) {
      // Avoid sending too many requests to get new cells.
      return;
    }
    var xhrRequest = new XMLHttpRequest();
    var fragment = document.createDocumentFragment();
    var cells = [];
    var images;
    xhrRequest.open('GET', 'json.php?n=' + num, true);
    xhrRequest.onreadystatechange = function() {
      if(xhrRequest.readyState == 4 && xhrRequest.status == 200) {
        images = JSON.parse(xhrRequest.responseText);
        for(var j = 0, k = images.length; j < k; j++) {
          var cell = document.createElement('div');
          cell.className = 'cell pending';
          cell.tagLine = images[j].title;
          cells.push(cell);
          front(cellTemplate, images[j], cell);
          fragment.appendChild(cell);
        }
        cellsContainer.appendChild(fragment);
        loading = false;
        adjustCells(cells);
      }
    };
    loading = true;
    xhrRequest.send(null);
  }
function ( num ) { if ( loading ) { // Avoid sending too many requests to get new cells. return ; } var xhrRequest = new XMLHttpRequest ( ) ; var fragment = document . createDocumentFragment ( ) ; var cells = [ ] ; var images ; xhrRequest . open ( 'GET' , 'json.php?n=' + num , true ) ; xhrRequest . onreadystatechange = function ( ) { if ( xhrRequest . readyState == 4 && xhrRequest . status == 200 ) { images = JSON . parse ( xhrRequest . responseText ) ; for ( var j = 0 , k = images . length ; j < k ; j ++ ) { var cell = document . createElement ( 'div' ) ; cell . className = 'cell pending' ; cell . tagLine = images [ j ] . title ; cells . push ( cell ) ; front ( cellTemplate , images [ j ] , cell ) ; fragment . appendChild ( cell ) ; } cellsContainer . appendChild ( fragment ) ; loading = false ; adjustCells ( cells ) ; } } ; loading = true ; xhrRequest . send ( null ) ; }
Fetch JSON string via Ajax, parse to HTML and append to the container.
Fetch JSON string via Ajax parse to HTML and append to the container .