1 $(document).ready(function(){
2 $("head").append('<style type="text/css"></style>');
3 var newStyleElement = $("head").children(':last');
4 newStyleElement.html('.limit-height{max-height: ' + postLimitHeight + 'px; overflow: hidden;}');
6 handleNewWallItemBodies();
8 document.addEventListener("postprocess_liveupdate", function() {
9 handleNewWallItemBodies();
13 function handleNewWallItemBodies() {
14 $('.wall-item-body:not(.showmore-done)').each(function() {
16 $el.addClass('showmore-done');
17 if ($el.has('button.content-filter-button').length > 0) {
18 $el.removeClass('limitable');
22 addHeightToggleHandler($el);
23 var limited = processHeightLimit($el);
26 var mutationObserver = new MutationObserver(function(mutations) {
27 var limited = processHeightLimit($el);
29 mutationObserver.disconnect()
32 mutationObserver.observe($el[0], { attributes: true, characterData: true, childList: true, subtree: true, attributeOldValue: true, characterDataOldValue: true });
34 $el.imagesLoaded().then(function(){
35 processHeightLimit($el);
41 function addHeightToggleHandler($item) {
42 var itemId = parseInt($item.attr("id").replace("wall-item-body-", ""));
43 $item.data("item-id", itemId);
44 var wrapperId = "wall-item-body-wrapper-" + itemId;
45 var toggleId = "wall-item-body-toggle-" + itemId;
47 $item.wrap('<div id="' + wrapperId + '" class="wall-item-body-wrapper"></div>');
48 $("#" + wrapperId).append('<div class="wall-item-body-toggle" data-item-id="' + itemId + '" id="' + toggleId + '" ><button type="button" class="wall-item-body-toggle-text">' + showmore_dyn_showmore_linktext + '</button></div>');
49 $item.addClass("limitable limit-height");
51 var $toggle = $("#" + toggleId);
53 $toggle.click(function(el) {
54 $item.toggleClass("limit-height");
56 $item.removeClass("limitable");
60 function processHeightLimit($item) {
61 if (!$item.hasClass("limitable")) {
65 var itemId = $item.data("item-id");
66 var $toggle = $("#wall-item-body-toggle-" + itemId);
67 if ($item.height() < postLimitHeight) {
68 $item.removeClass("limit-height");
72 $item.addClass("limit-height");