Commits

Mike Cannon-Brookes committed bcbea9a

Initial commit of Confluence inline reply extension. Works on pages and blog posts, whether you can edit or not.

  • Participants
  • Tags 1_0

Comments (0)

Files changed (2)

File atlassian-extension.json

+{
+	"key": 			"inlinereply",
+	"name":			"Inline Reply",
+	"description":	"Inline replies in Confluence comments",
+	"version":		"2",
+	
+	"vendor": {	"name": "Mike Cannon-Brookes",
+			     "url": "http://example.com/extension-homepage.html",
+		       "email": "mike@atlassian.com" }
+}

File js/inlinereply/main.js

+/**
+ * The main module
+ *
+ * @context page, blogpost
+ */
+var $ = require('speakeasy/jquery').jQuery;
+
+function setupInlineReplies() {
+	jQuery("li.action-reply-comment a").each(function(i) {  
+	    commentId = jQuery(this).attr('id');
+		commentId = commentId.substring(commentId.indexOf('ment-') + 5);
+
+		jQuery(this).parent().after("<li><input type='text' name='" + commentId + "' style='font-size: 0.8em; color: #ccc;' size='50' class='inlinereply' value='Quick reply...'></li>");
+	});
+
+	jQuery('.inlinereply').click(function() { 
+	    el = jQuery(this);
+	    el.val(''); 
+	    el.css('color', 'black');
+
+	    el.keypress(function(e) {
+	        if(e.which == 13 || e.which == 10) {
+	            jQuery(this).blur();
+				postComment(this);
+	        }
+	    });
+	});
+}
+
+// is there a more consistent way to do this? Info link should always be visible AFAIK
+function getPageId() {
+	infoLink = jQuery('#view-page-info-link').attr('href');
+	return infoLink.substring(infoLink.indexOf('=') + 1);
+}
+
+function postComment(o) {
+	el = jQuery(o);
+	el.disable();
+
+    commentText = el.val();
+    parentId = el.attr('name')
+
+	pageId = getPageId();
+	
+	el.after('<span style="padding-left: 8px; margin-top: 4px;"><img src="https://extranet.atlassian.com/images/icons/wait.gif" text-align="absmiddle"></span>');
+	
+	AJS.safe.ajax({
+		type: 'POST',
+		url: '/pages/doaddcomment.action?pageId=' + pageId + '&parentId=' + parentId,
+		data: {'confirm': 'save', 'wysiwygContent': commentText},
+		dataType: "JSON",
+		success: function() { 
+			jQuery(o).next().remove();
+			jQuery(o).after('<div style="color: black; background-color: #dfd; border-radius: 4px; padding: 4px 8px;">Posted!</div>');
+			jQuery(o).remove();
+		}
+	});
+}
+
+$(document).ready(function() {
+	setupInlineReplies();
+	AJS.whenIType("shift+w").execute(function() { jQuery('#page-watch').click(); });
+});