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

Update dataverse.xhtml to add "read more/read less" buttons for dataverse descriptions #9222

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/release-notes/1249-collapse_dataverse_description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Long descriptions for collections are now truncated but can be expanded to read the full description.
2 changes: 1 addition & 1 deletion src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ delete=Delete
copyClipboard=Copy to Clipboard
truncateMoreBtn=Read full {0} [+]
truncateMoreTip=Click to read the full {0}.
truncateLessBtn=Collapse {0} [+]
truncateLessBtn=Collapse {0} [-]
truncateLessTip=Click to collapse the {0}.
yes=Yes
no=No
Expand Down
13 changes: 7 additions & 6 deletions src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@
<p:remoteCommand name="datasetSaveCommand" action="#{DatasetPage.save()}" update=":datasetForm,:messagePanel"/>
<!-- END: Publish/Submit for Review Dialogs -->
</h:form>
<c:set var="descriptionText" value="#{DatasetPage.datasetVersionUI.description.datasetFieldType.localeTitle}" />
<script>
//<![CDATA[
$(document).ready(function () {
Expand All @@ -1798,13 +1799,13 @@
function summaryDescTruncation() {
// truncate summary description, contentTruncate function in dv_rebind_bootstrap_ui.js
// add summary desc row id to pass as selector param
var descId = 'dsDescription';
var descId = 'dsDescription td > div';
// add metadata dynamic label text, tooltip text from bundle as param
var truncMoreBtn = '#{of:format1(bundle.truncateMoreBtn, DatasetPage.datasetVersionUI.description.datasetFieldType.localeTitle)}';
var truncMoreTip = '#{of:format1(bundle.truncateMoreTip, DatasetPage.datasetVersionUI.description.datasetFieldType.localeTitle)}';
var truncLessBtn = '#{of:format1(bundle.truncateLessBtn, DatasetPage.datasetVersionUI.description.datasetFieldType.localeTitle)}';
var truncLessTip = '#{of:format1(bundle.truncateLessTip, DatasetPage.datasetVersionUI.description.datasetFieldType.localeTitle)}';
var truncMoreBtn = '#{of:format1(bundle.truncateMoreBtn, descriptionText)}';
var truncMoreTip = '#{of:format1(bundle.truncateMoreTip, descriptionText)}';
var truncLessBtn = '#{of:format1(bundle.truncateLessBtn, descriptionText)}';
var truncLessTip = '#{of:format1(bundle.truncateLessTip, descriptionText)}';

// pass bundle text variabls as params to function
contentTruncate(descId, truncMoreBtn, truncMoreTip, truncLessBtn, truncLessTip);
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/webapp/dataverse.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
<o:importFunctions type="edu.harvard.iq.dataverse.util.MarkupChecker" />
<div class="row margin-bottom" jsf:rendered="#{!empty DataversePage.dataverse.description and !widgetWrapper.widgetView}">
<div id="dataverseDesc" class="col-xs-12">
<h:outputText value="#{MarkupChecker:sanitizeBasicHTML(DataversePage.dataverse.description)}" escape="false"/>
<h:outputText value="#{MarkupChecker:sanitizeBasicHTML(DataversePage.dataverse.description)}" escape="false"/>
</div>
</div>
<!-- Featured Dataverses Carousel -->
Expand Down Expand Up @@ -822,12 +822,14 @@
</div>
</h:form>
</p:dialog>
<c:set var="descriptionText" value="#{bundle.description}" />
<script>
//<![CDATA[
var scrollPos=0;
$(document).ready(function () {
initCarousel();
popoverHTML('#{bundle.htmlAllowedTitle}','#{bundle.htmlAllowedTags}');
summarizeDesc();
});
function initCarousel() {
var owl1 = $("#featuredDataversesList");
Expand All @@ -853,6 +855,18 @@
}
$('#featuredDataversesList .item').matchHeight();
}
function summarizeDesc() {
// truncate summary description, contentTruncate function in dv_rebind_bootstrap_ui.js
// add id to pass as selector param
var descId = 'dataverseDesc';
// add metadata dynamic label text, tooltip text from bundle as param
var truncMoreBtn = '#{of:format1(bundle.truncateMoreBtn, descriptionText)}';
var truncMoreTip = '#{of:format1(bundle.truncateMoreTip, descriptionText)}';
var truncLessBtn = '#{of:format1(bundle.truncateLessBtn, descriptionText)}';
var truncLessTip = '#{of:format1(bundle.truncateLessTip, descriptionText)}';
// pass bundle text variables as params to function
contentTruncate(descId, truncMoreBtn, truncMoreTip, truncLessBtn, truncLessTip);
}
function callOnError(){
window.scrollTo(0, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/resources/js/dv_rebind_bootstrap_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function sharrre(){
*/
function contentTruncate(truncSelector, truncMoreBtn, truncMoreTip, truncLessBtn, truncLessTip){
// SELECTOR ID FROM PARAMETERS
$('#' + truncSelector + ' td > div:first-child').each(function () {
$('#' + truncSelector).each(function () {

// add responsive img class to limit width to that of container
$(this).find('img').attr('class', 'img-responsive');
Expand All @@ -176,7 +176,7 @@ function contentTruncate(truncSelector, truncMoreBtn, truncMoreTip, truncLessBtn

if (containerHeight > 250) {
// ADD A MAX-HEIGHT TO CONTAINER
$(this).css({'max-height':'250px','overflow-y':'hidden','position':'relative'});
$(this).css({'max-height':'250px','overflow-y':'hidden', 'overflow-x':'hidden', 'position':'relative'});

// BTN LABEL TEXT, ARIA ATTR'S, FROM BUNDLE VIA PARAMETERS
var readMoreBtn = '<button class="btn btn-link desc-more-link" type="button" data-toggle="tooltip" data-original-title="' + truncMoreTip + '" aria-expanded="false" aria-controls="#' + truncSelector + '">' + truncMoreBtn + '</button>';
Expand Down