Use a more consistent style in the websupport js

This commit is contained in:
Daniel Neuhäuser 2010-08-13 15:10:48 +02:00
parent 4dc41e5293
commit 1509c0d3d3

View File

@ -117,9 +117,9 @@
});
};
/**
* Create a comp function. If the user has preferences stored in
* the sortBy cookie, use those, otherwise use the default.
/*
Create a comp function. If the user has preferences stored in
the sortBy cookie, use those, otherwise use the default.
*/
function initComparator() {
var by = 'rating'; // Default to sort by rating.
@ -137,8 +137,8 @@
setComparator(by);
};
/**
* Show the comments popup window.
/*
Show the comments popup window.
*/
function show(nodeId) {
var id = nodeId.substring(1);
@ -167,8 +167,8 @@
});
};
/**
* Hide the comments popup window.
/*
Hide the comments popup window.
*/
function hide() {
$('div.popup_comment').fadeOut('fast', function() {
@ -181,9 +181,9 @@
});
};
/**
* Perform an ajax request to get comments for a node
* and insert the comments into the comments tree.
/*
Perform an ajax request to get comments for a node
and insert the comments into the comments tree.
*/
function getComments(id) {
$.ajax({
@ -200,8 +200,7 @@
ul.html('<li>No comments yet.</li>');
commentListEmpty = true;
var speed = 100;
}
else {
} else {
// If there are comments, sort them and put them in the list.
var comments = sortComments(data.comments);
var speed = data.comments.length * 100;
@ -218,8 +217,8 @@
});
};
/**
* Add a comment via ajax and insert the comment into the comment tree.
/*
Add a comment via ajax and insert the comment into the comment tree.
*/
function addComment(form) {
// Disable the form that is being submitted.
@ -231,10 +230,12 @@
type: "POST",
url: opts.addCommentURL,
dataType: 'json',
data: {node: node_id,
data: {
node: node_id,
parent: form.find('input[name="parent"]').val(),
text: form.find('textarea[name="comment"]').val(),
proposal: form.find('textarea[name="proposal"]').val()},
proposal: form.find('textarea[name="proposal"]').val()
},
success: function(data, textStatus, error) {
// Reset the form.
if (node_id) {
@ -257,9 +258,9 @@
});
};
/**
* Recursively append comments to the main comment list and children
* lists, creating the comment tree.
/*
Recursively append comments to the main comment list and children
lists, creating the comment tree.
*/
function appendComments(comments, ul) {
$.each(comments, function() {
@ -272,9 +273,9 @@
});
};
/**
* After adding a new comment, it must be inserted in the correct
* location in the comment tree.
/*
After adding a new comment, it must be inserted in the correct
location in the comment tree.
*/
function insertComment(comment) {
var div = createCommentDiv(comment);
@ -286,8 +287,7 @@
if (comment.node != null) {
var ul = $('ul#comment_ul');
var siblings = getChildren(ul);
}
else {
} else {
var ul = $('#cl' + comment.parent);
var siblings = getChildren(ul);
}
@ -398,8 +398,8 @@
textarea.slideUp('fast');
};
/**
* Handle when the user clicks on a sort by link.
/*
Handle when the user clicks on a sort by link.
*/
function handleReSort(link) {
setComparator(link.attr('id'));
@ -414,8 +414,8 @@
appendComments(comments, $('ul#comment_ul').empty());
};
/**
* Function to process a vote when a user clicks an arrow.
/*
Function to process a vote when a user clicks an arrow.
*/
function handleVote(link) {
if (!opts.voting) {
@ -426,11 +426,11 @@
var id = link.attr('id');
// If it is an unvote, the new vote value is 0,
// Otherwise it's 1 for an upvote, or -1 for a downvote.
if (id.charAt(1) == 'u')
if (id.charAt(1) == 'u') {
var value = 0;
else
} else {
var value = id.charAt(0) == 'u' ? 1 : -1;
}
// The data to be sent to the server.
var d = {
comment_id: id.substring(2),
@ -475,8 +475,8 @@
});
};
/**
* Open a reply form used to reply to an existing comment.
/*
Open a reply form used to reply to an existing comment.
*/
function openReply(id) {
// Swap out the reply link for the hide link
@ -497,8 +497,8 @@
div.slideDown('fast');
};
/**
* Close the reply form opened with openReply.
/*
Close the reply form opened with openReply.
*/
function closeReply(id) {
// Remove the reply div from the DOM.
@ -511,8 +511,8 @@
$('#rl' + id).show();
};
/**
* Recursively sort a tree of comments using the comp comparator.
/*
Recursively sort a tree of comments using the comp comparator.
*/
function sortComments(comments) {
comments.sort(comp);
@ -522,9 +522,9 @@
return comments;
};
/**
* Set comp, which is a comparator function used for sorting and
* inserting comments into the list.
/*
Set comp, which is a comparator function used for sorting and
inserting comments into the list.
*/
function setComparator(by) {
// If the first three letters are "asc", sort in ascending order
@ -532,19 +532,19 @@
if (by.substring(0,3) == 'asc') {
var i = by.substring(3);
comp = function(a, b) { return a[i] - b[i]; }
}
} else {
// Otherwise sort in descending order.
else
comp = function(a, b) { return b[by] - a[by]; }
}
// Reset link styles and format the selected sort option.
$('a.sel').attr('href', '#').removeClass('sel');
$('#' + by).removeAttr('href').addClass('sel');
};
/**
* Get the children comments from a ul. If recursive is true,
* recursively include childrens' children.
/*
Get the children comments from a ul. If recursive is true,
recursively include childrens' children.
*/
function getChildren(ul, recursive) {
var children = [];
@ -552,16 +552,15 @@
.each(function() {
var comment = $(this).data('comment');
if (recursive) {
comment.children =
getChildren($(this).find('#cl' + comment.id), true);
comment.children = getChildren($(this).find('#cl' + comment.id), true);
}
children.push(comment);
});
return children;
};
/**
* Create a div to display a comment in.
/*
Create a div to display a comment in.
*/
function createCommentDiv(comment) {
// Prettify the comment rating.
@ -594,9 +593,9 @@
return div;
}
/**
* A simple template renderer. Placeholders such as <%id%> are replaced
* by context['id']. Items are always escaped.
/*
A simple template renderer. Placeholders such as <%id%> are replaced
by context['id']. Items are always escaped.
*/
function renderTemplate(template, context) {
var esc = $('<span></span>');
@ -617,15 +616,16 @@
function showError(message) {
$('<div class="popup_error">' +
'<h1>' + message + '</h1>' +
'</div>')
'</div>'
)
.appendTo('body')
.fadeIn("slow")
.delay(2000)
.fadeOut("slow");
};
/**
* Add a link the user uses to open the comments popup.
/*
Add a link the user uses to open the comments popup.
*/
$.fn.comment = function() {
return this.each(function() {
@ -640,7 +640,8 @@
.click(function(event) {
event.preventDefault();
show($(this).parent().attr('id'));
}));
})
);
});
};