- Fetches comments from your server and displays them
- Pushes comments to your server
- Allows visitors to comment using their Twitter screen name
The plugin is based on the idea of Joey Primiani
For code examples have a look at the "example" directory.
To install TwitComments simply reference the jquery.twitcomments.min.js file from your HTML:
<script src="jquery-1.7.min.js"></script>
<script src="jquery.twitcomments.min.js"></script>
Then add the following to the end of the <body>
tag making sure to replace "server" with your actual server URL.
<script>
$(document).ready(function(){
$('#comments').twitComments({
pullURL: 'server',
pushURL: 'server'
});
});
</script>
The plugin needs to communicates with your server to obtain existing comments and to send new comments.
Therefore you need the set the pullURL
and pushURL
. The first URL will be called to retrieve comments from your server and the second will be called to send a new comment to your server.
Your server must understand the following GET request. "pullURL" will be replaced with the URL you provided.
GET /pullURL?params=[...] HTTP/1.1
The "params" query string will be populated with whatever you provide client side. For example you could set a pageID to identify the page the request is originating from.
$(document).ready(function(){
$('#comments').twitComments({
params: { pageID: xyz }
});
});
The server must respond with HTTP status code 200 and the following JSON format:
{
"screen_name": SCREEN_NAME,
"url": URL,
"name": NAME,
"location": LOCATION,
"profile_image_url": PROFILE_IMAGE_URL,
"comment_timestamp": TIMESTAMP,
"comment_content": CONTENT
}
If any error occurs server side the server must respond with a HTTP status code other than 200 (404, 500, ...).
Your server must understand the following POST request. "pushURL" will be replaced with the URL you provided.
POST /pushURL HTTP/1.1
user=SCREEN_NAME
comment=COMMENT
params=[...]
The server should call the Twitter API to retrieve the following information:
- screen name
- url
- name
- location
- profile image url
The server must then respond with HTTP status code 200 and the following JSON format:
{
"screen_name": SCREEN_NAME,
"url": URL,
"name": NAME,
"location": LOCATION,
"profile_image_url": PROFILE_IMAGE_URL,
"comment_timestamp": TIMESTAMP,
"comment_content": CONTENT
}
If any error occurs server side the server must respond with a HTTP status code other than 200 (404, 500, ...).
To configure the plugin you can set the following optional configuration options:
Name | Type | Default value | Description |
---|---|---|---|
params | mixed | null | Will be sent to your server on every pull or push request. |
defaultProfileImageURL | string | null | The image to use in case the user has no profile image. |
cssClass | string | twitcomments | The name of the CSS class that prefixes the DOM elements created by the plugin. |
The following configuration settings can be used to translate the output of the plugin. The "{}" in the strings concerning the time will be replaced by the according numbers. For example "{} hours ago" will become "3 hours ago".
Name | Default Value |
---|---|
comments | Comments |
twitterUsername | Twitter Username |
writeAComment | Write a comment... |
submit | Comment... |
sending | Sending... |
errorNoName | Please enter your Twitter name |
errorNoComment | Please enter a comment |
errorCommentsNotLoaded | The comments could not be loaded |
errorCommentNotSaved | Your comment could not be saved |
from | from |
justNow | just now |
aMinuteAgo | a minute ago |
minutesAgo | {} minutes ago |
oneHourAgo | one hour ago |
hoursAgo | {} hours ago |
yesterday | yesterday |
daysAgo | {} days ago |
aWeekAgo | a week ago |
weeksAgo | {} weeks ago |
aMonthAgo | a month ago |
monthsAgo | {} months ago |
aYearAgo | a year ago |
yearsAgo | {} years ago |
Copyright (c) 2011 Georg Dresler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.