Xử lý những link có đoạn text quá dài trong website

Note lại đây và cũng để chia sẻ đoạn jQuery tôi đang dùng để xử lý mấy cái link có text quá dài làm tràn layout của website (__lý do là chưa tìm được hướng giải quyết khác):

Giải thích là như vầy: đoạn script sẽ duyệt từng thẻ a trong trang web sau khi đã load, lấy cái text trong thẻ a kiểm tra xem; nếu dài hơn 60 ký tự, thì nó ẩn đi, thêm vào 1 button “Show this link”; khi user nhấn vào button đó, nó sẽ hiện lại đoạn text của link, và bỏ đi cái button.

<script>
$(document).ready(function(){
    var i = 0;
    $("article span p a").each(function(){
        var url1 = $(this).text();
        if (url1.length &amp;gt; 60) {
            $(this).hide();
            $(this).after("<button class='long-url' id="+i+" title='This link is too long to display'>Show the link</button>");
        }
        i+=1;
    });
    
    $("article span p button").click(function(){
        var indexB = this.id;
        $("article span p a").eq(indexB).show();
        $(this).remove();
    });
});
</script>

P/s: Mà thực ra do quá rảnh + lười + chả biết nghĩ cái gì mà mới làm vậy thôi, chứ bình thường nếu text quá dài, blogger có thể sửa trực tiếp đoạn text đó trong khi chèn link vào bài viết.

RELATED POSTS

AttributeError: module ‘yaml’ has no attribute ‘FullLoader’

Issue found: Solution:Reference: https://stackoverflow.com/questions/55551191/module-yaml-has-no-attribute-fullloader The FullLoader class is only available in PyYAML 5.1 and later. Version 5.1 was released on March 13, 2019 and has probably not filtered down to many distributions yet. You can check the version of PyYAML by inspecting yaml.__version__: If you

Read More »
Share the Post: