-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathshowmore_dyn.js
90 lines (78 loc) · 2.27 KB
/
showmore_dyn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var nextBodyIdx = 0;
$(document).ready(function() {
loc = window.location.pathname;
if (loc.startsWith('/display')) {
return;
}
if (postLimitHeight) {
$('head').append('<style type="text/css">.limit-height{max-height: ' + postLimitHeight + 'px; overflow: hidden; }</style>');
handleNewWallItemBodies();
document.addEventListener('postprocess_liveupdate', function() {
handleNewWallItemBodies();
});
}
});
function handleNewWallItemBodies() {
$('.wall-item-body:not(.showmore-done)').each(function() {
var $el = $(this);
$el.addClass('showmore-done');
if ($el.has('button.content-filter-button').length > 0) {
$el.removeClass('limitable');
return;
}
if (!$el.attr("id")) {
$el.attr("id", nextBodyIdx++);
}
addHeightToggleHandler($el);
var limited = processHeightLimit($el);
if (!limited) {
var mutationObserver = new MutationObserver(function() {
var limited = processHeightLimit($el);
if (limited) {
mutationObserver.disconnect()
}
});
mutationObserver.observe($el[0], {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});
$el.imagesLoaded().then(function() {
processHeightLimit($el);
});
}
});
}
function addHeightToggleHandler($item) {
var itemId = parseInt($item.attr("id").replace("wall-item-body-", ""));
$item.data("item-id", itemId);
var toggleId = "wall-item-body-toggle-" + itemId;
$item.append('<div class="wall-item-body-toggle" data-item-id="' + itemId + '" id="' + toggleId + '" ><button type="button" class="wall-item-body-toggle-text" aria-hidden="true">' + showmore_dyn_showmore_linktext + '</button></div>');
$item.addClass("limitable limit-height");
var $toggle = $("#" + toggleId);
$toggle.show();
$toggle.click(function(el) {
$item.toggleClass("limit-height");
$(this).hide();
$item.removeClass("limitable");
});
}
function processHeightLimit($item) {
if (!$item.hasClass("limitable")) {
return false;
}
var itemId = $item.data("item-id");
var $toggle = $("#wall-item-body-toggle-" + itemId);
if ($item.height() < postLimitHeight) {
$item.removeClass("limit-height");
$toggle.hide();
return false;
} else {
$item.addClass("limit-height");
$toggle.show();
return true;
}
}