Created
October 22, 2018 07:52
-
-
Save chillybin/4abed9cc68f16d270680ba9a7b955928 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("footer.infinite a").click(function(e){ | |
loadArticle(); | |
e.preventDefault(); | |
}); | |
function loadArticle() { | |
$("footer.infinite a").html("..."); | |
var offset = $("footer.infinite a").data("count"); | |
var num = parseInt(offset, 10); | |
var cat = $("footer.infinite a").data('cat'); | |
var loading = $("footer.infinite a").data('loading'); | |
if(loading == 0){ | |
$("footer.infinite a").data('loading',"1"); | |
$.ajax({ | |
url: "//" + location.host + "/wp-admin/admin-ajax.php", | |
type:'POST', | |
data: { | |
action: 'infinitescroll', | |
offset: num, | |
category: cat | |
}, | |
success: function(html){ | |
var off = $("footer.infinite a").data('count'); | |
off = parseInt(off, 10) + 5; | |
$("footer.infinite a").data('loading',"0"); | |
if(html == ''){ | |
$("footer.infinite a").html('done'); | |
} | |
else { | |
$("footer.infinite").before(html); | |
$("footer.infinite a").data("count", off); | |
$("footer.infinite a").html("more"); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment