diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/ref/jquery.plugin.docscomments.js	Wed Jun 01 19:41:26 2011 +0000
@@ -0,0 +1,103 @@
+$(document).ready(function () {
+
+
+	var _comments = {};
+
+	$.getJSON("docscomments.json", function (data) {
+		//console.log(data);
+		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]);
+		}
+
+
+		var getComments = function (link) {
+			return _comments[link];
+		};
+
+		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 pygame.display.init "></form>'
+		];
+
+		var addCommentHtml = [
+			'<form action="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">Comments ',
+			'</a><div id="comment_',
+			'" class="hidden"></div>'
+		];
+		var commentPartHtml = [
+			'<div class="commentPart"><div class="commentHeading">', '</div>',
+			'<div class="commentContent">', '</div></div>',
+		]
+
+		$('dt.title').each(function (idx, el) {
+			var link = $(el).attr('id');
+			if (typeof link === "undefined") {
+				return;
+			}
+
+			// Add "search internet for source code" buttons.
+			var searchButton = $(searchButtonHtml[0] + link + searchButtonHtml[1]);
+			$(el).next().append(searchButton);
+
+			// Add show comments buttons.
+			var comments = getComments(link);
+			if(typeof comments === "undefined") {
+				var addCommentButton = $(addCommentHtml[0] + link + addCommentHtml[1]);
+				$(el).next().append(addCommentButton);
+			} else {
+				// show comment button.
+				console.log(link)
+				var $showCommentButton = $([showCommentHtml[0], 
+							  link.replace(/\./g, "_"), 
+							showCommentHtml[1],
+							comments.length,
+							showCommentHtml[2],
+							  link.replace(/\./g, "_"), 
+							showCommentHtml[3]
+							  ].join(""));
+				$(el).next().append($showCommentButton);
+
+				$showCommentButton.click(function () {
+					//console.log('asdf')
+					var $commentSection = $("#comment_" + link.replace(/\./g, "_"));
+					$commentSection.removeClass("hidden");
+					$.each(comments, function(idx) {
+						console.log(comments[idx])
+						// date + user
+						var userName = comments[idx]['user'];
+						if (userName == null) {
+							userName = 'Anonymous';
+						}
+						var commentHeading = comments[idx]['datetimeon'] + " - " + userName;
+						var commentContent= comments[idx]['content'];
+
+						var $commentPart = $([commentPartHtml[0], 
+							  commentHeading, 
+							commentPartHtml[1],
+							commentContent,
+							commentPartHtml[2]].join("\n"));
+						$commentSection.append($commentPart);
+					});
+					
+				})
+			}
+			
+		});
+
+
+
+	});
+
+
+
+
+});