Skip to content

Commit

Permalink
Merge branch 'develop' into feat/tabs-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mayan-000 committed Nov 25, 2024
2 parents 9317e4b + 28c29ae commit 447ef49
Show file tree
Hide file tree
Showing 35 changed files with 15,843 additions and 132 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"**/dist-types/**",
"out/**",
"data/**",
"assets/**/*.js",
"coverage/**"
],
"rules": {
Expand Down
4 changes: 4 additions & 0 deletions assets/amp/amp-animation-0.1.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/amp/amp-loader-0.1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

174 changes: 174 additions & 0 deletions assets/amp/amp-player-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let cards;
let cardMargin;
let cardWidth;
let player;
let lightboxEl;
let maxScroll;
let scaleVal = 1;
let scalingDown = false;
let deltaY = 0;

function setPlayer(playerEl) {
player = playerEl;
}

function setLightbox(lightbox) {
lightboxEl = lightbox;
}

function setCards(cardEls) {
cards = cardEls;
}

function setCardWidth(width) {
cardWidth = width;
}

function setCardMargin(margin) {
cardMargin = margin;
}

/**
* Initializes arrows for horizontal scrolling on desktop.
*/
function initializeArrows() {
const scrollContainer = document.querySelector('.carousel-cards-container');
const containerPadding =
parseFloat(
getComputedStyle(scrollContainer.firstElementChild).paddingLeft
) +
parseFloat(
getComputedStyle(scrollContainer.firstElementChild).paddingRight
);

maxScroll =
scrollContainer.offsetWidth -
containerPadding +
cardMargin -
cards.length * cardWidth;

if (maxScroll < 0) {
document.querySelector('.carousel-container').classList.add('overflow-right');
}
}

/**
* Closes the lightbox and resets the player and UI.
*/
function closePlayer() {
const data = { storyOpened: false }
const event = new CustomEvent('webStoriesLightBoxEvent', { detail: data })
window.parent.document.dispatchEvent(event)
player.pause();
document.body.classList.remove('lightbox-open');
lightboxEl.classList.add('closed');
cards.forEach((card) => card.classList.remove('hidden'));
}

/**
* Handles scaling animation during interactions.
*/
function animateScale(val) {
if (val < 1 && scalingDown) {
scaleVal = lerp(easeOutQuad(val), 1, 0.95);
lightboxEl.style.transform = `translate3d(0px, ${Math.pow(
-deltaY,
0.6
)}px, 0) scale3d(${scaleVal}, ${scaleVal}, 1)`;
requestAnimationFrame(() => animateScale(val + 0.05));
}
}

/**
* Resets scaling animation styles.
*/
function resetStyles() {
scalingDown = false;
scaleVal = 1;
lightboxEl.style.transform = `translate3d(0, 0, 0) scale3d(1, 1, 1)`;
}

/**
* Initializes card click events and sets up their dimensions.
*/
function initializeCards() {
setCards(document.querySelectorAll('.entry-point-card-container'));
setCardMargin(parseFloat(getComputedStyle(cards[0]).marginRight));
setCardWidth(cardMargin + cards[0].offsetWidth);

const stories = player.getStories();

cards.forEach((card, idx) => {
card.addEventListener('click', () => {
player.show(stories[idx].href, null, { animate: false });
const data = { storyOpened: true }
const event = new CustomEvent('webStoriesLightBoxEvent', { detail: data })
window.parent.document.dispatchEvent(event)

document.body.classList.add('lightbox-open');
lightboxEl.classList.remove('closed');
card.classList.add('hidden');
resetStyles();
player.play();
});
});
}

/**
* Initializes the carousel with the player and cards.
*/
function initializeCarousel() {
const lightbox = document.body.querySelector('.lightbox');
setLightbox(lightbox);

initializeCards();
initializeArrows();

player.addEventListener('amp-story-player-close', closePlayer);
}

/**
* Initializes the player and sets up the carousel.
*/
function init() {
const playerEl = document.body.querySelector('amp-story-player');
setPlayer(playerEl);

if (player.isReady) {
initializeCarousel();
} else {
player.addEventListener('ready', initializeCarousel);
}
}

/**
* Linear interpolation helper.
*/
function lerp(pct, v0, v1) {
return v0 * (1 - pct) + v1 * pct;
}

/**
* Ease-out quadratic easing function.
*/
function easeOutQuad(t) {
return --t * t * t + 1;
}

// Initialize on window load.
window.addEventListener('load', init);
11 changes: 11 additions & 0 deletions assets/amp/amp-story-1.0.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/amp/amp-story-player-v0.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/amp/amp-video-0.1.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/amp/amp-viewer-integration-0.1.js

Large diffs are not rendered by default.

Loading

0 comments on commit 447ef49

Please sign in to comment.