Could someone comment it plese... what does what!!!!
var guestbook;
window.addEvent('domready', domReady);
//a custom event that fires when the DOM is ready to be manipulated
function domReady() {
var req = new Request.JSON({
url: 'control.php?action=getPage',
onSuccess: ajaxSuccess
}).send()
$('newComment').addEvent('submit', addComment);
$('delete').addEvent('submit', deletee);
$('edit').addEvent('submit', editt);
}
function ajaxSuccess(jArray){
jArray.each(function(post){
var postObject = new PostItem(post.id, post.name, post.comment);
postObject.display().inject($('commentList'));
});
}
function addComment(e){
e.stop();
var req = new Request({
url:'control.php?action=insertPost',
onSuccess:insert
}).post(this);
}
function insert(idNo){
new Element('span',{
'text':'inserted item ' + idNo
}).inject($('newComment'));
}
function editt(e){
e.stop();
var req = new Request({
url:'control.php?action=editPost',
onSuccess:edit2
}).post(this);
}
function edit2(idNo){
new Element('span',{
'text':'edited item.'
}).inject($('edit'));
}
function deletee(e){
e.stop();
var req = new Request({
url:'control.php?action=removePost&id='+this.id.va lue,
onSuccess:delete2
}).send();
}
function delete2(idNo){
new Element('span',{
'text':'deleted item.'
}).inject($('newComment'));
}
var PostItem = new Class({
initialize: function(id, name, comment){
this.id = id;
this.name = name;
this.comment = comment;
},
display: function(){
var cont = new Element('div',{
'class':'postItem',
'id':'post'+this.id
});
var number = new Element('p',{
'class':'postid',
'text':this.id + ' is your ID'
});
var title = new Element('h3',{
'class':'postTitle',
'text':this.name + ' says...'
});
var comment = new Element('p',{
'class':'postComment',
'text':this.comment
});
number.inject(cont);
title.inject(cont);
comment.inject(cont);
return cont;
}
});