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