This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First require it. | |
var SideComments = require('side-comments'); | |
// Then, create a new SideComments instance, passing in the wrapper element and the optional the current user and any existing comments. | |
sideComments = new SideComments('#commentable-area', currentUser, existingComments); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
id: 1, | |
avatarUrl: "http://f.cl.ly/items/0s1a0q1y2Z2k2I193k1y/default-user.png", | |
name: "You" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var existingComments = [ | |
{ | |
"sectionId": "1", | |
"comments": [ | |
{ | |
"authorAvatarUrl": "http://f.cl.ly/items/1W303Y360b260u3v1P0T/jon_snow_small.png", | |
"authorName": "Jon Sno", | |
"comment": "I'm Ned Stark's bastard. Related: I know nothing." | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Listen to "commentPosted", and send a request to your backend to save the comment. | |
// More about this event in the "docs" section. | |
sideComments.on('commentPosted', function( comment ) { | |
$.ajax({ | |
url: '/comments', | |
type: 'POST' | |
data: comment, | |
success: function( savedComment ) { | |
// Once the comment is saved, you can insert the comment into the comment stream with "insertComment(comment)". | |
sideComments.insertComment(comment); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var currentUser = { | |
"id": 1, | |
"avatarUrl": "users/avatars/user1.png", | |
"name": "Jim Jones" | |
}; | |
sideComments.setCurrentUser(currentUser); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var comment = { | |
sectionId: 12, | |
comment: "Hey there!", | |
authorAvatarUrl: "users/avatars/test1.png", | |
authorName: "Jim Jones", | |
authorId: 16 | |
}; | |
sideComments.insertComment(comment); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sideComments.selectSection(12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sideComments.deselectSection(12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(201, {'Content-Type': 'text/plain'}); | |
res.end('{ "user_id": 1 }'); | |
return; | |
}).listen(8080, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:8080/'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var search = location.search.substring(1); | |
JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}'); |