aboutsummaryrefslogtreecommitdiff
path: root/exampleData/trac-new-ticket/New Ticket_files/threaded_comments.js
diff options
context:
space:
mode:
Diffstat (limited to 'exampleData/trac-new-ticket/New Ticket_files/threaded_comments.js')
-rw-r--r--exampleData/trac-new-ticket/New Ticket_files/threaded_comments.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/exampleData/trac-new-ticket/New Ticket_files/threaded_comments.js b/exampleData/trac-new-ticket/New Ticket_files/threaded_comments.js
new file mode 100644
index 0000000..479df0c
--- /dev/null
+++ b/exampleData/trac-new-ticket/New Ticket_files/threaded_comments.js
@@ -0,0 +1,100 @@
+/* Threaded ticket comments
+ ========================
+
+ See the #prefs form in ticket.html.
+
+ We have three mutually exclusive orders, 'newest' first, 'oldest'
+ first and 'threaded'. In addition, changes without comments can be
+ filtered out.
+
+ When switching to 'threaded', the changes without comments must be
+ shown again as they can also have a follow-up. After appending
+ eventual children, they must be hidden again and `:has(.comment)`
+ will now take into account the threaded comments in
+ children. Likewise, when switching away from 'threaded' to a linear
+ order, the changes without comments need to be hidden again.
+ */
+jQuery(document).ready(function($){
+ var comments = null;
+ var order = null;
+ var form = $("#prefs");
+
+ var commentsOnly = $("#trac-comments-only-toggle");
+ var applyCommentsOnly = function() {
+ if (commentsOnly.attr('checked')) {
+ $("ul.changes").hide();
+ $("div.change:not(:has(.comment))").hide();
+ } else {
+ $("ul.changes").show();
+ $("div.change:not(:has(.comment))").show();
+ }
+ };
+
+ var applyOrder = function() {
+ var commentsOnlyChecked = commentsOnly.attr('checked');
+ if (commentsOnlyChecked) {
+ commentsOnly.attr("checked", false);
+ applyCommentsOnly();
+ }
+ order = $("input[name='trac-comments-order']:checked").val();
+ if (order == 'newest') {
+ $("#changelog").append($("div.change").get().reverse());
+ } else if (order == 'threaded') {
+ comments = $("div.change");
+ comments.each(function() {
+ var children = $("a.follow-up", this).map(function() {
+ var cnum = $(this).attr("href").replace('#comment:', '');
+ return $('[id^="trac-change-' + cnum + '-"]').get(0);
+ });
+ if (children.length) {
+ var ul = $('<ul class="children"></ul>').appendTo(this);
+ children.appendTo(ul).wrap('<li class="child">');
+ }
+ });
+ }
+ if (commentsOnlyChecked) {
+ commentsOnly.attr("checked", true);
+ applyCommentsOnly();
+ }
+ };
+ var unapplyOrder = function() {
+ if (order == 'newest') {
+ $("#changelog").append($("div.change").get().reverse());
+ } else if (order == 'threaded') {
+ if (comments) {
+ $("#changelog").append(comments);
+ $("#changelog ul.children").remove();
+ }
+ }
+ };
+
+ if ($("a.follow-up").length)
+ $('#trac-threaded-toggle').show();
+ else if (comments_prefs.comments_order == 'threaded')
+ comments_prefs.comments_order = 'oldest'
+
+ $("input[name='trac-comments-order']")
+ .filter("[value=" + comments_prefs.comments_order + "]")
+ .attr('checked', 'checked');
+ applyOrder();
+ $("input[name='trac-comments-order']").change(function() {
+ unapplyOrder();
+ applyOrder();
+ $.ajax({ url: form.attr('action'), type: 'POST', data: {
+ save_prefs: true,
+ ticket_comments_order: order,
+ __FORM_TOKEN: form_token,
+ }, dataType: 'text' });
+ });
+
+ commentsOnly.attr('checked', comments_prefs.comments_only != 'false');
+ applyCommentsOnly();
+ commentsOnly.click(function() {
+ applyCommentsOnly();
+ $.ajax({ url: form.attr('action'), type: 'POST', data: {
+ save_prefs: true,
+ ticket_comments_only: commentsOnly.attr('checked'),
+ __FORM_TOKEN: form_token,
+ }, dataType: 'text' });
+ });
+});