var MAJLibrary = { //JSON Object creation
'cb_items' : [],
'cb_store' : function(item_to_store) {
//Clear the comment area
if(this.cb_items.length == 0){
$("#comment_loader").empty();
}
//Store the item into the items array
var number_of_comments = this.cb_items.length;
var id = number_of_comments--;
//obviously, we start at 0 items in the array of comments. This would normally be managed by a DB
item_to_store.push(id);
this.cb_items.push(item_to_store);
if(this.cb_items[id][3] == true){
$("#comment_loader").prepend('<div class="col-xs-12"><h5>'+this.cb_items[id][0]+'</h5><p>'+this.cb_items[id][2]+'</p></div>');
}else{
$("#comment_loader").prepend('<div class="col-xs-12"><h5><a href="mailto:'+this.cb_items[id][1]+'">'+this.cb_items[id][0]+'</a></h5><p>'+this.cb_items[id][2]+'</p></div>');
}
console.log(this.cb_items);
return this;
},
'cb_retrieve_all' : function() {
//Retrieve all comments and display
if(this.cb_items.length > 0){
for (var i = 0; i < this.cb_items.length; i++){
if(this.cb_items[i][3] == true){
$("#comment_loader").empty();
$("#comment_loader").prepend('<div class="col-xs-12"><h5>'+this.cb_items[i][0]+'</h5><p>'+this.cb_items[i][2]+'</p></div>');
}else{
$("#comment_loader").empty();
$("#comment_loader").prepend('<div class="col-xs-12"><h5><a href="mailto:'+this.cb_items[i][1]+'">'+this.cb_items[i][0]+'</a></h5><p>'+this.cb_items[i][2]+'</p></div>');
}
}
}else{
$("#comment_loader").empty();
$("#comment_loader").prepend("<p>No comments to load!</p>");
}
return this;
},
'cb_retrieve_last' : function(id) {
}
}; //Note the semicolon at the end
$('#comment_submit').click( function() {
var name = $("#sender").val();
var email = $("#email").val();
var comment = $("#comment").val(); //You MUST ALWAYS strip tags - I wont here but for any projects you MUST.
var...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.