function renderMaterialDesignTile(data) {
  let mdTile = document.createElement('a');

  if (data == null) {
    mdTile.className = CLASSES.MD_EMPTY_TILE;
    return mdTile;
  }

  // The tile will be appended to tiles.
  const position = tiles.children.length;
  // This is set in the load/error event for the favicon image.
  let tileType = TileVisualType.NONE;

  mdTile.className = CLASSES.MD_TILE;
  mdTile.setAttribute('data-tid', data.tid);
  mdTile.setAttribute('data-pos', position);
  if (isSchemeAllowed(data.url)) {
    mdTile.href = data.url;
  }
  mdTile.setAttribute('aria-label', data.title);
  mdTile.title = data.title;

  mdTile.addEventListener('click', function(ev) {
    logMostVisitedNavigation(
        position, data.tileTitleSource, data.tileSource, tileType,
        data.dataGenerationTime);
  });
  mdTile.addEventListener('keydown', function(event) {
    if (event.keyCode == 46 /* DELETE */ ||
        event.keyCode == 8 /* BACKSPACE */) {
      event.preventDefault();
      event.stopPropagation();
      blacklistTile(this);
    } else if (
        event.keyCode == 13 /* ENTER */ || event.keyCode == 32 /* SPACE */) {
      event.preventDefault();
      this.click();
    } else if (event.keyCode == 37 /* LEFT */) {
      const tiles = document.querySelectorAll('#mv-tiles .' + CLASSES.MD_TILE);
      tiles[Math.max(this.getAttribute('data-pos') - 1, 0)].focus();
    } else if (event.keyCode == 39 /* RIGHT */) {
      const tiles = document.querySelectorAll('#mv-tiles .' + CLASSES.MD_TILE);
      tiles[Math.min(this.getAttribute('data-pos') + 1, tiles.length - 1)]
          .focus();
    }
  });

  let mdTileInner = document.createElement('div');
  mdTileInner.className = CLASSES.MD_TILE_INNER;

  let mdIcon = document.createElement('div');
  mdIcon.className = CLASSES.MD_ICON;
  let mdIconBackground = document.createElement('div');
  mdIconBackground.className = CLASSES.MD_ICON_BACKGROUND;

  let mdFavicon = document.createElement('div');
  mdFavicon.className = CLASSES.MD_FAVICON;
  let fi = document.createElement('img');
  fi.src = data.faviconUrl;
  // Set title and alt to empty so screen readers won't say the image name.
  fi.title = '';
  fi.alt = '';
  loadedCounter += 1;
  fi.addEventListener('load', function(ev) {
    // Store the type for a potential later navigation.
    tileType = TileVisualType.ICON_REAL;
    logMostVisitedImpression(
        position, data.tileTitleSource, data.tileSource, tileType,
        data.dataGenerationTime);
    // Note: It's important to call countLoad last, because that might emit the
    // NTP_ALL_TILES_LOADED event, which must happen after the impression log.
    countLoad();
  });
  fi.addEventListener('error', function(ev) {
    mdFavicon.classList.add(CLASSES.FAILED_FAVICON);
    thumb.removeChild(img);
    // Store the type for a potential later navigation.
    tileType = TileVisualType.ICON_DEFAULT;
    logMostVisitedImpression(
        position, data.tileTitleSource, data.tileSource, tileType,
        data.dataGenerationTime);
    // Note: It's important to call countLoad last, because that might emit the
    // NTP_ALL_TILES_LOADED event, which must happen after the impression log.
    countLoad();
  });
  mdFavicon.appendChild(fi);
  mdIconBackground.appendChild(mdFavicon);
  mdIcon.appendChild(mdIconBackground);
  mdTileInner.appendChild(mdIcon);

  let mdTitleContainer = document.createElement('div');
  mdTitleContainer.className = CLASSES.MD_TITLE_CONTAINER;
  let mdTitle = document.createElement('div');
  mdTitle.className = CLASSES.MD_TITLE;
  mdTitle.innerText = data.title;
  mdTitle.style.direction = data.direction || 'ltr';
  mdTitleContainer.appendChild(mdTitle);
  mdTileInner.appendChild(mdTitleContainer);

  let mdMenu = document.createElement('button');
  mdMenu.className = CLASSES.MD_MENU;
  mdMenu.title = queryArgs['removeTooltip'] || '';
  mdMenu.addEventListener('click', function(ev) {
    removeAllOldTiles();
    blacklistTile(mdTile);
    ev.preventDefault();
    ev.stopPropagation();
  });
  // Don't allow the event to bubble out to the containing tile, as that would
  // trigger navigation to the tile URL.
  mdMenu.addEventListener('keydown', function(event) {
    event.stopPropagation();
  });

  mdTile.appendChild(mdTileInner);
  mdTile.appendChild(mdMenu);
  return mdTile;
}
/**
 * Renders a MostVisited tile with Material Design styles.
 * @param {object} data Object containing rid, url, title, favicon. data is null
 *     if you want to construct an empty tile.
 * @return {Element}
 */
Renders a MostVisited tile with Material Design styles.
@param {object} data Object containing rid, url, title, favicon. data is null
if you want to construct an empty tile.
@return {Element}
Renders a MostVisited tile with Material Design styles . @param { object } data Object containing rid url title favicon . data is null if you want to construct an empty tile . @return { Element }
function renderMaterialDesignTile(data) {
  let mdTile = document.createElement('a');
  if (data == null) {
    mdTile.className = CLASSES.MD_EMPTY_TILE;
    return mdTile;
  }
  const position = tiles.children.length;
  let tileType = TileVisualType.NONE;
  mdTile.className = CLASSES.MD_TILE;
  mdTile.setAttribute('data-tid', data.tid);
  mdTile.setAttribute('data-pos', position);
  if (isSchemeAllowed(data.url)) {
    mdTile.href = data.url;
  }
  mdTile.setAttribute('aria-label', data.title);
  mdTile.title = data.title;
  mdTile.addEventListener('click', function(ev) {
    logMostVisitedNavigation(
        position, data.tileTitleSource, data.tileSource, tileType,
        data.dataGenerationTime);
  });
  mdTile.addEventListener('keydown', function(event) {
    if (event.keyCode == 46  ||
        event.keyCode == 8 ) {
      event.preventDefault();
      event.stopPropagation();
      blacklistTile(this);
    } else if (
        event.keyCode == 13  || event.keyCode == 32 ) {
      event.preventDefault();
      this.click();
    } else if (event.keyCode == 37 ) {
      const tiles = document.querySelectorAll('#mv-tiles .' + CLASSES.MD_TILE);
      tiles[Math.max(this.getAttribute('data-pos') - 1, 0)].focus();
    } else if (event.keyCode == 39 ) {
      const tiles = document.querySelectorAll('#mv-tiles .' + CLASSES.MD_TILE);
      tiles[Math.min(this.getAttribute('data-pos') + 1, tiles.length - 1)]
          .focus();
    }
  });
  let mdTileInner = document.createElement('div');
  mdTileInner.className = CLASSES.MD_TILE_INNER;
  let mdIcon = document.createElement('div');
  mdIcon.className = CLASSES.MD_ICON;
  let mdIconBackground = document.createElement('div');
  mdIconBackground.className = CLASSES.MD_ICON_BACKGROUND;
  let mdFavicon = document.createElement('div');
  mdFavicon.className = CLASSES.MD_FAVICON;
  let fi = document.createElement('img');
  fi.src = data.faviconUrl;
  fi.title = '';
  fi.alt = '';
  loadedCounter += 1;
  fi.addEventListener('load', function(ev) {
    tileType = TileVisualType.ICON_REAL;
    logMostVisitedImpression(
        position, data.tileTitleSource, data.tileSource, tileType,
        data.dataGenerationTime);
    countLoad();
  });
  fi.addEventListener('error', function(ev) {
    mdFavicon.classList.add(CLASSES.FAILED_FAVICON);
    thumb.removeChild(img);
    tileType = TileVisualType.ICON_DEFAULT;
    logMostVisitedImpression(
        position, data.tileTitleSource, data.tileSource, tileType,
        data.dataGenerationTime);
    countLoad();
  });
  mdFavicon.appendChild(fi);
  mdIconBackground.appendChild(mdFavicon);
  mdIcon.appendChild(mdIconBackground);
  mdTileInner.appendChild(mdIcon);
  let mdTitleContainer = document.createElement('div');
  mdTitleContainer.className = CLASSES.MD_TITLE_CONTAINER;
  let mdTitle = document.createElement('div');
  mdTitle.className = CLASSES.MD_TITLE;
  mdTitle.innerText = data.title;
  mdTitle.style.direction = data.direction || 'ltr';
  mdTitleContainer.appendChild(mdTitle);
  mdTileInner.appendChild(mdTitleContainer);
  let mdMenu = document.createElement('button');
  mdMenu.className = CLASSES.MD_MENU;
  mdMenu.title = queryArgs['removeTooltip'] || '';
  mdMenu.addEventListener('click', function(ev) {
    removeAllOldTiles();
    blacklistTile(mdTile);
    ev.preventDefault();
    ev.stopPropagation();
  });
  mdMenu.addEventListener('keydown', function(event) {
    event.stopPropagation();
  });
  mdTile.appendChild(mdTileInner);
  mdTile.appendChild(mdMenu);
  return mdTile;
}
function renderMaterialDesignTile ( data ) { let mdTile = document . createElement ( 'a' ) ; if ( data == null ) { mdTile . className = CLASSES . MD_EMPTY_TILE ; return mdTile ; } const position = tiles . children . length ; let tileType = TileVisualType . NONE ; mdTile . className = CLASSES . MD_TILE ; mdTile . setAttribute ( 'data-tid' , data . tid ) ; mdTile . setAttribute ( 'data-pos' , position ) ; if ( isSchemeAllowed ( data . url ) ) { mdTile . href = data . url ; } mdTile . setAttribute ( 'aria-label' , data . title ) ; mdTile . title = data . title ; mdTile . addEventListener ( 'click' , function ( ev ) { logMostVisitedNavigation ( position , data . tileTitleSource , data . tileSource , tileType , data . dataGenerationTime ) ; } ) ; mdTile . addEventListener ( 'keydown' , function ( event ) { if ( event . keyCode == 46 || event . keyCode == 8 ) { event . preventDefault ( ) ; event . stopPropagation ( ) ; blacklistTile ( this ) ; } else if ( event . keyCode == 13 || event . keyCode == 32 ) { event . preventDefault ( ) ; this . click ( ) ; } else if ( event . keyCode == 37 ) { const tiles = document . querySelectorAll ( '#mv-tiles .' + CLASSES . MD_TILE ) ; tiles [ Math . max ( this . getAttribute ( 'data-pos' ) - 1 , 0 ) ] . focus ( ) ; } else if ( event . keyCode == 39 ) { const tiles = document . querySelectorAll ( '#mv-tiles .' + CLASSES . MD_TILE ) ; tiles [ Math . min ( this . getAttribute ( 'data-pos' ) + 1 , tiles . length - 1 ) ] . focus ( ) ; } } ) ; let mdTileInner = document . createElement ( 'div' ) ; mdTileInner . className = CLASSES . MD_TILE_INNER ; let mdIcon = document . createElement ( 'div' ) ; mdIcon . className = CLASSES . MD_ICON ; let mdIconBackground = document . createElement ( 'div' ) ; mdIconBackground . className = CLASSES . MD_ICON_BACKGROUND ; let mdFavicon = document . createElement ( 'div' ) ; mdFavicon . className = CLASSES . MD_FAVICON ; let fi = document . createElement ( 'img' ) ; fi . src = data . faviconUrl ; fi . title = '' ; fi . alt = '' ; loadedCounter += 1 ; fi . addEventListener ( 'load' , function ( ev ) { tileType = TileVisualType . ICON_REAL ; logMostVisitedImpression ( position , data . tileTitleSource , data . tileSource , tileType , data . dataGenerationTime ) ; countLoad ( ) ; } ) ; fi . addEventListener ( 'error' , function ( ev ) { mdFavicon . classList . add ( CLASSES . FAILED_FAVICON ) ; thumb . removeChild ( img ) ; tileType = TileVisualType . ICON_DEFAULT ; logMostVisitedImpression ( position , data . tileTitleSource , data . tileSource , tileType , data . dataGenerationTime ) ; countLoad ( ) ; } ) ; mdFavicon . appendChild ( fi ) ; mdIconBackground . appendChild ( mdFavicon ) ; mdIcon . appendChild ( mdIconBackground ) ; mdTileInner . appendChild ( mdIcon ) ; let mdTitleContainer = document . createElement ( 'div' ) ; mdTitleContainer . className = CLASSES . MD_TITLE_CONTAINER ; let mdTitle = document . createElement ( 'div' ) ; mdTitle . className = CLASSES . MD_TITLE ; mdTitle . innerText = data . title ; mdTitle . style . direction = data . direction || 'ltr' ; mdTitleContainer . appendChild ( mdTitle ) ; mdTileInner . appendChild ( mdTitleContainer ) ; let mdMenu = document . createElement ( 'button' ) ; mdMenu . className = CLASSES . MD_MENU ; mdMenu . title = queryArgs [ 'removeTooltip' ] || '' ; mdMenu . addEventListener ( 'click' , function ( ev ) { removeAllOldTiles ( ) ; blacklistTile ( mdTile ) ; ev . preventDefault ( ) ; ev . stopPropagation ( ) ; } ) ; mdMenu . addEventListener ( 'keydown' , function ( event ) { event . stopPropagation ( ) ; } ) ; mdTile . appendChild ( mdTileInner ) ; mdTile . appendChild ( mdMenu ) ; return mdTile ; }
Renders a MostVisited tile with Material Design styles.
Renders a MostVisited tile with Material Design styles .
// The tile will be appended to tiles. // This is set in the load/error event for the favicon image. /* DELETE */ /* BACKSPACE */ /* ENTER */ /* SPACE */ /* LEFT */ /* RIGHT */ // Set title and alt to empty so screen readers won't say the image name. // Store the type for a potential later navigation. // Note: It's important to call countLoad last, because that might emit the // NTP_ALL_TILES_LOADED event, which must happen after the impression log. // Store the type for a potential later navigation. // Note: It's important to call countLoad last, because that might emit the // NTP_ALL_TILES_LOADED event, which must happen after the impression log. // Don't allow the event to bubble out to the containing tile, as that would // trigger navigation to the tile URL.