Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

see more <-> see less on wins page mobile view #1924

Merged
merged 12 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions _sass/components/_wins-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
height: 88px;
overflow: hidden;
position: relative;
&.relative {
position: relative;
.wins-see-more-div {
bottom: 0;
right: 0;
}
}
p {
margin: 0;
}
Expand Down Expand Up @@ -249,11 +256,8 @@
}

.wins-see-more-div {
height: 0;
margin-top: 4px;
padding: 0;
right: 7%;
top: 88.5%;
right: 24px;
bottom: 10px;
}

.home-getting-started-container {
Expand All @@ -277,6 +281,7 @@
@media #{$bp-below-mobile} {
.wins-card-text{
height: 80px;
margin-top: 16px;
}
.wins-card{
padding: 24px;
Expand Down Expand Up @@ -313,9 +318,6 @@
height: 20px;
width: 20px;
}
.wins-card-text{
margin-top: 16px;
}

.wins-card-overview{
margin-top: 0;
Expand All @@ -329,7 +331,6 @@
@media #{$bp-desktop-up} {
.wins-card-overview{
overflow: hidden;
text-overflow: ellipsis;
}

.overlay {
Expand Down Expand Up @@ -405,10 +406,10 @@
.expanded{
height: auto;
.wins-see-more-div {
position: relative;
text-align: right;
z-index: 10;
}
}

}

.wins-card-content > * {
Expand Down
3 changes: 3 additions & 0 deletions assets/images/wins-page/caret.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pages/wins/wins-card-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="project-inner wins-card-text">
<p class="wins-card-overview"></p>
<p class="wins-card-info"></p>
<div class="project-inner wins-see-more-div">
<div class="wins-see-more-div">
<span id="0" onclick="seeMore(id)" expandable class="see-more-div">...see more</span>
</div>
</div>
Expand Down
65 changes: 28 additions & 37 deletions pages/wins/wins.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@
cardObj[keys[i]] = data[i];
}
cardData.push(cardObj)



})

//createFilter();
Expand Down Expand Up @@ -268,17 +265,6 @@

}

function formatMessage(win) {
let str = '';
let lastCommaIndex = win.lastIndexOf(",");
if (lastCommaIndex != -1) {
str += win.slice(0, lastCommaIndex + 1) + " and" + win.slice(lastCommaIndex + 1) + '!';
} else {
str += win + '!';
}
return str;
}

function ifPageEmpty() {
if (document.querySelectorAll('.wins-card').length == 0) {
const page = document.querySelector('.wins-page-contain');
Expand Down Expand Up @@ -388,18 +374,23 @@
cloneCardTemplate.querySelector('span.see-more-div').id = index;

winsCardContainer.append(cloneCardTemplate);

const winText = cloneCardTemplate.querySelector('.wins-card-text')
function addSeeMore() {
let innerHeight = Array.from(winText.childNodes).reduce((acc, el) => (el.offsetHeight || 0) + acc, 0) - 22
const winInfo = winText.querySelector('.wins-card-overview')

//makes the see more span on the bottom of the card
if (innerHeight <= winText.offsetHeight) { //checks if see more is needed.
if (
!winText.classList.contains('expanded') &&
winInfo.offsetHeight <= winText.offsetHeight
) { //checks if see more is needed.
winText.querySelector('.wins-see-more-div').setAttribute('hidden', 'true')
// winText.classList.remove('relative')
} else {
winText.querySelector('.wins-see-more-div').removeAttribute('hidden')
winsBelowDesktop()
}
if (!winText.classList.contains('expanded'))
winText.classList.add('relative')
}
addSeeMore()

Expand All @@ -412,39 +403,39 @@
if (screenWidth > 960){
updateOverlay(id);
}else{
mobileSeeMore(id);
toggleSeeMoreLess(id);
}
}

//Adds event listener to badge icons when viewers interface is below desktop size
//Click expands wins text and removes "see more"
//Click to toggle "see more" and "see less" to expand and collapse wins text
function winsBelowDesktop() {
document.querySelectorAll('.wins-badge-icon').forEach(img => img.addEventListener('click', function (event) {
const container = event.target.parentElement.parentElement;
const id = container.dataset.index
const id = container.dataset.index;

mobileSeeMore(id)
container.setAttribute('class', 'wins-tablet wins-icon-container');
toggleSeeMoreLess(id);
}))
}

function mobileSeeMore(id){
function toggleSeeMoreLess(id){
let span = document.getElementById(id);
let parent = span.parentElement.parentElement;
let winsInfo = span.parentElement.parentElement.parentElement.parentElement;
let winsIconContainer = winsInfo.nextElementSibling
parent.classList.add('expanded');
winsIconContainer.setAttribute('class', 'wins-tablet wins-icon-container');
//FIXME: this is here for when see more/see less logic is added
// if (parent.classList.contains('expanded')) {
// span.innerHTML = "see less";
// winsInfo.nextElementSibling.setAttribute('class', 'wins-tablet wins-icon-container');
// }
// else {
// span.innerHTML = "...see more";
// winsInfo.nextElementSibling.removeAttribute('class', 'wins-tablet');
// }
let winsIconContainer = winsInfo.nextElementSibling;

if (!parent.classList.contains('expanded')) {
parent.setAttribute('class','project-inner wins-card-text expanded');
span.innerHTML = '<img src="/assets/images/wins-page/caret.svg" alt="caret">&nbsp; see less';
winsIconContainer.setAttribute('class', 'wins-tablet wins-icon-container');
}
else {
parent.setAttribute('class','project-inner wins-card-text relative');
span.innerHTML = "...see more";
winsIconContainer.setAttribute('class', 'wins-icon-container');
}
}

// need to delete makeElement and makeIcon
function makeElement(elementType, parent, className) {
let child = document.createElement(elementType);
Expand Down Expand Up @@ -526,7 +517,7 @@
cloneCardTemplate.insertAdjacentHTML('beforeend',
`<div class='overlay-item-container'>
<img class="overlay-badge-icon" alt="${badgeIcons[otherIcon]}" src="${SVG_FILE_PATH}${otherIcon}">
<p class="overlay-wins-text" data-wins="font-styling">Other</p>
<p class="overlay-wins-text" data-wins="font-styling">${item}</p>
</div>`
)
return
Expand Down