Spaces:
Running
Running
File size: 4,425 Bytes
a4af94c 60a46cc a4af94c 60a46cc a4af94c 63462ac a4af94c 63462ac a4af94c 60a46cc a4af94c 60a46cc a4af94c 60a46cc a4af94c 60a46cc a4af94c 1094f81 a4af94c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
class CustomVideoCard extends HTMLElement {
connectedCallback() {
const videoId = this.getAttribute('video-id');
const title = this.getAttribute('title');
const thumbnail = this.getAttribute('thumbnail');
const videoUrl = this.getAttribute('video-url');
const likes = this.getAttribute('likes');
const orientation = this.getAttribute('orientation');
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.video-card {
background: white;
border-radius: 0.5rem;
overflow: hidden;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
transition: transform 0.2s ease, box-shadow 0.2s ease;
cursor: pointer;
}
.video-card:hover {
transform: translateY(-4px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
z-index: 10;
}
.video-thumbnail {
position: relative;
padding-bottom: ${orientation === 'portrait' ? '177.78%' : '56.25%'};
height: 0;
overflow: hidden;
border-radius: 0.5rem 0.5rem 0 0;
}
.video-thumbnail img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.play-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(255, 255, 255, 0.8);
border-radius: 50%;
width: 48px;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.video-info {
padding: 1rem;
}
.video-title {
font-weight: 600;
margin-bottom: 0.5rem;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.video-stats {
display: flex;
align-items: center;
color: #6b7280;
font-size: 0.875rem;
cursor: pointer;
transition: color 0.2s;
pointer-events: auto;
}
.video-stats:hover {
color: #ef4444;
}
.video-stats i {
transition: all 0.2s;
}
.video-stats[data-liked] i,
.video-stats.liked i {
color: #ef4444;
fill: #ef4444;
}
</style>
<div class="video-card">
<div class="video-thumbnail">
<img src="${thumbnail}" alt="${title}">
<div class="play-button" id="play-button">
<i data-feather="play" class="text-purple-600"></i>
</div>
</div>
<div class="video-info">
<h3 class="video-title">${title}</h3>
<div class="video-stats">
<i data-feather="heart" class="w-4 h-4 mr-1"></i>
<span>${likes}</span>
</div>
</div>
</div>
<script>
feather.replace();
</script>
`;
const videoCard = this.shadowRoot.querySelector('.video-card');
videoCard.addEventListener('click', (e) => {
// Don't trigger if clicking on like button
if (!e.target.closest('.video-stats')) {
const videoPlayer = document.querySelector('custom-video-player');
if (videoPlayer) {
videoPlayer.playVideo(videoUrl, parseInt(likes));
}
}
});
// Handle like button click
const likeButton = this.shadowRoot.querySelector('.video-stats');
likeButton.addEventListener('click', (e) => {
e.stopPropagation();
let currentLikes = parseInt(likes);
const isLiked = likeButton.hasAttribute('data-liked');
if (isLiked) {
likeButton.removeAttribute('data-liked');
currentLikes--;
likeButton.querySelector('i').classList.remove('liked');
} else {
likeButton.setAttribute('data-liked', '');
currentLikes++;
likeButton.querySelector('i').classList.add('liked');
}
likes = currentLikes.toString();
likeButton.querySelector('span').textContent = currentLikes.toLocaleString();
});
}
}
customElements.define('custom-video-card', CustomVideoCard); |