annotate docs/ref/jquery.plugin.docscomments.js @ 3158:29d7349c8a31 nullege-examples

Update example search to use Nullege. Google Code Search is no more.
author Thomas Kluyver <takowl@gmail.com>
date Thu, 03 Jan 2013 12:34:02 +0000
parents b3e367b1eca6
children
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 /*
2255
b3e367b1eca6 some style fixes for doc comments
Rene Dudfield <renesd@gmail.com>
parents: 2254
diff changeset
5 - fix comment addition for module level comment.
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
6 - 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
7 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
8 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
9 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
10 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
11 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
12 */
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
13
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
14 var _comments = {};
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
15
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
16 $.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
17 //console.log(data);
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
18
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
19 // newest comment first.
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
20 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
21 var x = a.datetimeon;
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
22 var y = b.datetimeon;
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
23 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
24 }
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
25
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
26 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
27 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
28 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
29 _comments[link] = [];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
30 }
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
31 _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
32 _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
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
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
36 var getComments = function (link) {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
37 return _comments[link];
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
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
40 var searchButtonHtml = [
3158
29d7349c8a31 Update example search to use Nullege.
Thomas Kluyver <takowl@gmail.com>
parents: 2255
diff changeset
41 '<form action="http://nullege.com/codes/search" class="addcomment"><input type="hidden" value="',
29d7349c8a31 Update example search to use Nullege.
Thomas Kluyver <takowl@gmail.com>
parents: 2255
diff changeset
42 '" name="cq"><input type="submit" value="Search examples for ',
2252
2d8f88a602e5 Fixed up the search button label.
Rene Dudfield <renesd@gmail.com>
parents: 2251
diff changeset
43 '"></form>'
2237
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
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
46 var addCommentHtml = [
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
47 '<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
48 '" 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
49 ];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
50 var showCommentHtml = [
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
51 '<a href="#comment_',
2250
d7e5f2ab5dcc Styled the comment buttons for the docs.
Rene Dudfield <renesd@gmail.com>
parents: 2237
diff changeset
52 '" 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
53 '</a><article id="comment_',
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
54 '" 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
55 ];
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
56 var commentPartHtml = [
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
57 '<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
58 '</header>',
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
59 '<pre class="commentContent">',
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
60 '</pre></section>'
2237
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
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
63 $('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
64 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
65 if (typeof link === "undefined") {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
66 return;
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
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
69 // Add "search internet for source code" buttons.
2252
2d8f88a602e5 Fixed up the search button label.
Rene Dudfield <renesd@gmail.com>
parents: 2251
diff changeset
70 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
71 $(el).next().append(searchButton);
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
72
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
73 // Add show comments buttons.
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
74 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
75
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
76 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
77 $(el).next().append(addCommentButton);
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
78
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
79 if(typeof comments === "undefined") {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
80 } else {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
81 // show comment button.
2251
f23548af1cf3 comment out some console.log calls.
Rene Dudfield <renesd@gmail.com>
parents: 2250
diff changeset
82 //console.log(link)
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
83 var $showCommentButton = $([showCommentHtml[0],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
84 link.replace(/\./g, "_"),
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
85 showCommentHtml[1],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
86 comments.length,
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
87 showCommentHtml[2],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
88 link.replace(/\./g, "_"),
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
89 showCommentHtml[3]
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
90 ].join(""));
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
91 $(el).next().append($showCommentButton);
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
92
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
93 $showCommentButton.click(function () {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
94 //console.log('asdf')
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
95 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
96 if (!$commentSection.hasClass('hidden')) {
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
97 // 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
98 return;
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
99 }
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
100 $commentSection.removeClass("hidden");
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
101 $.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
102 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
103 // date + user
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
104 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
105 if (userName == null) {
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
106 userName = 'Anonymous';
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
107 }
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
108 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
109 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
110
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
111 var $commentPart = $([commentPartHtml[0],
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
112 commentHeading,
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
113 commentPartHtml[1],
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
114 commentPartHtml[2],
2237
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
115 commentContent,
2253
8362fd4de9d3 Fixed a number of bugs in the doc commenting system.
Rene Dudfield <renesd@gmail.com>
parents: 2252
diff changeset
116 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
117 $commentSection.append($commentPart);
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
93cd207f3ff8 Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
131 });