function addRippleAnimations() {
  let ripple = (event) => {
    let target = event.target;
    const rect = target.getBoundingClientRect();
    const x = Math.round(event.clientX - rect.left);
    const y = Math.round(event.clientY - rect.top);

    // Calculate radius
    const corners = [
      {x: 0, y: 0},
      {x: rect.width, y: 0},
      {x: 0, y: rect.height},
      {x: rect.width, y: rect.height},
    ];
    let distance = (x1, y1, x2, y2) => {
      var xDelta = x1 - x2;
      var yDelta = y1 - y2;
      return Math.sqrt(xDelta * xDelta + yDelta * yDelta);
    };
    let cornerDistances = corners.map(function(corner) {
      return Math.round(distance(x, y, corner.x, corner.y));
    });
    const radius =
        Math.min(RIPPLE_MAX_RADIUS_PX, Math.max.apply(Math, cornerDistances));

    let ripple = document.createElement('div');
    let rippleContainer = document.createElement('div');
    ripple.classList.add(CLASSES.RIPPLE_EFFECT);
    rippleContainer.classList.add(CLASSES.RIPPLE_CONTAINER);
    rippleContainer.appendChild(ripple);
    target.appendChild(rippleContainer);
    // Ripple start location
    ripple.style.marginLeft = x + 'px';
    ripple.style.marginTop = y + 'px';

    rippleContainer.style.left = rect.left + 'px';
    rippleContainer.style.width = target.offsetWidth + 'px';
    rippleContainer.style.height = target.offsetHeight + 'px';
    rippleContainer.style.borderRadius =
        window.getComputedStyle(target).borderRadius;

    // Start transition/ripple
    ripple.style.width = radius * 2 + 'px';
    ripple.style.height = radius * 2 + 'px';
    ripple.style.marginLeft = x - radius + 'px';
    ripple.style.marginTop = y - radius + 'px';
    ripple.style.backgroundColor = 'rgba(0, 0, 0, 0)';

    window.setTimeout(function() {
      ripple.remove();
      rippleContainer.remove();
    }, RIPPLE_DURATION_MS);
  };

  let rippleElements = document.querySelectorAll('.' + CLASSES.RIPPLE);
  for (let i = 0; i < rippleElements.length; i++) {
    rippleElements[i].addEventListener('mousedown', ripple);
  }
}
/**
 * Enables ripple animations for elements with CLASSES.RIPPLE.
 * TODO(kristipark): Remove after migrating to WebUI.
 */
Enables ripple animations for elements with CLASSES.RIPPLE.
TODO(kristipark): Remove after migrating to WebUI.
Enables ripple animations for elements with CLASSES . RIPPLE . TODO ( kristipark ) : Remove after migrating to WebUI .
function addRippleAnimations() {
  let ripple = (event) => {
    let target = event.target;
    const rect = target.getBoundingClientRect();
    const x = Math.round(event.clientX - rect.left);
    const y = Math.round(event.clientY - rect.top);
    const corners = [
      {x: 0, y: 0},
      {x: rect.width, y: 0},
      {x: 0, y: rect.height},
      {x: rect.width, y: rect.height},
    ];
    let distance = (x1, y1, x2, y2) => {
      var xDelta = x1 - x2;
      var yDelta = y1 - y2;
      return Math.sqrt(xDelta * xDelta + yDelta * yDelta);
    };
    let cornerDistances = corners.map(function(corner) {
      return Math.round(distance(x, y, corner.x, corner.y));
    });
    const radius =
        Math.min(RIPPLE_MAX_RADIUS_PX, Math.max.apply(Math, cornerDistances));
    let ripple = document.createElement('div');
    let rippleContainer = document.createElement('div');
    ripple.classList.add(CLASSES.RIPPLE_EFFECT);
    rippleContainer.classList.add(CLASSES.RIPPLE_CONTAINER);
    rippleContainer.appendChild(ripple);
    target.appendChild(rippleContainer);
    ripple.style.marginLeft = x + 'px';
    ripple.style.marginTop = y + 'px';
    rippleContainer.style.left = rect.left + 'px';
    rippleContainer.style.width = target.offsetWidth + 'px';
    rippleContainer.style.height = target.offsetHeight + 'px';
    rippleContainer.style.borderRadius =
        window.getComputedStyle(target).borderRadius;
    ripple.style.width = radius * 2 + 'px';
    ripple.style.height = radius * 2 + 'px';
    ripple.style.marginLeft = x - radius + 'px';
    ripple.style.marginTop = y - radius + 'px';
    ripple.style.backgroundColor = 'rgba(0, 0, 0, 0)';
    window.setTimeout(function() {
      ripple.remove();
      rippleContainer.remove();
    }, RIPPLE_DURATION_MS);
  };
  let rippleElements = document.querySelectorAll('.' + CLASSES.RIPPLE);
  for (let i = 0; i < rippleElements.length; i++) {
    rippleElements[i].addEventListener('mousedown', ripple);
  }
}
function addRippleAnimations ( ) { let ripple = ( event ) => { let target = event . target ; const rect = target . getBoundingClientRect ( ) ; const x = Math . round ( event . clientX - rect . left ) ; const y = Math . round ( event . clientY - rect . top ) ; const corners = [ { x : 0 , y : 0 } , { x : rect . width , y : 0 } , { x : 0 , y : rect . height } , { x : rect . width , y : rect . height } , ] ; let distance = ( x1 , y1 , x2 , y2 ) => { var xDelta = x1 - x2 ; var yDelta = y1 - y2 ; return Math . sqrt ( xDelta * xDelta + yDelta * yDelta ) ; } ; let cornerDistances = corners . map ( function ( corner ) { return Math . round ( distance ( x , y , corner . x , corner . y ) ) ; } ) ; const radius = Math . min ( RIPPLE_MAX_RADIUS_PX , Math . max . apply ( Math , cornerDistances ) ) ; let ripple = document . createElement ( 'div' ) ; let rippleContainer = document . createElement ( 'div' ) ; ripple . classList . add ( CLASSES . RIPPLE_EFFECT ) ; rippleContainer . classList . add ( CLASSES . RIPPLE_CONTAINER ) ; rippleContainer . appendChild ( ripple ) ; target . appendChild ( rippleContainer ) ; ripple . style . marginLeft = x + 'px' ; ripple . style . marginTop = y + 'px' ; rippleContainer . style . left = rect . left + 'px' ; rippleContainer . style . width = target . offsetWidth + 'px' ; rippleContainer . style . height = target . offsetHeight + 'px' ; rippleContainer . style . borderRadius = window . getComputedStyle ( target ) . borderRadius ; ripple . style . width = radius * 2 + 'px' ; ripple . style . height = radius * 2 + 'px' ; ripple . style . marginLeft = x - radius + 'px' ; ripple . style . marginTop = y - radius + 'px' ; ripple . style . backgroundColor = 'rgba(0, 0, 0, 0)' ; window . setTimeout ( function ( ) { ripple . remove ( ) ; rippleContainer . remove ( ) ; } , RIPPLE_DURATION_MS ) ; } ; let rippleElements = document . querySelectorAll ( '.' + CLASSES . RIPPLE ) ; for ( let i = 0 ; i < rippleElements . length ; i ++ ) { rippleElements [ i ] . addEventListener ( 'mousedown' , ripple ) ; } }
Enables ripple animations for elements with CLASSES.RIPPLE.
Enables ripple animations for elements with CLASSES . RIPPLE .
// Calculate radius // Ripple start location // Start transition/ripple