src/lib/demo.js
function() {
    // Lock managing state to avoid another async call. See {Function} delayedScroll.
    managing = true;

    var cells = cellsContainer.children;
    var viewportTop = (document.body.scrollTop || document.documentElement.scrollTop) - cellsContainer.offsetTop;
    var viewportBottom = (window.innerHeight || document.documentElement.clientHeight) + viewportTop;

    // Remove cells' contents if they are too far away from the viewport. Get them back if they are near.
    // TODO: remove the cells from DOM should be better :<
    for(var i = 0, l = cells.length; i < l; i++) {
      if((cells[i].offsetTop - viewportBottom > THRESHOLD) || (viewportTop - cells[i].offsetTop - cells[i].offsetHeight > THRESHOLD)) {
        if(cells[i].className === 'cell ready') {
          cells[i].fragment = cells[i].innerHTML;
          cells[i].innerHTML = '';
          cells[i].className = 'cell shadow';
        }
      } else {
        if(cells[i].className === 'cell shadow') {
          cells[i].innerHTML = cells[i].fragment;
          cells[i].className = 'cell ready';
        }
      }
    }

    // If there's space in viewport for a cell, request new cells.
    if(viewportBottom > getMinVal(columnHeights)) {
      // Remove the if/else statement in your project, just call the appendCells function.
      if(isGithubDemo) {
        appendCellsDemo(columnCount);
      } else {
        appendCells(columnCount);
      }
    }

    // Unlock managing state.
    managing = false;
  }
function() {
    // Lock managing state to avoid another async call. See {Function} delayedScroll.
    managing = true;

    var cells = cellsContainer.children;
    var viewportTop = (document.body.scrollTop || document.documentElement.scrollTop) - cellsContainer.offsetTop;
    var viewportBottom = (window.innerHeight || document.documentElement.clientHeight) + viewportTop;

    // Remove cells' contents if they are too far away from the viewport. Get them back if they are near.
    // TODO: remove the cells from DOM should be better :<
    for(var i = 0, l = cells.length; i < l; i++) {
      if((cells[i].offsetTop - viewportBottom > THRESHOLD) || (viewportTop - cells[i].offsetTop - cells[i].offsetHeight > THRESHOLD)) {
        if(cells[i].className === 'cell ready') {
          cells[i].fragment = cells[i].innerHTML;
          cells[i].innerHTML = '';
          cells[i].className = 'cell shadow';
        }
      } else {
        if(cells[i].className === 'cell shadow') {
          cells[i].innerHTML = cells[i].fragment;
          cells[i].className = 'cell ready';
        }
      }
    }

    // If there's space in viewport for a cell, request new cells.
    if(viewportBottom > getMinVal(columnHeights)) {
      // Remove the if/else statement in your project, just call the appendCells function.
      if(isGithubDemo) {
        appendCellsDemo(columnCount);
      } else {
        appendCells(columnCount);
      }
    }

    // Unlock managing state.
    managing = false;
  }
function ( ) { // Lock managing state to avoid another async call. See {Function} delayedScroll. managing = true ; var cells = cellsContainer . children ; var viewportTop = ( document . body . scrollTop || document . documentElement . scrollTop ) - cellsContainer . offsetTop ; var viewportBottom = ( window . innerHeight || document . documentElement . clientHeight ) + viewportTop ; // Remove cells' contents if they are too far away from the viewport. Get them back if they are near. // TODO: remove the cells from DOM should be better :< for ( var i = 0 , l = cells . length ; i < l ; i ++ ) { if ( ( cells [ i ] . offsetTop - viewportBottom > THRESHOLD ) || ( viewportTop - cells [ i ] . offsetTop - cells [ i ] . offsetHeight > THRESHOLD ) ) { if ( cells [ i ] . className === 'cell ready' ) { cells [ i ] . fragment = cells [ i ] . innerHTML ; cells [ i ] . innerHTML = '' ; cells [ i ] . className = 'cell shadow' ; } } else { if ( cells [ i ] . className === 'cell shadow' ) { cells [ i ] . innerHTML = cells [ i ] . fragment ; cells [ i ] . className = 'cell ready' ; } } } // If there's space in viewport for a cell, request new cells. if ( viewportBottom > getMinVal ( columnHeights ) ) { // Remove the if/else statement in your project, just call the appendCells function. if ( isGithubDemo ) { appendCellsDemo ( columnCount ) ; } else { appendCells ( columnCount ) ; } } // Unlock managing state. managing = false ; }
Toggle old cells' contents from the DOM depending on their offset from the viewport, save memory. Load and append new cells if there's space in viewport for a cell.
Toggle old cells contents from the DOM depending on their offset from the viewport save memory . Load and append new cells if there s space in viewport for a cell .