Skip to content

Instantly share code, notes, and snippets.

@aroc
aroc / init-side-comments
Last active August 29, 2015 14:02
init-side-comments
// 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);
@aroc
aroc / side-comments-current-user-structure
Created June 15, 2014 19:34
SideComments.js currentUser structure
{
id: 1,
avatarUrl: "http://f.cl.ly/items/0s1a0q1y2Z2k2I193k1y/default-user.png",
name: "You"
}
@aroc
aroc / side-comments-existing-comments-structure
Last active August 29, 2015 14:02
SideComments.js existing comments array structure
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."
},
{
@aroc
aroc / side-comments-listening-to-events
Last active August 29, 2015 14:02
SideComments listening to events example.
// 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);
@aroc
aroc / setCurrentUser.js
Created June 15, 2014 20:36
SideComments setCurrentUser
var currentUser = {
"id": 1,
"avatarUrl": "users/avatars/user1.png",
"name": "Jim Jones"
};
sideComments.setCurrentUser(currentUser);
@aroc
aroc / insertComment.js
Created June 15, 2014 20:40
SideComments insertComment
var comment = {
sectionId: 12,
comment: "Hey there!",
authorAvatarUrl: "users/avatars/test1.png",
authorName: "Jim Jones",
authorId: 16
};
sideComments.insertComment(comment);
@aroc
aroc / selectSection.js
Created June 15, 2014 20:51
SideComments selectSection
sideComments.selectSection(12);
@aroc
aroc / deselectSection.js
Created June 15, 2014 20:54
SideComments deselectSection
sideComments.deselectSection(12);
@aroc
aroc / simple-server.js
Created July 21, 2014 21:32
Simple node server
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/');
@aroc
aroc / parse-url.js
Created February 9, 2015 17:25
Parse URL into object
var search = location.search.substring(1);
JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');