This file contains 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
/** | |
* Register the necessary fields to display post information correctly | |
*/ | |
add_action( 'rest_api_init', 'theme_slug_register_rest_fields' ); | |
function theme_slug_register_rest_fields() { | |
register_rest_field( 'post', | |
'comments', | |
array( | |
'get_callback' => 'theme_slug_get_comments', |
This file contains 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
.controller('SinglePost', ['$scope', '$http', '$stateParams', 'Comments', 'SortComments', function ($scope, $http, $stateParams, Comments, SortComments) { | |
$http.get(myLocalized.api_url + 'posts?slug=' + $stateParams.slug + '&_embed').success(function(res){ | |
$scope.post.comments = SortComments.arrangeComments( $scope.post.comments ); | |
$scope.numComments = $scope.post.comments.length; | |
}); | |
}]) |
This file contains 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
.service('SortComments', function () { | |
}) |
This file contains 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
.service('SortComments', function () { | |
this.getCommentById = function ( commentID, comments_list ) { | |
} | |
this.getCommentDepth = function ( theComment, comments_list ) { | |
} | |
this.arrangeComments = function ( commentsList ) { | |
} | |
}) |
This file contains 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
this.getCommentById = function ( commentID, comments_list ) { | |
for ( j = 0; j < comments_list.length; j++ ) { | |
if ( comments_list[j].comment_ID == commentID ) { | |
return comments_list[j]; | |
} | |
} | |
} |
This file contains 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
this.getCommentDepth = function ( theComment, comments_list ) { | |
var depthLevel = 0; | |
while ( theComment.comment_parent > 0 ) { | |
theComment = this.getCommentById( theComment.comment_parent, comments_list ); | |
depthLevel++; | |
} | |
return depthLevel; | |
} |
This file contains 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
this.arrangeComments = function ( commentsList ) { | |
var maxDepth = 0; | |
for ( i = commentsList.length - 1; i >= 0; i-- ) { | |
if ( commentsList[i].comment_approved != 1 ) { | |
commentsList.splice( i, 1 ); | |
} | |
} | |
for ( i = 0; i | |
< commentsList.length; i += 1 ) { | |
commentsList[i].comment_children = []; |
This file contains 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
.directive('collection', function () { | |
return { | |
restrict: "E", | |
replace: true, | |
scope: { | |
collection: '=' | |
}, | |
template: "<ul><member ng-repeat='member in collection' member='member'></member></ul>" | |
} | |
}) |
This file contains 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
.directive('member', function ($compile) { | |
return { | |
restrict: "E", | |
replace: true, | |
scope: { | |
member: '=' | |
}, | |
templateUrl: myLocalized.partials + 'comments.html', | |
link: function (scope, element, attrs) { | |
var collectionSt = '<collection collection="member.comment_children"></collection>'; |
This file contains 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
<li id="comment-{{member.comment_ID}}" class="comment comment-{{member.comment_ID}} {{member.comment_parent ? 'child-comment post-parent-' + member.comment_parent : ''}}"> | |
<header class="comment-header"> | |
<h4 class="comment-name">{{member.comment_author}}</h4> | |
<h5 class="comment-date">{{ member.comment_date | date:"h:mm a" }} on {{ member.comment_date | date:"MMMM dd, yyyy" }}</h5> | |
</header> | |
<div class="comment-content" ng-bind-html="member.comment_content | unsafe"></div> | |
<footer class="reply"> | |
<button id="reply-{{member.comment_ID}}" class="respond-to-comment button" onclick="replyToComment(this.id)">{{translations.reply}}</button> | |
</footer> | |
</li> |
OlderNewer