Mercurial > pygame
diff docs/ref/jquery.plugin.docscomments.js @ 2253:8362fd4de9d3
Fixed a number of bugs in the doc commenting system.
| author | Rene Dudfield <renesd@gmail.com> |
|---|---|
| date | Sun, 19 Jun 2011 16:49:28 +0000 |
| parents | 2d8f88a602e5 |
| children | f68916095ca5 |
line wrap: on
line diff
--- a/docs/ref/jquery.plugin.docscomments.js Sun Jun 19 15:44:46 2011 +0000 +++ b/docs/ref/jquery.plugin.docscomments.js Sun Jun 19 16:49:28 2011 +0000 @@ -1,16 +1,34 @@ $(document).ready(function () { + /* + - format dates in a more human readable way. + X - show user title for each post. + X - order comments by newest first. + X - prevent comments from being added multiple times. + X - add comment button to reference full url. + X - Add 'add comment' button in, even if there are comments. + */ + var _comments = {}; $.getJSON("docscomments.json", function (data) { //console.log(data); + + // newest comment first. + var sortComments = function (a,b) { + var x = a.datetimeon; + var y = b.datetimeon; + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); + } + for(var i=0; i < data.length; i+=1) { var link = data[i]['link'] if(typeof _comments[link] === "undefined") { _comments[link] = []; } _comments[link].push(data[i]); + _comments[link].sort(sortComments); } @@ -20,23 +38,25 @@ var searchButtonHtml = [ '<form action="http://www.google.com/codesearch" class="addcomment"><input type="hidden" value="file:\.py$ ', - '" name="q"><input type="submit" value="Search internet source code for examples of ', + '" name="q"><input type="submit" value="Search examples of ', '"></form>' ]; var addCommentHtml = [ - '<form action="comment_new.php" class="addcomment"><input type="hidden" value="', + '<form action="http://www.pygame.org/docs/ref/comment_new.php" class="addcomment"><input type="hidden" value="', '" name="link"><input type="submit" value="Add a Comment"></form>' ]; var showCommentHtml = [ '<a href="#comment_', '" title="show comments" class="commentButton">Comments ', - '</a><div id="comment_', - '" class="hidden"></div>' + '</a><article id="comment_', + '" class="hidden commentsArticle"></article>' ]; var commentPartHtml = [ - '<div class="commentPart"><div class="commentHeading">', '</div>', - '<div class="commentContent">', '</div></div>', + '<section class="commentPart"><header class="commentHeading">', + '</header>', + '<pre class="commentContent">', + '</pre></section>' ] $('dt.title').each(function (idx, el) { @@ -51,9 +71,11 @@ // Add show comments buttons. var comments = getComments(link); + + var addCommentButton = $(addCommentHtml[0] + link + addCommentHtml[1]); + $(el).next().append(addCommentButton); + if(typeof comments === "undefined") { - var addCommentButton = $(addCommentHtml[0] + link + addCommentHtml[1]); - $(el).next().append(addCommentButton); } else { // show comment button. //console.log(link) @@ -70,11 +92,15 @@ $showCommentButton.click(function () { //console.log('asdf') var $commentSection = $("#comment_" + link.replace(/\./g, "_")); + if (!$commentSection.hasClass('hidden')) { + // we have already loaded the comments for this part. + return; + } $commentSection.removeClass("hidden"); $.each(comments, function(idx) { - //console.log(comments[idx]) + console.log(comments[idx]) // date + user - var userName = comments[idx]['user']; + var userName = comments[idx]['user_title']; if (userName == null) { userName = 'Anonymous'; } @@ -84,14 +110,14 @@ var $commentPart = $([commentPartHtml[0], commentHeading, commentPartHtml[1], + commentPartHtml[2], commentContent, - commentPartHtml[2]].join("\n")); + commentPartHtml[3]].join("\n")); $commentSection.append($commentPart); }); }) } - });
