CommentBox for SharePoint


13.08.2011 v1.2 released with these changes to the argObj:

  • paging: Use this in conjunction with the next parameter to set the number of top level comments to display initially.
  • topLevelCommentsLimit: The number of top level comments to display initially.
  • showMoreCommentsText: If there are more comments, this text is used for the link to show the rest of the comments.
  • sortAscending: true or false. Used to control the order of the comments.
  • commentFormVisible: true or false. Used to have the comment box expanded or collapsed initially.

There are changes to these files:

  • CommentBox.js
  • CommentBox.css

And the CEWP-code. See the CEWP-code section below for details.


17.07.2011 v1.1 released with these changes:

  • Anonymous users can read comments, but must sign in to post.
  • Added new parameter “loadLiveProfile” to the CEWP argObj. This defines whether or not to load the profile image and email from the user profile, or to use the values stored in the comment. This will automatically be set to false for anonymous users. To accompany this change i have added some new fields to the configuration list (these will be automatically created when submitting the first comment), and changed the parameters “newCommentText” and “replyText” from string to array.

There are changes to these files:

  • CommentBox.js
  • spjs-webservices.js

And to the CEWP-code.


I got this request from Brett:

Hi Alexander,

Got an awesome request for your mad skills.
Are you able to provide a Javascript/JQuery code for a Comments Box Web Part? So it can be added to any page, list or library?

I’m thinking you could set it like the Poll web part, where the Admin can specify the ID Name for each Comments Web Part instance, which will allow the user comments be allocated to the correct web part.

So it would function exactly like the Comments Web Part in a Blog Site, using the authenticated user credentials and/or anonymous comments if you desire.

There are a few Posts mentioning DVWP’s and SP Designer but I’m hoping to use a Javascript based solution.

I’ve looked everywhere for this function and closest I found was this Post.

http://devgrow.com/simple-threaded-comments-with-jcollapsible/

Many thanks for your time and efforts,

Brett


I thought this would be a useful solution for many users – myself included. It’s not very complicated as all comments are stored in a single list – identified by the pages relative URL.

Of course – as i started building – i incorporated this and that, an all of a sudden i had myself a full featured, multi level comment solution.

Sample thread:

IMG

New comment – plain text:

IMG

New comment – Rich text:

IMG

List of features

  • Supports both SharePoint 2007 and SharePoint 2010
  • Tested in IE7, IE9, Safari 5.0.5 for Windows, Firefox 5.0 and Google Chrome 12.0.742.112
  • Multi level comments
  • You can collapse top level threads
  • Rich text or plain text comments
  • Option to allow the authors to edit their comments
  • Option to let specific users act as “moderators”
  • Can be used in multiple locations within the site as each instance is identified by the relative URL of the page
  • Simple “drop in CEWP-setup”
  • On list holds all comments for all instances within the site
  • This list that holds the comments is automatically created
  • Layout customizable trough separate css-file
  • And more…

How to use

This solution is designed to be put in a CEWP where you want to use it. You will have to download all the files from the download section to a local folder/library where all users have read access, and change the <script src=”… in the CEWP code to reflect your local path.

CEWP code example

<div id="myCommentBox"></div>
<link rel="stylesheet" href="/test/EMSKJS/CommentBox/CommentBox.css">
<script type="text/javascript" src="/test/EMSKJS/CommentBox/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/test/EMSKJS/CommentBox/CommentBox.js"></script>
<script type="text/javascript" src="/test/EMSKJS/CommentBox/spjs-webservices.js"></script>
<script type="text/javascript" src="/test/EMSKJS/CommentBox/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">

var pageID = location.pathname+"?ID="+GetUrlKeyValue('ID');
var argObj = {pageID:pageID,
			 containerID:'myCommentBox',
			 containerWidth:600,
			 replyLevels:2,
			 threadInitiallyCollapsed:false,
			 commentIndent:40,			 
			 commentBoxHeight:100,
			 showProfileImage:true,
			 createdByPrefix:'Posted by ',
			 createdPrefix:' on ',
			 modifiedPrefix:'- Modified: ',
			 modifiedByPrefix:' by ',
			 showUserEmail:true,
			 authorCanEdit:true,
			 editText:'Edit',			 
			 commentBoxRTE:false,
			 expandThread:"<span title='Expand thread'><img style='vertical-align:text-bottom' src='/_layouts/images/tpmax2.gif'  border='0'>&nbsp;Expand</span>",
			 collapseThread:"<span title='Collapse thread'><img style='vertical-align:text-bottom' src='/_layouts/images/tpmin2.gif' border='0'>&nbsp;Collapse</span>",
			 newCommentText:['Leave comment','You must sign in to comment'],
			 replyText:['Reply','<span title=\"You must be signed in to leave replies\">Sign in</span>'],			 
			 submitText:'Submit comment',
			 canceImgHover:"Cancel",
			 deleteThreadText:'Delete comment',
			 moderateText:'Moderate',
			 moderatorID:['15','27'],
			 loadLiveProfile:true,
		 	 paging:false,
			 topLevelCommentsLimit:25,
			 showMoreCommentsText:"More comments",
			 sortAscending:true,
			 commentFormVisible:true
			 };

init_getComments(argObj);
</script>

Note to SharePoint 2010 users:
Add this code to a text file and put it in a document library, then use the content link option on the CEWP to link to this code. This is necessary to overcome a “bug” in the CEWP handling when editing a SP2010 page. If you put a script that generates HTML directly into a CEWP, the HTML is accumulated when editing the page.

This tip is also recommended for SharePoint 2007 users, but is not absolutely necessary.

Argument object parameters

  • pageID: The identifier for the unique instance – see separate description below.
  • containerID: The container where the comments are inserted – see separate description below.
  • containerWidth: Width in pixels.
  • replyLevels: The number of nested levels.
  • threadInitiallyCollapsed: true or false to indicate whether the threads are initially collapsed.
  • commentIndent: The number of pixels to indent each nested level of comments.
  • commentBoxHeight: The textbox (for new comments or reply) height in pixels.
  • showProfileImage: true or false to indicate whether or not to display the profile image from the SharePoint user profile.
  • createdByPrefix: The text before the user name of the author.
  • createdPrefix: The text between the author name and the date/time for when the comment is created.
  • modifiedPrefix: The text before the date/time for when the comment is modified.
  • modifiedByPrefix: The text before the name of the editor.
  • showUserEmail: true or false to indicate whether to show the email for the author.
  • authorCanEdit: true or false to indicate whether the author can edit his or hers own comments.
  • editText: The text on the “Edit item link”.
  • commentBoxRTE: true or false to indicate whether to use the TinyMCE rich text editor – see separate description below.
  • expandThread: The text/image of the “Expand thread” link.
  • collapseThread: The text/image of the “Collapse thread” link.
  • newCommentText: Array with the text on the “Leave comment” link for both authenticated and unauthenticated users.
  • replyText: Array with the text on the “Reply” link for both authenticated and unauthenticated users.
  • submitText: The text on the “Submit comment button”.
  • canceImgHover: The mouseover text on the “Cancel comment image”
  • deleteThreadText: The text on the “Delete comment” link.
  • moderateText: The text on the “Moderate item link”.
  • moderatorID: An array of the user ID’s (as string) for the moderators.
  • loadLiveProfile: true or false to indicate whether to load the profile image and email from the user profile, or to use the values stored in the comment.

New in v1.2

  • paging: Use this in conjunction with the next parameter to set the number of top level comments to display initially.
  • topLevelCommentsLimit: The number of top level comments to display initially.
  • showMoreCommentsText: If there are more comments, this text is used for the link to show the rest of the comments.
  • sortAscending: true or false. Used to control the order of the comments.
  • commentFormVisible: true or false. Used to have the comment box expanded or collapsed initially.

Details on “pageID”
For ordinary aspx-pages, use

location.pathname

When using in DispForm/EditForm, use

location.pathname+"?ID="+GetUrlKeyValue('ID')

Details on “containerID”

You can supply a placeholder in the page with the ID corresponding with the parameter “containerID” from the function call. You will want to do this to control the placement of the container, or to supply some custom settings (style or class). If you do not supply a container, it will be created automatically by the script.

Details on “commentBoxRTE”

TinyMCE – Javascript WYSIWYG Editor is a platform independent web based Javascript HTML WYSIWYG editor control released as Open Source under LGPL by Moxiecode Systems AB.

You can change the buttons and plugins for the TinyMCE by modifying the function “init_MCE” at the bottom of the file “CommentBox.js”. Refer the official site for details.

SharePoint 2010 users:
The TinyMCE solution has to be modified to change all “htm” files (and the references in the scripts) to “aspx” as the built in security feature in SharePoint 2010 does not let you open htm-files unless you change the “Browser file handling” from “Strict” to “Permissive”.

I have modified the files used in the default setup for the CommentBox solution. If you change the setup to include more plugins you must change the appropriate files. The modified package can be found in the download section.

Download

You find the files here

Copyright and disclaimer


Please let me know if you find any bugs.
Alexander

If you use this solution, please consider donating a few dollars to keep me motivated.


Donate

76 Responses to “CommentBox for SharePoint”

  1. Claudia Mulder Says:

    Hi Alexander, thanks for your reply. This is probably dumb question but where do the numbers ’15′,’27′ refer to? If these refer to SP user ID’s where can I find that info? I tried my SP user name but apparently that won’t do the trick. Sorry to bother you with this.
    Claudia

    • Alexander Bautz Says:

      Hi,
      Go to the “People and groups” list and either bring the ID column into the view, or click a user and look at the URL for the text “ID=XX”.

      Alexander

  2. QMKevin Says:

    HI Alex. I’m checking this out and ootb the functionality is great! I do have a couple of questions though:

    1) In the request from Brett he mentioned allowing comments from ‘anonymous comments if you desire’. My SharePoint site, which ‘m currently developing, would have public areas and private areas, and we’d like to allow comments on both types of area. For private the user just needs to be authenticated so this solution would be perfect ootb. However, for public areas we do want to allow anonymous users to leave comments and not display all those comments. The latter I can do by referencing a 2nd .css file where div.commentsRoot has ‘display:none;’, but would it be possible to adapt this solution to allow anonymous comments?

    2) relating to anonymous comments, I’m finding that while initially an anonymous visitor to my site can see the page where I add this solution (and see the ‘Sign In’ link by comments), very quickly the browser is automatically redirected to the sites sign in page. Any idea why this might happen, and where I could look to stop this redirection? Again, I do briefly see the page where this solution is used, but then I’m redirected, so presumably there’s some javascript (jQuery?) somewhere that’s doing this redirection.

    Cheers :)

    • Alexander Bautz Says:

      Hi,
      Q1: Comments from anonymous users is not supported as the solution uses webs services to post the comments. I might look into this later on, but for now it is not supported.

      Q2: The redirect happens in the function “addOrEditComment” – you could try to disable it there.

      Alexander

  3. Ram Says:

    Hi Alexander,

    Please post the steps for configure and running this commandBox solution in sp2010.

    Thanks,
    Rs

    • Alexander Bautz Says:

      Hi,
      Where exactly are you having trouble? All the steps necessary should already be in the article.

      Alexander

  4. Ram Says:

    Hi Alexander,

    Thanks for your reply.

    I have requirements “more comments” should come with paging like 1-10,10-20,etc….

    If you have idea please share with me.

    Thanks ,
    Ram

    • Alexander Bautz Says:

      Hi,
      Glad you figured out the setup.

      Regarding the paging, I cannot help you at the moment due to a heavy workload, but I’ll make a note of it and might pick it up later.

      Alexander

  5. Rebecca Says:

    Is there absolutely no way to post anonymous comments in SP 2007? I have been trying to figure this out for a couple of months now.

  6. vens Says:

    Hi Alexander,
    Here i am seeing all comments.but i want see my comments and replies only..How to solve this issue
    ?

    • Alexander Bautz Says:

      Hi,
      There is no such setting in this solution, sorry.

      Alexander

    • Mario Says:

      Hello Alexander,

      Great product.
      As an addition we would appreciate “Audience” targeting. To make the comment (and replies) available to a certain sharepoint group(s).
      If you would include a “view” property where “author” or “Audience” equals current user the above request would also be possible.

      Kind regards,
      Mario

    • Mario Says:

      Hello Alexander,

      After playing with the webpart I think my comment above is not really adding value. The strength of the CommentBox is that you put it on a page / listform where certain people/groups have access and only those can read/reply the comments listed there.
      One thing I think might add value is the possibility to “archive” comments which could replace the “topLevelCommentsLimit”.
      So instead of having a fixed limit you could hide archived comments.

      Kind regards,
      Mario

    • Alexander Bautz Says:

      Hi,
      I’ll make a note of your request, but I’m a bit swamped with requests and cannot manage to answer them all. I therefore cannot guarantee that it will be done.

      Alexander

  7. Eric Nash (@SharePointEric) Says:

    Another awesome solution! I’m struggling with one modification that I’m trying to make, maybe you or another commenter can help. Using this on a (MOSS) doc library I have a requirement (related to alerting) to show the name of the document on which the comment was left in each item in the CommentBox list.

    I know that I can see the ID of the library item in the Title column and if I could parse out the ID from that then I could fetch the Name of the document with SPD workflow but I can’t seem to work out a calculation like “substring-after” in a calculated column or in an SPD workflow action. Any thoughts?

    -Eric

    • Alexander Bautz Says:

      Hi,
      Sorry for the late reply. I think you could do this using a calculated column in the “Comment box list”. Create a new calculated column with this formula:

      =RIGHT(Title,LEN(Title)-FIND("=",Title))
      

      This column should now hold the ID of the item the comment was made on.

      Alexander

  8. Mario Says:

    Hello Alexander,

    sortAscending:false AND paging:true RESULTS in only “More comments”.
    No comments are directly visible.
    I would expect the same effect as with sortAscending:true

    Kind regards,
    Mario

  9. Substring-after or similar to extract ID from a URL? | Q&A System Says:

    [...] utilizing a script-based option to include a Comment Box to dispform.aspx in an exceptionally MOSS document library. The comments reside in an exceptionally [...]

  10. sharepointranger Says:

    I like the comment box and would like to use on our Intranet. We are using SharePoint 2007 and building a blog for the IT department. I would like to have a comment box which will have the ‘Comment Policy’ which users will have to read and agree. I would like to have ‘Yes & No’ radio buttons and a Title on the comment box. Can you help me on this issue?
    Thanks

    • Alexander Bautz Says:

      Hi,
      Sorry for the late answer. I’m afraid I do not have time to help you modify the solution. It is possible, but summer is approaching and i have so many other projects…

      If you could settle with a description text below the textarea reading something like “By answering you agree to the comment policy (link)”, you could get away much easier. Let me know if you would like to go with this solution.

      Alexander

  11. Claudia Mulder Says:

    Hi Alexander, we use the Commentbox on our intranet, and it works really great! 2 questions tho… I noticed a lot of people don’t understand how the Reply works; I think the fact that the Reply link only appears on mouse over is part of the problem. Therefore, I would like to show the Reply option permanently. Can I change this in the code of the JS file?
    Another thing is, it would be really cool if comments could be posted to a social platform, in our case, to Yammer. This way, discussions will be more transparent and reach a larger group.
    Just a thought… but if it is at all possible, it would be fantastic! :)
    Thanks for all the great work, Claudia.

    • Alexander Bautz Says:

      Hi,
      Glad you like the solution :-)
      To show the “Reply” text all times, add this css to the file “CommentBox.css”:

      td.commentReply a{
      	display:inline !important;	
      }
      

      I cannot help you posting to a social platform though.

      Alexander

  12. Prashant GANESH Says:

    Looks like a great solution. I m going to try this one out.

  13. Alex Says:

    Hi Alexander,

    I have a need to be able to post into the backend Sharepoint list from a different site in Sharepoint, that is not in the same farm – do you know if this is possible please, and if so, any ideas on how this can be achieved?

    Thanks,
    Alex.

  14. Jørgen Says:

    Hey Alexander!
    Great solution! I have tried it out in SharePoint Online. There is just some errors. The first is really not an error but a configuration thing, remember to put the mysite as a local intranett site (it is to see the picture of the person posting a comment). The second error that I saw was the limits of comments is set to 25 comments. When I tried this, i posted 30 comments and every comment was visible. Is it me that is doing it wrong? Or can I set the limit somewhere else?

    • Alexander Bautz Says:

      Hi,
      The limit is for top level comments – answers are not counted. Is this the case?

      Alexander

    • Jørgen Says:

      My bad, it was not a technical problem, but a human. Have a nice day. And you really have skills with Javascript and SharePoint!

  15. oman Says:

    hi alex….

    thanks for this awesome webpart…. :-)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 435 other followers