#8374: Addessing review comments

pull/968/head
Christian Wiwie 2020-03-13 22:09:21 +01:00
parent 858904090e
commit ab24c621b2
2 changed files with 59 additions and 66 deletions

View File

@ -1,79 +1,72 @@
$(document).ready(function(){ $(document).ready(function(){
handleNewWallItemBodies(); handleNewWallItemBodies();
var mutationObserver = new MutationObserver(function(mutations) { document.addEventListener("postprocess_liveupdate", function() {
handleNewWallItemBodies(); handleNewWallItemBodies();
}); });
mutationObserver.observe($("#content")[0], { attributes: false, characterData: false, childList: true, subtree: true, attributeOldValue: false, characterDataOldValue: false });
}); });
function handleNewWallItemBodies() { function handleNewWallItemBodies() {
$('.wall-item-body:not(.showmore-done)').each(function(i, el) { $('.wall-item-body:not(.showmore-done)').each(function() {
$(el).addClass('showmore-done'); var $el = $(this);
if ($(el).has('button.content-filter-button').length > 0) { $el.addClass('showmore-done');
$(el).removeClass('limitable'); if ($el.has('button.content-filter-button').length > 0) {
$el.removeClass('limitable');
return; return;
} }
var itemId = $(el).attr('id'); addHeightToggleHandler($el);
addHeightToggleHandler(itemId); var limited = processHeightLimit($el);
var limited = processHeightLimit(itemId);
if (!limited) { if (!limited) {
var mutationObserver = new MutationObserver(function(mutations) { var mutationObserver = new MutationObserver(function(mutations) {
var limited = processHeightLimit(itemId); var limited = processHeightLimit($el);
if (limited) { if (limited) {
mutationObserver.disconnect() mutationObserver.disconnect()
} }
}); });
mutationObserver.observe(el, { attributes: true, characterData: true, childList: true, subtree: true, attributeOldValue: true, characterDataOldValue: true }); mutationObserver.observe($el[0], { attributes: true, characterData: true, childList: true, subtree: true, attributeOldValue: true, characterDataOldValue: true });
$(el).imagesLoaded().then(function(){ $el.imagesLoaded().then(function(){
processHeightLimit(itemId); processHeightLimit($el);
}); });
} }
}); });
} }
function addHeightToggleHandler(id) { function addHeightToggleHandler($item) {
var itemIdSel = "#" + id; var itemId = parseInt($item.attr("id").replace("wall-item-body-", ""));
var itemId = parseInt(id.replace("wall-item-body-", "")); $item.data("item-id", itemId);
$(itemIdSel).data("item-id", itemId);
var wrapperId = "wall-item-body-wrapper-" + itemId; var wrapperId = "wall-item-body-wrapper-" + itemId;
var wrapperIdSel = "#" + wrapperId;
var toggleId = "wall-item-body-toggle-" + itemId; var toggleId = "wall-item-body-toggle-" + itemId;
var toggleIdSel = "#" + toggleId;
$(itemIdSel).wrap('<div id="' + wrapperId + '" class="wall-item-body-wrapper"></div>'); $item.wrap('<div id="' + wrapperId + '" class="wall-item-body-wrapper"></div>');
$(wrapperIdSel).append('<div class="wall-item-body-toggle" data-item-id="' + itemId + '" id="' + toggleId + '" ><a href="javascript:void(0)" class="wall-item-body-toggle-text">Show more ...</a></div>'); $("#" + wrapperId).append('<div class="wall-item-body-toggle" data-item-id="' + itemId + '" id="' + toggleId + '" ><a href="javascript:void(0)" class="wall-item-body-toggle-text">Show more ...</a></div>');
$(itemIdSel).addClass("limitable"); $item.addClass("limitable limit-height");
$(itemIdSel).addClass("limit-height");
$(toggleIdSel).show(); var $toggle = $("#" + toggleId);
$(toggleIdSel).click(function(el) { $toggle.show();
$(itemIdSel).toggleClass("limit-height"); $toggle.click(function(el) {
$item.toggleClass("limit-height");
$(this).hide(); $(this).hide();
$(itemIdSel).removeClass("limitable"); $item.removeClass("limitable");
}); });
} }
function processHeightLimit(id) { function processHeightLimit($item) {
var idSel = "#" + id; if (!$item.hasClass("limitable")) {
if (!$(idSel).hasClass("limitable")) {
return false; return false;
} }
var itemId = $item.data("item-id");
var itemId = $(idSel).data("item-id"); var $toggle = $("#wall-item-body-toggle-" + itemId);
var toggleSelector = "#wall-item-body-toggle-" + itemId; if ($item.height() < 250) {
if ($(idSel).height() < 250) { $item.removeClass("limit-height");
$(idSel).removeClass("limit-height"); $toggle.hide();
$(toggleSelector).hide();
return false; return false;
} else { } else {
$(idSel).addClass("limit-height"); $item.addClass("limit-height");
$(toggleSelector).show(); $toggle.show();
return true; return true;
} }
} }