coComment has added native JSONP support. They seem to have worked out the bugs from their first implementation and I have reworked the code for my sidebar to use their system. Out of this has come two generic coCo JSON functions. One, coco_flat, takes their nested group-comments-by-article format and flattens it to one-element-per-comment with all the article and comment attributes intact:
function coco_flat(coco) {
var comments = [];
for(var i=0; i<coco.length; i++) {
for(var i2=0; i2<coco[i].comments.length; i2++) {
comments.push({
“blogID”:coco[i].blogID,
“blogTitle”:coco[i].blogTitle,
“blogURL”:coco[i].blogURL,
“blogURLCoco”:coco[i].blogURLCoco,
“articleID”:coco[i].articleID,
“articleTitle”:coco[i].articleTitle,
“articleURL”:coco[i].articleURL,
“articleURLCoco”:coco[i].articleURLCoco,
“id”:coco[i].comments[i2].id,
“author”:coco[i].comments[i2].author,
“authorURL”:coco[i].comments[i2].authorURL,
“authorAlias”:coco[i].comments[i2].authorAlias,
“comment”:coco[i].comments[i2].comment,
“commentURLCoco”:coco[i].comments[i2].commentURLCoco,
“dateISO”:coco[i].comments[i2].dateISO,
“date”:coco[i].comments[i2].date
});
}//end for cocommentResultSet[i].comments
}//end for cocommentResultSet
return comments;
}//end function coco_flat
The other, coco_compare, is for use in sorting so flattened results by date:
function coco_compare(a,b) {
if(a.date<b.date) return -1;
if(a.date>b.date) return 1;
return 0;
}//end function coco_compare
To use this function to sort a flattened array of coComment data oldest to newest call array.sort(coco_compare), and to sort by newest to oldest also call array.reverse() as well.
Here is an example piece of code putting together all that is above, an incidentally what I am using in my sidebar: