ads/_ping_.js
/**
 * A fake ad network integration that is mainly used for testing
 * and demo purposes. This implementation gets stripped out in compiled
 * production code.
 * @param {!Window} global
 * @param {!Object} data
 */
A fake ad network integration that is mainly used for testing
and demo purposes. This implementation gets stripped out in compiled
production code.
@param {!Window} global
@param {!Object} data
A fake ad network integration that is mainly used for testing and demo purposes . This implementation gets stripped out in compiled production code . @param { !Window } global @param { !Object } data
function _ping_(global, data) {
  global.networkIntegrationDataParamForTesting = data;
  validateData(data, [], ['valid', 'adHeight', 'adWidth', 'enableIo', 'url']);
  global.document.getElementById('c').textContent = data.ping;
  global.ping = Object.create(null);
  global.context.onResizeSuccess(() => {
    global.ping.resizeSuccess = true;
  });
  global.context.onResizeDenied(() => {
    global.ping.resizeSuccess = false;
  });
  if (data.ad_container) {
    dev().assert(
        global.context.container == data.ad_container, 'wrong container');
  }
  if (data.valid && data.valid == 'true') {
    const img = document.createElement('img');
    if (data.url) {
      img.setAttribute('src', data.url);
      img.setAttribute('width', data.width);
      img.setAttribute('height', data.height);
    }
    let width, height;
    if (data.adHeight) {
      img.setAttribute('height', data.adHeight);
      height = Number(data.adHeight);
    }
    if (data.adWidth) {
      img.setAttribute('width', data.adWidth);
      width = Number(data.adWidth);
    }
    document.body.appendChild(img);
    if (width || height) {
      global.context.renderStart({width, height});
    } else {
      global.context.renderStart();
    }
    if (data.enableIo) {
      global.context.observeIntersection(function(changes) {
        changes.forEach(function(c) {
          dev().info('AMP-AD', 'Intersection: (WxH)' +
              `${c.intersectionRect.width}x${c.intersectionRect.height}`);
        });
        global.ping.lastIO = changes[changes.length - 1];
      });
    }
  } else {
    global.setTimeout(() => {
      global.context.noContentAvailable();
    }, 1000);
  }
}
function _ping_ ( global , data ) { global . networkIntegrationDataParamForTesting = data ; validateData ( data , [ ] , [ 'valid' , 'adHeight' , 'adWidth' , 'enableIo' , 'url' ] ) ; global . document . getElementById ( 'c' ) . textContent = data . ping ; global . ping = Object . create ( null ) ; global . context . onResizeSuccess ( ( ) => { global . ping . resizeSuccess = true ; } ) ; global . context . onResizeDenied ( ( ) => { global . ping . resizeSuccess = false ; } ) ; if ( data . ad_container ) { dev ( ) . assert ( global . context . container == data . ad_container , 'wrong container' ) ; } if ( data . valid && data . valid == 'true' ) { const img = document . createElement ( 'img' ) ; if ( data . url ) { img . setAttribute ( 'src' , data . url ) ; img . setAttribute ( 'width' , data . width ) ; img . setAttribute ( 'height' , data . height ) ; } let width , height ; if ( data . adHeight ) { img . setAttribute ( 'height' , data . adHeight ) ; height = Number ( data . adHeight ) ; } if ( data . adWidth ) { img . setAttribute ( 'width' , data . adWidth ) ; width = Number ( data . adWidth ) ; } document . body . appendChild ( img ) ; if ( width || height ) { global . context . renderStart ( { width , height } ) ; } else { global . context . renderStart ( ) ; } if ( data . enableIo ) { global . context . observeIntersection ( function ( changes ) { changes . forEach ( function ( c ) { dev ( ) . info ( 'AMP-AD' , 'Intersection: (WxH)' + ` ${ c . intersectionRect . width } ${ c . intersectionRect . height } ` ) ; } ) ; global . ping . lastIO = changes [ changes . length - 1 ] ; } ) ; } } else { global . setTimeout ( ( ) => { global . context . noContentAvailable ( ) ; } , 1000 ) ; } }
A fake ad network integration that is mainly used for testing
 and demo purposes.
A fake ad network integration that is mainly used for testing and demo purposes .
// for testing only. see #10628 // store changes to global.lastIO for testing purpose