FriendsOfSymfony/FOSCommentBundle — pull request #273 by XWB (2012-11-13 15:30:31+00:00)
Title: Add javascript sorter option

The `FOSCommentBundle` has the possibility to sort the comments by date (asc/desc), but the corresponding javascript lacks support for this feature. I suggest adding a variable `fos_comment_sorter` which will be pickep up by the `getThreadComments` method.

Secondly, we need to call a custom method after the comments are loaded to bind some events. For this I added a `fos_comment_thread_load_callback` variable.

To give an example what you could do with this:

1) Make you setup
```
var fos_comment_thread_id = 'a_unique_identifier_for_the_thread';
var fos_comment_sorter = 'date_asc'; // fetch default from config
// etc
```

2) Create a HTML select box with 2 sorting options.
```

ASC

Desc

```

3) Define your callback function
```
var fos_comment_thread_load_callback = function() {
$('#sorter').on('change', function() {
// Set the new sorter
window.fos_comment_sorter = this.value;

// Reload the comments
window.fos.Comment.getThreadComments(window.fos_comment_thread_id);
});
}
```

That's all!