annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
1 $(document).ready(function () {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
2
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
3
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
4 /*
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
5 - format dates in a more human readable way.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
6 X - show user title for each post.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
7 X - order comments by newest first.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
8 X - prevent comments from being added multiple times.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
9 X - add comment button to reference full url.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
10 X - Add 'add comment' button in, even if there are comments.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
11 */
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
12
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
13 var _comments = {};
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
14
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
15 $.getJSON("docscomments.json", function (data) {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
16 //console.log(data);
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
17
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
18 // newest comment first.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
19 var sortComments = function (a,b) {
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
20 var x = a.datetimeon;
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
21 var y = b.datetimeon;
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
22 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
23 }
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
24
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
25 for(var i=0; i < data.length; i+=1) {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
26 var link = data[i]['link']
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
27 if(typeof _comments[link] === "undefined") {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
28 _comments[link] = [];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
29 }
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
30 _comments[link].push(data[i]);
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
31 _comments[link].sort(sortComments);
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
32 }
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
33
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
34
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
35 var getComments = function (link) {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
36 return _comments[link];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
37 };
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
38
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
39 var searchButtonHtml = [
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
40 '<form action="http://www.google.com/codesearch" class="addcomment"><input type="hidden" value="file:\.py$ ',
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
41 '" name="q"><input type="submit" value="Search examples of ',
2252
2d8f88a602e5 Fixed up the search button label.
Rene Dudfield <renesd@gmail.com>
parents: 2251
diff changeset
42 '"></form>'
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
43 ];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
44
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
45 var addCommentHtml = [
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
46 '<form action="http://www.pygame.org/docs/ref/comment_new.php" class="addcomment"><input type="hidden" value="',
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
47 '" name="link"><input type="submit" value="Add a Comment"></form>'
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
48 ];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
49 var showCommentHtml = [
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
50 '<a href="#comment_',
2250
d7e5f2ab5dcc Styled the comment buttons for the docs.
Rene Dudfield <renesd@gmail.com>
parents: 2237
diff changeset
51 '" title="show comments" class="commentButton">Comments ',
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
52 '</a><article id="comment_',
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
53 '" class="hidden commentsArticle"></article>'
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
54 ];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
55 var commentPartHtml = [
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
56 '<section class="commentPart"><header class="commentHeading">',
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
57 '</header>',
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
58 '<pre class="commentContent">',
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
59 '</pre></section>'
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
60 ]
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
61
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
62 $('dt.title').each(function (idx, el) {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
63 var link = $(el).attr('id');
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
64 if (typeof link === "undefined") {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
65 return;
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
66 }
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
67
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
68 // Add "search internet for source code" buttons.
2252
2d8f88a602e5 Fixed up the search button label.
Rene Dudfield <renesd@gmail.com>
parents: 2251
diff changeset
69 var searchButton = $(searchButtonHtml[0] + link + searchButtonHtml[1] + link + searchButtonHtml[2]);
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
70 $(el).next().append(searchButton);
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
71
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
72 // Add show comments buttons.
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
73 var comments = getComments(link);
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
74
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
75 var addCommentButton = $(addCommentHtml[0] + link + addCommentHtml[1]);
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
76 $(el).next().append(addCommentButton);
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
77
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
78 if(typeof comments === "undefined") {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
79 } else {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
80 // show comment button.
2251
f23548af1cf3 comment out some console.log calls.
Rene Dudfield <renesd@gmail.com>
parents: 2250
diff changeset
81 //console.log(link)
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
82 var $showCommentButton = $([showCommentHtml[0],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
83 link.replace(/\./g, "_"),
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
84 showCommentHtml[1],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
85 comments.length,
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
86 showCommentHtml[2],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
87 link.replace(/\./g, "_"),
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
88 showCommentHtml[3]
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
89 ].join(""));
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
90 $(el).next().append($showCommentButton);
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
91
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
92 $showCommentButton.click(function () {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
93 //console.log('asdf')
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
94 var $commentSection = $("#comment_" + link.replace(/\./g, "_"));
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
95 if (!$commentSection.hasClass('hidden')) {
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
96 // we have already loaded the comments for this part.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
97 return;
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
98 }
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
99 $commentSection.removeClass("hidden");
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
100 $.each(comments, function(idx) {
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
101 console.log(comments[idx])
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
102 // date + user
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
103 var userName = comments[idx]['user_title'];
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
104 if (userName == null) {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
105 userName = 'Anonymous';
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
106 }
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
107 var commentHeading = comments[idx]['datetimeon'] + " - " + userName;
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
108 var commentContent= comments[idx]['content'];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
109
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
110 var $commentPart = $([commentPartHtml[0],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
111 commentHeading,
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
112 commentPartHtml[1],
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
113 commentPartHtml[2],
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
114 commentContent,
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
115 commentPartHtml[3]].join("\n"));
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
116 $commentSection.append($commentPart);
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
117 });
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
118
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
119 })
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
120 }
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
121 });
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
122
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
123
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
124
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
125 });
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
126
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
127
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
128
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
129
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
130 });