]> git.mxchange.org Git - friendica-addons.git/blobdiff - showmore_dyn/showmore_dyn.js
[twitter] Fix return value of twitter_user_to_contact()
[friendica-addons.git] / showmore_dyn / showmore_dyn.js
index 7d91c33769890610ea7323c341325ae79e542ec5..4b32b2d31d7da499a474bba34869ce2de7dbe886 100644 (file)
@@ -1,4 +1,15 @@
-$(document).ready(function(){
+var nextBodyIdx = 0;
+
+$(document).ready(function() {
+       loc = window.location.pathname;
+       if (loc.startsWith('/display')) {
+               return;
+       }
+
+       $("head").append('<style type="text/css"></style>');
+       var newStyleElement = $("head").children(':last');
+       newStyleElement.html('.limit-height{max-height: ' + postLimitHeight + 'px; overflow: hidden; }');
+
        handleNewWallItemBodies();
 
        document.addEventListener("postprocess_liveupdate", function() {
@@ -15,19 +26,29 @@ function handleNewWallItemBodies() {
                        return;
                }
 
+               if (!$el.attr("id")) {
+                       $el.attr("id", nextBodyIdx++);
+               }
                addHeightToggleHandler($el);
                var limited = processHeightLimit($el);
 
                if (!limited) {
-                       var mutationObserver = new MutationObserver(function(mutations) {
+                       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 });
+                       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($el);
                        });
                }
@@ -37,11 +58,9 @@ function handleNewWallItemBodies() {
 function addHeightToggleHandler($item) {
        var itemId = parseInt($item.attr("id").replace("wall-item-body-", ""));
        $item.data("item-id", itemId);
-       var wrapperId = "wall-item-body-wrapper-" + itemId;
        var toggleId = "wall-item-body-toggle-" + itemId;
 
-       $item.wrap('<div id="' + wrapperId + '" class="wall-item-body-wrapper"></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>');
+       $item.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>');
        $item.addClass("limitable limit-height");
 
        var $toggle = $("#" + toggleId);
@@ -60,7 +79,7 @@ function processHeightLimit($item) {
 
        var itemId = $item.data("item-id");
        var $toggle = $("#wall-item-body-toggle-" + itemId);
-       if ($item.height() < 250) {
+       if ($item.height() < postLimitHeight) {
                $item.removeClass("limit-height");
                $toggle.hide();
                return false;
@@ -70,5 +89,3 @@ function processHeightLimit($item) {
                return true;
        }
 }
-
-