Skip to content

Instantly share code, notes, and snippets.

@JMWebDevelopment
Created February 7, 2017 03:37
Show Gist options
  • Save JMWebDevelopment/79c9a20378bda67a6c40340b8f2e1e96 to your computer and use it in GitHub Desktop.
Save JMWebDevelopment/79c9a20378bda67a6c40340b8f2e1e96 to your computer and use it in GitHub Desktop.
.directive('archiveLoadMore', ['$compile', '$http', function($compile, $http) {
return {
restrict: 'E',
replace: true,
templateUrl: quotidiano.partials + 'loaded-archive-post.html',
link: function($scope, element, attrs) {
$scope.paged = 2;
$scope.loadMorePosts= function() {
jQuery('.post').each( function() {
jQuery(this).removeAttr("ng-repeat");
})
var archiveType = jQuery('.archive-template').attr('id');
url = quotidiano.api_url + '&page=' + $scope.paged;
$http.get(url).then(function(res) {
var data = res.data;
$scope.new_archive_posts = data;
$compile(element)($scope, function(cloned, $scope) {
element.parent().append(cloned);
element.parent().append(element);
});
jQuery('.post').each( function() {
jQuery(this).removeAttr("ng-repeat");
jQuery(this).addClass('removed');
})
var totalPages = res.headers( 'X-WP-Total' );
if ( $scope.paged == totalPages ) {
} else {
$scope.paged += 1;
}
})
}
}
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment