Share code load more posts cho Blogger

Share code load more posts cho Blogger 


Demo: https://www.nhipsong24h.net/search/label/chuyen-cua-sao
Chèn trước thẻ đóng </body>
<b:if cond='data:view.isMultipleItems'>
<style type='text/css'>
a.loadpost{display:inline-block;padding:0 40px 0 10px;height:36px;background:#ff6a28;position:relative;font-family:Arial;font-size:18px;text-transform:uppercase;line-height:36px;color:#fff;text-decoration:none;border-radius:100px;-webkit-border-radius:100px;-moz-border-radius:100px;transition:background .3s;-webkit-transition:background .3s;-moz-transition:background .3s}
a.loadpost:before{display:block;width:30px;height:30px;background:url(https://i.imgur.com/W169O3u.png) -68px -36px no-repeat;position:absolute;top:3px;right:5px;content:''}
a.loadpost:hover{background: #263040;}
</style>
<script>
//<![CDATA[
(function($) {
    var loadingGif = 'https://1.bp.blogspot.com/-KV2XR964ylU/VmPf26HwlsI/AAAAAAAAASI/7l-4hZ1NV7o/s000/ajax-loader.gif';
    var olderPostsLink = '';
    var loadMoreDiv = null;
    var postContainerSelector = 'div.blog-posts';
    var loading = false;
    var win = $(window);
    var doc = $(document);
    // Took from jQuery to avoid permission denied error in IE.
    var rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
    function loadDisqusScript(domain) {
        $.getScript('http://' + domain + '.disqus.com/blogger_index.js');
    }
    function loadMore() {
        if (loading) {
            return;
        }
        loading = true;
        if (!olderPostsLink) {
            loadMoreDiv.hide();
            return;
        }
        loadMoreDiv.find('a').hide();
        loadMoreDiv.find('img').show();
        $.ajax(olderPostsLink, {
            'dataType': 'html'
        }).done(function(html) {
            var newDom = $('<div></div>').append(html.replace(rscript, ''));
            var newLink = newDom.find('a.blog-pager-older-link');
            if (newLink) {
                olderPostsLink = newLink.attr('href');
            } else {
                olderPostsLink = '';
                loadMoreDiv.hide();
            }
            var newPosts = newDom.find(postContainerSelector).children('.post-outer');
            $(postContainerSelector).append(newPosts);
            // Loaded more posts successfully.  Register this pageview with
            // Google Analytics.
            if (window._gaq) {
                window._gaq.push(['_trackPageview', olderPostsLink]);
            }
            // Render +1 buttons.
            if (window.gapi && window.gapi.plusone && window.gapi.plusone.go) {
                window.gapi.plusone.go();
            }
            // Render Disqus comments.
            if (window.disqus_shortname) {
                loadDisqusScript(window.disqus_shortname);
            }
            // Render Facebook buttons.
            if (window.FB && window.FB.XFBML && window.FB.XFBML.parse) {
                window.FB.XFBML.parse();
            }
            loadMoreDiv.find('img').hide();
            loadMoreDiv.find('a').show();
            loading = false;
        });
    }
    function init() {
        if (_WidgetManager._GetAllData().blog.pageType == 'item') {
            return;
        }
        olderPostsLink = $('a.blog-pager-older-link').attr('href');
        if (!olderPostsLink) {
            return;
        }
        var link = $('<a class="loadpost" href="javascript:;" title="Bấm để xem thêm">xem thêm</a>');
        link.click(loadMore);
        var img = $('<img src="' + loadingGif + '" style="display: none;">');
        loadMoreDiv = $('<div style="text-align:center;clear:both;"></div>');
        loadMoreDiv.append(link);
        loadMoreDiv.append(img);
        loadMoreDiv.insertBefore($('#blog-pager'));
        $('#blog-pager').hide();
    }
    $(document).ready(init);
})(jQuery);
//]]>
</script>
</b:if>
Nguồn: Nguyễn Tuấn