|
@@ -20,6 +20,7 @@
|
|
var page = 1;
|
|
var page = 1;
|
|
var timer;
|
|
var timer;
|
|
|
|
|
|
|
|
+wp.api.loadPromise.done( function() {
|
|
var posts = new wp.api.collections.Posts();
|
|
var posts = new wp.api.collections.Posts();
|
|
var options = {
|
|
var options = {
|
|
data: {
|
|
data: {
|
|
@@ -40,6 +41,44 @@
|
|
author: settings.queriedObject.data.ID
|
|
author: settings.queriedObject.data.ID
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Initial posts fetch
|
|
|
|
+ */
|
|
|
|
+ posts.fetch( options ).done( function() {
|
|
|
|
+
|
|
|
|
+ if ( posts.length > 0 ) {
|
|
|
|
+ $postContainer.append( $moreButton );
|
|
|
|
+
|
|
|
|
+ setupMoreListener();
|
|
|
|
+ setupScrollListener();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Grab more posts if more button is clicked and append them to loop
|
|
|
|
+ */
|
|
|
|
+ function setupMoreListener() {
|
|
|
|
+ $postContainer.on( 'click', '.more-button', function( event ) {
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ $moreButton.hide();
|
|
|
|
+
|
|
|
|
+ var $setContainer = $( '<div data-page-num="' + posts.state.currentPage + '" class="post-set"></div>' );
|
|
|
|
+ posts.each( function( model ) {
|
|
|
|
+ $setContainer.append( postTemplate( { post: model.attributes, settings: settings } ) );
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $postContainer.append( $setContainer );
|
|
|
|
+
|
|
|
|
+ if ( posts.hasMore() ) {
|
|
|
|
+ posts.more().done( function() {
|
|
|
|
+ $moreButton.appendTo( $postContainer).show();
|
|
|
|
+ } );
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+});
|
|
|
|
|
|
/**
|
|
/**
|
|
* Update current url using HTML5 history API
|
|
* Update current url using HTML5 history API
|
|
@@ -57,7 +96,6 @@
|
|
|
|
|
|
/**
|
|
/**
|
|
* Determine URL for pushing new history. Props to Automattic's Jetpack plugin
|
|
* Determine URL for pushing new history. Props to Automattic's Jetpack plugin
|
|
- * for much of this code.
|
|
|
|
*/
|
|
*/
|
|
function determineURL() {
|
|
function determineURL() {
|
|
var windowTop = $( window ).scrollTop();
|
|
var windowTop = $( window ).scrollTop();
|
|
@@ -152,41 +190,4 @@
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Grab more posts if more button is clicked and append them to loop
|
|
|
|
- */
|
|
|
|
- function setupMoreListener() {
|
|
|
|
- $postContainer.on( 'click', '.more-button', function( event ) {
|
|
|
|
- event.preventDefault();
|
|
|
|
-
|
|
|
|
- $moreButton.hide();
|
|
|
|
-
|
|
|
|
- var $setContainer = $( '<div data-page-num="' + posts.state.currentPage + '" class="post-set"></div>' );
|
|
|
|
- posts.each( function( model ) {
|
|
|
|
- $setContainer.append( postTemplate( { post: model.attributes, settings: settings } ) );
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- $postContainer.append( $setContainer );
|
|
|
|
-
|
|
|
|
- if ( posts.hasMore() ) {
|
|
|
|
- posts.more().done( function() {
|
|
|
|
- $moreButton.appendTo( $postContainer).show();
|
|
|
|
- } );
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Initial posts fetch
|
|
|
|
- */
|
|
|
|
- posts.fetch( options ).done( function() {
|
|
|
|
-
|
|
|
|
- if ( posts.length > 0 ) {
|
|
|
|
- $postContainer.append( $moreButton );
|
|
|
|
-
|
|
|
|
- setupMoreListener();
|
|
|
|
- setupScrollListener();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
})( jQuery, Backbone, _, settings );
|
|
})( jQuery, Backbone, _, settings );
|