-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: APPS-2680 html tags and "read more" button for the search resul…
…ts (#1152) * feat: APPS-2680 html tags and "read more" button for the search results * Allow .html_safe * APPS-2680: updated JS to not cut description in the middle of the word * APPS-2680: updated JS to not cut description in the middle of the word and number --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Andy Wallace <[email protected]>
- Loading branch information
1 parent
1ccf5b3
commit 398dfdd
Showing
4 changed files
with
35 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
document.addEventListener("turbolinks:load", function() { | ||
var viewMoreButtons = document.querySelectorAll('.view-more') | ||
document.addEventListener("turbolinks:load", function () { | ||
var viewMoreButtons = document.querySelectorAll(".view-more"); | ||
viewMoreButtons.forEach(function (el) { | ||
var description = el.previousElementSibling | ||
var originalText = description.innerText | ||
var truncatedText = description.innerText.substr(0, 299) | ||
truncatedText += '…' | ||
var description = el.previousElementSibling; | ||
var originalText = description.innerText; | ||
|
||
if (description.innerText.length < 300) { | ||
el.style.display = 'none' | ||
} else { | ||
description.innerText = truncatedText | ||
if (originalText.length < 300) { | ||
el.style.display = "none"; | ||
return; | ||
} | ||
|
||
el.addEventListener('click', function () { | ||
if (description.classList.contains('description')) { | ||
el.innerHTML = 'Read Less <div class="up-arrow">»</div>' | ||
description.classList.replace('description', 'description-full') | ||
description.innerText = originalText | ||
var truncatedText = originalText.substr(0, 299); | ||
|
||
// To avoid truncation in the middle of the word get the end of the word | ||
// from the the cut part of the description. | ||
var cutString = originalText.substr(299); | ||
truncatedText += cutString.match(/^[a-z0-9]*/i)[0]; //regex gets the end of the word | ||
|
||
truncatedText += "…"; | ||
description.innerText = truncatedText; | ||
|
||
el.addEventListener("click", function () { | ||
if (description.classList.contains("description")) { | ||
el.innerHTML = 'Read Less <div class="up-arrow">»</div>'; | ||
description.classList.replace("description", "description-full"); | ||
description.innerText = originalText; | ||
} else { | ||
el.innerHTML = 'Read More <div class="down-arrow">»</div>' | ||
description.classList.replace('description-full', 'description') | ||
description.innerText = truncatedText | ||
el.innerHTML = 'Read More <div class="down-arrow">»</div>'; | ||
description.classList.replace("description-full", "description"); | ||
description.innerText = truncatedText; | ||
} | ||
}) | ||
}) | ||
}) | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.view-more { | ||
@extend a; | ||
cursor: pointer; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.down-arrow { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters