Last active
December 16, 2015 07:19
-
-
Save ericmann/5397940 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
// load posts | |
var loadPosts = document.getElementById( 'loadposts' ), | |
$loadPostsA = $( loadPosts.querySelectorAll( 'a' ) ), | |
$articles = $( document.getElementById( 'articles' ) ); | |
$loadPostsA.on( 'click', function(e) { | |
e.preventDefault(); | |
var $this = $( this ); | |
$this.html( 'Loading…' ); | |
$.ajax({ | |
type: "GET", | |
url: $this.attr( 'href' ) + '#content', | |
dataType: "html", | |
success: function( out ) { | |
var $out = $( out ), | |
respElement = $out[0], | |
$result = respElement.querySelector( '#content article' ), | |
nextLink = respElement.querySelector( '#loadposts a' ).getAttribute( 'href' ); | |
$articles.append( $result ); | |
$this.text( 'Load More' ); | |
if ( nextlink != undefined ) { | |
$this.attr( 'href', nextlink ); | |
} else { | |
loadPosts.remove(); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment