/**
* Source block functionality
*/
(function($) {
let viewAllLink = $('.viewall-link');
let viewLessLink = $('.viewless-link');
let sourceList = $('.sources-block ol');
if (!viewAllLink.length ||
!sourceList.length ||
!viewLessLink.length
) {
return;
}
/**
* Clicking on View All Sources link...
*/
viewAllLink.click(function() {
sourceList.css('height', 'unset');
sourceList.css('overflow', 'visible');
sourceList.css('-webkit-mask-image', 'none');
sourceList.css('mask-image', 'none');
viewAllLink.css('display', 'none');
viewLessLink.css('display', 'block');
});
/**
* Clicking on the Hide Sources link...
*/
viewLessLink.click(function() {
let height = '80px';
if (window.matchMedia("(max-width: 767px)").matches) {
if (countSourceLines(sourceList) > 6) {
height = '144px';
}
} else {
if (countSourceLines(sourceList) > 3) {
}
}
sourceList.css('height', height);
sourceList.css('overflow', 'hidden'); // this is the only value that needed to be updated
sourceList.css('-webkit-mask-image', 'linear-gradient(180deg, #000 70%, transparent)');
sourceList.css('mask-image', 'mask-image: linear-gradient(180deg, #000 70%, transparent);');
viewAllLink.css('display', 'block');
viewLessLink.css('display', 'none');
});
/**
* Set initial state of Sources block and if we need to display the View All link or not.
*/
if (window.matchMedia("(max-width: 767px)").matches) {
if (countSourceLines(sourceList) > 6) {
sourceList.css('height', '144px');
sourceList.css('overflow', 'hidden');
viewAllLink.css('display', 'block');
} else {
sourceList.css('-webkit-mask-image', 'none');
sourceList.css('mask-image', 'none');
viewAllLink.css('display', 'none');
}
} else {
console.log(countSourceLines(sourceList));
if (countSourceLines(sourceList) > 3) {
sourceList.css('height', '80px');
sourceList.css('overflow', 'hidden');
viewAllLink.css('display', 'block');
} else {
sourceList.css('-webkit-mask-image', 'none');
sourceList.css('mask-image', 'none');
viewAllLink.css('display', 'none');
}
}
/**
*
* @param el
* @returns {number}
*/
function countSourceLines(el) {
let olElement = $(el);
let olHeight = olElement.outerHeight();
let lineHeight = parseInt(olElement.css("line-height").replace("px", ""));
return olHeight / lineHeight;
}
})(jQuery);
html {
scroll-behavior: smooth !important;
margin: 0;
padding: 0;
}
body {
font-family: 'Museo Sans', sans-serif;
font-size: 18px;
line-height: 28px;
font-weight: 300;
color: #222;
margin: 0;
padding: 0;
}
#content-wrap {
padding: 50px;
}
#footer {
text-align: center;
background: #222;
color: #FFF;
padding: 50px;
}
.sources-block {
background: #F0F0F0;
padding: 8px;
margin: 48px 0;
}
.sources-block h4 {
font-weight: 600;
margin: 0;
padding: 8px;
}
.sources-block p {
margin-bottom: 0;
}
.sources-block ol {
padding-left: 32px;
-webkit-mask-image: linear-gradient(180deg, #000 70%, transparent);
mask-image: linear-gradient(180deg, #000 70%, transparent);
margin-bottom: 5px;
}
.sources-block li {
word-break: break-word;
margin-bottom: 0;
}
.sources-block .viewall-link,
.sources-block .viewless-link {
font-weight: 600;
font-size: 16px;
line-height: 24px;
text-align: center;
color: #298FC2;
cursor: pointer;
border-top: 1px solid #298fc2;
padding: 8px 0 0;
}
.sources-block .viewless-link {
display: none;
}
.sources-block i {
padding-left: 5px;
}
<!DOCTYPE html>
<html>
<head>
<title>Footer Whitespace Demo</title>
</head>
<body>
<div id="content-wrap">
<h1>Example Page</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris et felis in magna dignissim finibus. Fusce neque ante, mattis condimentum metus id, rhoncus fermentum neque. Nulla vel aliquam eros. Proin convallis imperdiet mauris id dignissim. Duis
tortor magna, molestie sit amet tortor egestas, aliquet sollicitudin tortor. Curabitur volutpat convallis nisl, ut vehicula massa convallis eu. Aliquam erat volutpat. Pellentesque sit amet lacus sem. Nam lacus erat, viverra eget tincidunt non, ullamcorper
non justo. Sed ultricies diam eu lacus luctus eleifend.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris et felis in magna dignissim finibus. Fusce neque ante, mattis condimentum metus id, rhoncus fermentum neque. Nulla vel aliquam eros. Proin convallis imperdiet mauris id dignissim. Duis
tortor magna, molestie sit amet tortor egestas, aliquet sollicitudin tortor. Curabitur volutpat convallis nisl, ut vehicula massa convallis eu. Aliquam erat volutpat. Pellentesque sit amet lacus sem. Nam lacus erat, viverra eget tincidunt non, ullamcorper
non justo. Sed ultricies diam eu lacus luctus eleifend.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris et felis in magna dignissim finibus. Fusce neque ante, mattis condimentum metus id, rhoncus fermentum neque. Nulla vel aliquam eros. Proin convallis imperdiet mauris id dignissim. Duis
tortor magna, molestie sit amet tortor egestas, aliquet sollicitudin tortor. Curabitur volutpat convallis nisl, ut vehicula massa convallis eu. Aliquam erat volutpat. Pellentesque sit amet lacus sem. Nam lacus erat, viverra eget tincidunt non, ...
<div class="sources-block">
<h4>Sources</h4>
<ol>
<li>Source Blah Blah Blah</li>
</ol>
<div class="viewall-link">View All Sources <i class="fa fa-chevron-down"></i></div>
<div class="viewless-link">Hide Sources <i class="fa fa-chevron-up"></i></div>
</div>
</div>
<div id="footer">
Footer Here
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js" integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
</html>