The Javascript library of choice for implementing commenting in your web app

Overview

jquery-comments

jquery-comments is a jQuery plugin for implementing an out-of-the-box commenting solution to any web application with an existing backend. It provides all the UI functionalities and ties them to callbacks that let you easily define what you want to do with the data. The library is highly customizable and very easy to integrate thanks to a wide variety of settings.

Screenshot of jquery-comments

Features

  • Commenting
  • Replying (nested comments)
  • Editing comments
  • Deleting comments
  • Upvoting comments
  • Uploading attachments
  • Hashtags
  • Pinging users
  • Enabling/disabling functionalities
  • Localization
  • Time formatting
  • Field mappings
  • Callbacks
  • Fully responsive and mobile compatible
  • Miscellaneous settings

Demo

http://viima.github.io/jquery-comments/demo/

Quick start

1) Add the following to your HTML file

<link rel="stylesheet" type="text/css" href="css/jquery-comments.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-comments.js"></script>

2) Initialize the library

$('#comments-container').comments({
    getComments: function(success, error) {
        var commentsArray = [{
            id: 1,
            created: '2015-10-01',
            content: 'Lorem ipsum dolort sit amet',
            fullname: 'Simon Powell',
            upvote_count: 2,
            user_has_upvoted: false
        }];
        success(commentsArray);
    }
});

If you are not using Font Awesome for icons, you should replace the icons with custom images by overriding following options when initializing the library:

spinnerIconURL: '',
noCommentsIconURL: '',
closeIconURL: '',
upvoteIconURL: '',      // Only if upvoting is enabled
replyIconURL: '',       // Only if replying is enabled
uploadIconURL: '',      // Only if attachments are enabled
attachmentIconURL: '',  // Only if attachments are enabled

Dependencies

  • jQuery >= 1.9.0
  • Font Awesome (optional)
  • jquery-textcomplete (optional)

Documentation

http://viima.github.io/jquery-comments

Maintainers

Browser support

IE9+ and all modern browsers

Copyright and license

Code and documentation copyright 2020 Viima Solutions Oy. Code released under the MIT license.

Comments
  • support for multiple comments on a single page

    support for multiple comments on a single page

    We are working to implement this plugin on several sites through a framework. We provide the script automatically and it is included on the site. The include a div with a 'framework-comments' class and an id. We then do this: $('.framework-comments').each(function(index, element) { var ID = this.id; $('#' + ID).comments({ ... }); });

    What we have noticed when two threads are placed on the same page, the first calls to get the comments work fine - they get the comments for the right ID. However, as soon as you go to post a new comment or reply, the ID remains that of the second div.

    Any suggestions on how we might allow multiple threads on the same page?

    opened by shelane 15
  • Uncaught TypeError: n.map is not a functionn @ jquery-comments.min.js

    Uncaught TypeError: n.map is not a functionn @ jquery-comments.min.js

    Hello,

    I am a novice to web development/js/jquery and I tried using the jquery-comments, I modified the getcomments function as follows:

    getComments: function(success, error) { var comment_get_data = {'articleid':articleid, 'function':'getComments'}; $.ajax({ type: 'post', url: 'http://localhost/website/functions/comments.php', data: comment_get_data, success: function(commentsArray) { success(commentsArray) }, error: error }); },

    and my comments.php has the following return functionality:

    `case 'getComments':

            $data = mysqli_query($GLOBALS['connection'], "(SELECT comments.commentid, comments.parent, comments.created, comments.modified, comments.comment, comments.username, comments.createdByAdmin, comments.createdByCurrentUser, comments.upvoteCount, comments.userHasUpvoted, customers.cprofilePic AS profilePic FROM `comments` RIGHT JOIN customers ON customers.cusername=comments.username WHERE articleid = 1) UNION (SELECT comments.commentid, comments.parent, comments.created, comments.modified, comments.comment, comments.username, comments.createdByAdmin, comments.createdByCurrentUser, comments.upvoteCount, comments.userHasUpvoted, users.profilePic FROM `comments` RIGHT JOIN Users ON users.username=comments.username WHERE articleid = 1)");
            $i = 0;
            while($data2 = mysqli_fetch_assoc($data)){
                $commentsArray[$i] = $data2;
                $commentsArray[$i]['profileURL'] = "http://localhost/website/" . $data2['username'];
                $i++;
            }
            return $commentsArray;`
    

    and I am getting the uncaught type error n.map is not a function, I am not sure what I am doing wrong, any help is appreciated. Thanks for the code and thanks in advance for your help!

    opened by KG20 11
  • 'Invalid Date' and 'Reply' not working

    'Invalid Date' and 'Reply' not working

    Hello,

    I'm storing the comments to a database with Laravel via a post request. Then I'm loading then again with a get request. However, first when I send the comment, a new item appears in the list but there is no text. When I refresh the page it appears. The comment is written correctly to the database. When I'm loading the comments from the GET Request, everything works so far, but I can't get the date working (always displays "Invalid Date") and the reply buttons are not working anymore. When I use the example without post and get requests as you have described in "2) Initialize the library", everything is working so far. But of course I want to save the comments to the database. When I use the example without post and get requests as you have described in "2) Initialize the library", everything is working so far. But of course I want to save the comments to the database.

    Here is some code:

        $('.comments_content').comments({
            profilePictureURL: 'https://app.viima.com/static/media/user_profiles/user-icon.png',
                enableUpvoting: false,
            roundProfilePictures: true,
            enableReplying: true,
    
            fieldMappings: {
              id: 'id',
              parent: 'parent',
              created: 'created_at',
              modified: 'updated_at',
              content: 'content',
              fullname: 'author_id',
              profilePictureURL: 'profile_picture_url',
              createdByCurrentUser: 'created_by_current_user'
            },
            postComment: function(commentJSON, success, error) {
                $.ajax({
                    type: 'post',
                    url: "{{ action('CommentsController@store') }}",
                    data: {comment: commentJSON, cardid: clickedcardid},
                    success: function(comment) {
                        success(comment)
                    },
                    error: error
                });
            }
        });
    
    
    
    
            getComments: function(success, error) {
                $.ajax({
                    type: 'get',
                    url: '{{ action('CommentsController@index') }}',
                    success: function(commentsArray) {
    
                      // Only display the comments which are assigned to the clicked card
                      for(var i = commentsArray.length - 1; i >= 0; i--) {
                        if(commentsArray[i].card_id != clickedcardid) {
                          commentsArray.splice(i, 1);
                        }
                      }
    
                      for(var i=0; i<commentsArray.length; i++) {
                        commentsArray[i].profile_picture_url = 'https://app.viima.com/static/media/user_profiles/user-icon.png';
                      }
    
                      success(commentsArray)
                    },
                    error: error
                });
            }
    

    So to sum up:

    • I can save the comments to a database and read them out
    • I do it via jQuery AJAX POST and GET Requests
    • Problem 1: When I post a comment, a new item appears in the list, however without the content and author displayed. First displayed after refresh.
    • Problem 2: When reading out the comments, it always says "Invalid Date"
    • Problem 3: When reading out, the reply button is not working.

    Thanks for your help!

    opened by xEnigma 10
  • Could we have a feature which load/refresh the comments every 5 seconds

    Could we have a feature which load/refresh the comments every 5 seconds

    I am new to Jquery, but realized this plugin is pretty cool. Now I would like to reload/refresh the comments container every 5 seconds, googled and tried, but the experience is not so good.

    What I am looking for is that only some new comments being added or removed, not the whole div or page being refreshed.

    Thanks!

    enhancement 
    opened by cooperyuan 7
  • Firefox Issues

    Firefox Issues

    Hi.

    Great plugin. There is some Firefox issues http://oi67.tinypic.com/m9o8ko.jpg

    The plugin auto add new line but becuase is together with the text the new line shows as text only. Also the Oldest button dont work well.

    Any suggestions? Regards.

    opened by mstojanovv 7
  • Attachments feature

    Attachments feature

    Hello,

    In my current project I need my user to be able to upload and attach files to theirs comments. Can this feature be easily added here ? Do you have any advices to do so ?

    enhancement 
    opened by erichard 7
  • Getting started

    Getting started

    I downloaded and installed the package exactly as shown. Used the sample code for a starting point. On both the demo, and on the start up I have going. It fires a jquery / javascript error when you make a change to the text, and then of course the send button does not un-disable and the script is dead.

    The error I get is

    TypeError: this.commentsById[commentId] is undefined var contentChanged = content != this.commentsById[commentId].content;

    At line 545. If you look at the source code its looking for an attribute data-comments that does not exist on the textarea or its surrounding wrappers. I found the area in the code that defines the dom of that object. Tried adding it.

    I'm a newbie here. I've done a lot of jquery work, and tried to debug this on my own. After a couple of hours I figured I'd better simply ask someone. Either there is something left out of the setup instructions, or I've missed something.

    opened by paulsitebuildercorp1 6
  • TypeError: inputText is undefined

    TypeError: inputText is undefined

    Hello,

    I saw a post with the same tittle but with no response and I don't think the issue is based on the same as mine, so I decided to open a new issue.

    I’m trying out this plugin for the first time and trying to make it fit my needs. So far everything has turned out well when fetching comments from the database but when posting comments, I keep getting the following error. “TypeError: inputText is undefined” and it points to the following line.

    “return inputText.replace(new RegExp('\u00a0', 'g'), ' '); // Convert non-breaking spaces to regular spaces”.

    One important note is that the comments ARE saved to the database. I get the error after the query has finished and the comments do not show up until I refresh the page.

    I am not sure if this helps but I am not using the jquery-comments.min.js file but the jquery-comments.js file so I can have a better scope of everything that’s in the plugin.

    This is what I’m using to post the comments.

          postComment: function(commentJSON, success, error) {
               $.ajax({
                type: 'post',
                url: 'comments.php',
                data: commentJSON,
                success: function(comment) {
                              success(comment)
                       },
                       error: error
                     });
                },
    

    Here’s a sample of the server-side code (comments.php) to insert into the database. I am only taking the “content” from the POST and only using 3 parameters to save data to the db.

                    $creator_id = $user_id; //this is predefined from the user’s session ID.
                    $content = $_POST['content'];
     
                    $sql = "INSERT INTO comments
                    (creator_id, date_created, content)
                    VALUES
                    ('$creator_id', NOW(), '$content')";
                    $res = mysqli_query($conn, $sql) or die("Error: ".mysqli_error($conn));
    

    Not sure what the issue could be.

    Thanks in advance,

    opened by bluesun3k1 5
  • Reply not working

    Reply not working

    When i click the reply button, It was not add the text box . In the firefox console, its shows nothing . But in the chrome console . Its shows the jquery-comments.js:2096 The given range isn't in document.
    moveCursorToEnd @ jquery-comments.js:2096

    Especially on this moveCursorToEnd section

    sel.addRange(range);

    opened by p-g-krish 5
  • Use HTML inside comment

    Use HTML inside comment

    Is there any way to use HTML inside the comment?

    To do this i changed the following line: 1593: content.html(this.linkify(this.escape(commentModel.content)));

    to
    1593: content.html(this.linkify(commentModel.content));

    opened by SoaresMG 5
  • Send comment on

    Send comment on "Enter" event

    Hi,

    Many users are familiar with send a comment on Enter (thanks to Facebook?).

    I think that it will be a good improvement to have the option of send the comment on Enter event.

    Thanks!

    enhancement 
    opened by sergiogregorutti 5
  • hasAttachments function should test if attachments property exists

    hasAttachments function should test if attachments property exists

    I propose to change

    commentModel.hasAttachments = function() {
        return commentModel.attachments.length > 0;
    }
    

    to

    commentModel.hasAttachments = function() {
        return !!commentModel.attachments && commentModel.attachments.length > 0;
    }
    

    as commentModel does not always contain attachments property 👍

    opened by oldrich-svec 0
  • Scroll and focus on textbox when clicking on

    Scroll and focus on textbox when clicking on "reply"

    When I click on reply and the comment has lots of subcomments, the input field is not visible. I would like it to scroll down to the textbox and it should have mouse focus.

    opened by rewdboy 0
  • Comments search engine

    Comments search engine

    Is there a way to implement a system to search for comments? I think it is something very necessary and it would be useful to have this option available. Thank you!

    opened by yunierescobar 0
  • Limit number of attachments

    Limit number of attachments

    Hello,

    is it possible to limit the number of attachments each comment can have? I can't find anything in the documentation. Only way I have found is to check in the attachment validator but this will still allow multiple attachments to be submitted.

    Thanks

    opened by ledzgio 0
Owner
viima
The best way to collect & develop ideas
viima
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
VSCode extension that creates overlay for your Broadcasting Software of choice.

BSOverlay VSCode extension that creates an overlay for your Broadcasting Software of choice. Documentation Please refer to the Wiki Section. Installin

chocoearly44 4 Sep 30, 2022
Configure Wrangler in the format of your choice.

wjson ✨ Configure Wrangler in the format of your choice. ✨ Installation npm i -D @darkflare/wjson Usage (CLI) Run the below command and wjson will aut

Azury 9 Oct 5, 2022
Configure Wrangler in the format of your choice.

wjson ✨ Configure Wrangler in the format of your choice. ✨ Installation npm i -D @darkflare/wjson Usage (CLI) Run the below command and wjson will aut

darkflare 8 Jul 31, 2022
Obsidian plugin to open a note of your choice when creating a new tab, like in the browser.

New Tab Default Page Obsidian plugin to open a note of your choice when creating a new tab, like in the browser. Usage Set the note to open in new tab

pseudometa 20 Dec 27, 2022
Repository for DeCHO - a crowdfunding platform using Choice Coin for voting.

DeCHO Repository for DeCHO - a crowdfunding platform using Choice Coin for voting. ReactNative This project is built using ReactNative Code to run cd

Choice Coin 12 Oct 21, 2022
A toolkit to rapidly scaffold out a new tauri-apps project using the framework of their choice.

create-tauri-app Component Version create-tauri-app About Tauri Tauri is a polyglot and generic system that is very composable and allows engineers to

Tauri 408 Jan 4, 2023
This web application was build the microverse program, it's about implementing functionalities using JavaScript

This web application was build the microverse program, it's about implementing functionalities using JavaScript

Mehdi Abdelaziz Rahal 11 Aug 18, 2022
A Drag-and-Drop library for all JavaScript frameworks implementing an enhanced transformation mechanism to manipulate DOM elements

JavaScript Project to Manipulate DOM Elements DFlex A Drag-and-Drop library for all JavaScript frameworks implementing an enhanced transformation mech

DFlex 1.5k Jan 8, 2023
A lightweight JavaScript library for implementing tooltips.

Tooltipper A lightweight (1kB) JavaScript library for implementing tooltips. Installation Install via NPM: npm i -S tooltipper Install via CDN: <scrip

Kyle Andrews 9 Nov 2, 2022
An example SvelteKit app implementing a simple authentication system.

SvelteKit Auth Example An example SvelteKit app implementing a variety of authentication backends View the demo NOTE: this is very much a work in prog

Dana Woodman 54 Dec 30, 2022
Canvas-based JavaScript UI element implementing touch, keyboard, mouse and scroll wheel support.

pure-knob Initially a (circular) knob / dial control with mouse, wheel, touch and keyboard support, implemented in pure JavaScript. In addition, this

Andre Plötze 44 Nov 4, 2022
Example project implementing authentication, authorization, and routing with Next.js and Supabase

Magic Link Authentication and Route Controls with Supabase and Next.js To run this project, To get started with this project, first create a new proje

Nader Dabit 134 Dec 11, 2022
Implementing hexagonal architecture on AWS Lambda with Node.js

Developing evolutionary architecture with AWS Lambda Context Agility enables you to evolve a workload quickly, adding new features, or introducing new

AWS Samples 95 Dec 20, 2022
Venni backend - The backend of the Venni client apps implementing the credit card payments, matching algorithms, bank transfers, trip rating system, and more.

Cloud Functions Description This repository contains the cloud functions used in the Firebase backend of the Venni apps. Local Development Setup For t

Abrantes 1 Jan 3, 2022
It consists of a recreation of Twitter, to put into practice both Front-end and Back-end knowledge by implementing the MERN Stack together with other technologies to add more value to the project.

Twitter-Clone_Back-end ✨ Demo. ?? About the project. ?? Descriptions. It consists of a recreation of Twitter, to put into practice knowledge of both F

Mario Quirós Luna 5 Apr 12, 2022
startupDB is an Express middleware function implementing a high-performance in-memory database

startupDB startupDB is a database designed to create REST APIs. It is implemented as an Express middleware function and allows for easy implementation

Jeroen de Vries 8 Jul 26, 2022