Skip to content

Commit af93ea3

Browse files
authored
Merge pull request #1234 from ElixirTeSS/fix-see-more
Fix `tess-expandable` behaviour when multiple under the same parent e…
2 parents 41c5503 + 2937932 commit af93ea3

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

app/assets/javascripts/application.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ document.addEventListener("turbolinks:load", function(e) {
277277
LearningPaths.init();
278278

279279
$('.tess-expandable').each(function () {
280+
if (this.dataset.origHeight) {
281+
return;
282+
}
280283
var limit = this.dataset.heightLimit || 300;
281284

282285
if (this.clientHeight > limit) {
@@ -286,32 +289,11 @@ document.addEventListener("turbolinks:load", function(e) {
286289
this.dataset.origHeight = this.clientHeight;
287290
this.style.maxHeight = '' + limit + 'px';
288291
this.classList.add('tess-expandable-closed');
289-
var btn = $('<a href="#" class="tess-expandable-btn">Show more</a>');
292+
const btn = $('<a href="#" class="tess-expandable-btn">Show more</a>');
290293
btn.insertAfter($(this));
291294
}
292295
});
293296

294-
$(document).on('click', '.tess-expandable-btn', function (event) {
295-
event.preventDefault();
296-
var div = this.parentElement.querySelector('.tess-expandable');
297-
var maxHeight = parseInt(div.dataset.origHeight) + 80;
298-
var limit = parseInt(div.dataset.heightLimit || "300");
299-
300-
if (div.classList.contains('tess-expandable-closed')) {
301-
div.classList.add('tess-expandable-open');
302-
div.classList.remove('tess-expandable-closed');
303-
div.style.maxHeight = '' + maxHeight + 'px';
304-
this.innerHTML = 'Show less';
305-
} else {
306-
div.classList.remove('tess-expandable-open');
307-
div.classList.add('tess-expandable-closed');
308-
div.style.maxHeight = '' + limit + 'px';
309-
this.innerHTML = 'Show more';
310-
}
311-
312-
return false;
313-
});
314-
315297
$('.faq .question dt').click(function () {
316298
var button = $(this).find('.expand');
317299
var sign = button.text();
@@ -380,6 +362,36 @@ $(document).on('click', '[href="#activity_log"]', function () {
380362
return false;
381363
});
382364

365+
$(document).on('click', '.tess-expandable-btn', function (event) {
366+
event.preventDefault();
367+
let div = this.previousElementSibling;
368+
369+
if (!div || !div.classList.contains('tess-expandable')) {
370+
div = this.parentElement.querySelector('.tess-expandable');
371+
}
372+
373+
if (!div) {
374+
return false;
375+
}
376+
377+
const maxHeight = parseInt(div.dataset.origHeight) + 80;
378+
const limit = parseInt(div.dataset.heightLimit || "300");
379+
380+
if (div.classList.contains('tess-expandable-closed')) {
381+
div.classList.add('tess-expandable-open');
382+
div.classList.remove('tess-expandable-closed');
383+
div.style.maxHeight = '' + maxHeight + 'px';
384+
this.innerHTML = 'Show less';
385+
} else {
386+
div.classList.remove('tess-expandable-open');
387+
div.classList.add('tess-expandable-closed');
388+
div.style.maxHeight = '' + limit + 'px';
389+
this.innerHTML = 'Show more';
390+
}
391+
392+
return false;
393+
});
394+
383395
// sticky-navbar feature
384396
document.addEventListener('turbolinks:load', function () {
385397

0 commit comments

Comments
 (0)