Mercurial > pygame
annotate docs/ref/jquery.plugin.docscomments.js @ 2237:93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
the internet for source code containing the code looked at.
Still needs styling and adding a script tag to the footer, as well
as testing cross browser.
| author | Rene Dudfield <renesd@gmail.com> |
|---|---|
| date | Wed, 01 Jun 2011 19:41:26 +0000 |
| parents | |
| children | d7e5f2ab5dcc |
| 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 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
4 var _comments = {}; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
5 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
6 $.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
|
7 //console.log(data); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
8 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
|
9 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
|
10 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
|
11 _comments[link] = []; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
12 } |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
13 _comments[link].push(data[i]); |
|
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 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
16 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
17 var getComments = function (link) { |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
18 return _comments[link]; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
19 }; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
20 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
21 var searchButtonHtml = [ |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
22 '<form action="http://www.google.com/codesearch" class="addcomment"><input type="hidden" value="file:\.py$ ', |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
23 '" name="q"><input type="submit" value="Search internet source code for examples of pygame.display.init "></form>' |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
24 ]; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
25 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
26 var addCommentHtml = [ |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
27 '<form action="comment_new.php" class="addcomment"><input type="hidden" value="', |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
28 '" 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
|
29 ]; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
30 var showCommentHtml = [ |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
31 '<a href="#comment_', |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
32 '" title="show comments">Comments ', |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
33 '</a><div id="comment_', |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
34 '" class="hidden"></div>' |
|
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 commentPartHtml = [ |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
37 '<div class="commentPart"><div class="commentHeading">', '</div>', |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
38 '<div class="commentContent">', '</div></div>', |
|
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 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
41 $('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
|
42 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
|
43 if (typeof link === "undefined") { |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
44 return; |
|
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 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
47 // Add "search internet for source code" buttons. |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
48 var searchButton = $(searchButtonHtml[0] + link + searchButtonHtml[1]); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
49 $(el).next().append(searchButton); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
50 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
51 // Add show comments buttons. |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
52 var comments = getComments(link); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
53 if(typeof comments === "undefined") { |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
54 var addCommentButton = $(addCommentHtml[0] + link + addCommentHtml[1]); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
55 $(el).next().append(addCommentButton); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
56 } else { |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
57 // show comment button. |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
58 console.log(link) |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
59 var $showCommentButton = $([showCommentHtml[0], |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
60 link.replace(/\./g, "_"), |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
61 showCommentHtml[1], |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
62 comments.length, |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
63 showCommentHtml[2], |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
64 link.replace(/\./g, "_"), |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
65 showCommentHtml[3] |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
66 ].join("")); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
67 $(el).next().append($showCommentButton); |
|
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 $showCommentButton.click(function () { |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
70 //console.log('asdf') |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
71 var $commentSection = $("#comment_" + link.replace(/\./g, "_")); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
72 $commentSection.removeClass("hidden"); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
73 $.each(comments, function(idx) { |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
74 console.log(comments[idx]) |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
75 // date + user |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
76 var userName = comments[idx]['user']; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
77 if (userName == null) { |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
78 userName = 'Anonymous'; |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
79 } |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
80 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
|
81 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
|
82 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
83 var $commentPart = $([commentPartHtml[0], |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
84 commentHeading, |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
85 commentPartHtml[1], |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
86 commentContent, |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
87 commentPartHtml[2]].join("\n")); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
88 $commentSection.append($commentPart); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
89 }); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
90 |
|
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 } |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
93 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
94 }); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
95 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
96 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
97 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
98 }); |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
99 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
100 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
101 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
102 |
|
93cd207f3ff8
Adding the start of a plugin for displaying comments, and searching
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
103 }); |
