From f7dde138a05e914d4ee10586fcbbbbade0e5ab8f Mon Sep 17 00:00:00 2001 From: Edmund Wong Date: Mon, 17 May 2010 17:02:53 +0200 Subject: Bug 460799: Move JS code out of bug/comments.html.tmpl r/a=LpSolit --- js/comments.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 js/comments.js (limited to 'js') diff --git a/js/comments.js b/js/comments.js new file mode 100644 index 000000000..79bdae855 --- /dev/null +++ b/js/comments.js @@ -0,0 +1,88 @@ +/* The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is the Bugzilla Bug Tracking System. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): Frédéric Buclin + * Max Kanat-Alexander + * Edmund Wong + */ + +function updateCommentPrivacy(checkbox, id) { + var comment_elem = document.getElementById('comment_text_'+id).parentNode; + if (checkbox.checked) { + if (!comment_elem.className.match('bz_private')) { + comment_elem.className = comment_elem.className.concat(' bz_private'); + } + } + else { + comment_elem.className = + comment_elem.className.replace(/(\s*|^)bz_private(\s*|$)/, '$2'); + } +} + +/* The functions below expand and collapse comments */ + +function toggle_comment_display(link, comment_id) { + var comment = document.getElementById('comment_text_' + comment_id); + var re = new RegExp(/\bcollapsed\b/); + if (comment.className.match(re)) + expand_comment(link, comment); + else + collapse_comment(link, comment); +} + +function toggle_all_comments(action, comments_size) { + var num_comments = comments_size; + + // If for some given ID the comment doesn't exist, this doesn't mean + // there are no more comments, but that the comment is private and + // the user is not allowed to view it. + + for (var id = 0; id < num_comments; id++) { + var comment = document.getElementById('comment_text_' + id); + if (!comment) + continue; + + var link = document.getElementById('comment_link_' + id); + if (action == 'collapse') + collapse_comment(link, comment); + else + expand_comment(link, comment); + } +} + +function collapse_comment(link, comment) { + link.innerHTML = "[+]"; + link.title = "Expand the comment."; + YAHOO.util.Dom.addClass(comment, 'collapsed'); +} + +function expand_comment(link, comment) { + link.innerHTML = "[-]"; + link.title = "Collapse the comment"; + YAHOO.util.Dom.removeClass(comment, 'collapsed'); +} + +/* This way, we are sure that browsers which do not support JS + * won't display this link */ + +function addCollapseLink(count) { + document.write(' [-]<\/a> '); +} + -- cgit v1.2.3-24-g4f1b