1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
LibertyComment = {
// constants
'FORM_DIV_ID':'edit_comments',
'FORM_ID':'editcomment-form',
'REPLY_ID':null,
// functions
'attachForm': function(elm, reply_id, root_id){
LibertyComment.REPLY_ID = reply_id;
LibertyComment.cancelComment();
var form_div = MochiKit.DOM.removeElement( LibertyComment.FORM_DIV_ID );
MochiKit.DOM.insertSiblingNodesAfter( $(elm), form_div );
var form = $(LibertyComment.FORM_ID);
if (form.parent_id === undefined){
var idInput = MochiKit.DOM.INPUT({'type':'hidden', 'name':'parent_id', 'value':root_id});
form.appendChild( idInput );
}
form.parent_id.value = LibertyComment.ROOT_ID = root_id;
form.post_comment_reply_id.value = reply_id;
form.post_comment_id.value = "";
form_div.style.display = "block";
if ( LibertyComment.BROWSER != "ie" ){
MochiKit.Visual.ScrollTo( form_div );
}else{
self.scrollTo( form_div.offsetLeft, form_div.offsetTop );
}
},
'resetForm': function(){
$(LibertyComment.FORM_ID).reset();
},
'detachForm': function(){
var form_div = $(LibertyComment.FORM_DIV_ID);
form_div.style.display = "none";
document.body.appendChild( form_div );
},
"sendRequest": function(formdata, callback){
var url = bitRootUrl+"liberty/ajax_comments.php";
var params = queryString(formdata);
var req = getXMLHttpRequest();
req.open('POST', url, true);
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
req.setRequestHeader('Content-Length',params.length);
var post = sendXMLHttpRequest(req,params);
post.addCallback(callback);
},
'previewComment': function(){
var LC = LibertyComment;
for( i in LC.prepRequestSrvc ){
LC.prepRequestSrvc[i]( LC.FORM_ID );
}
var f = MochiKit.DOM.formContents( $(LC.FORM_ID) );
for (n in f[0]){
if (f[0][n] == 'post_comment_submit' || f[0][n] == 'post_comment_cancel'){ f[1][n] = null; }
}
LC.sendRequest(f,LC.displayPreview);
},
'postComment': function(){
var LC = LibertyComment;
for( i in LC.prepRequestSrvc ){
LC.prepRequestSrvc[i]( LC.FORM_ID );
}
var f = MochiKit.DOM.formContents( $(LC.FORM_ID) );
for (n in f[0]){
if (f[0][n] == 'post_comment_preview' || f[0][n] == 'post_comment_cancel'){ f[1][n] = null; }
}
LC.sendRequest(f,LC.checkRslt);
},
'cancelComment': function(ani){
LibertyComment.cancelPreview(true);
if (ani == true){
MochiKit.Visual.blindUp( LibertyComment.FORM_DIV_ID, {afterFinish: function(){
LibertyComment.detachForm();
LibertyComment.resetForm();
var reply_div = $('comment_'+LibertyComment.REPLY_ID);
if ( LibertyComment.BROWSER != "ie" ){
MochiKit.Visual.ScrollTo( reply_div );
}else{
self.scrollTo( reply_div.offsetLeft, reply_div.offsetTop );
}
}});
}else{
LibertyComment.detachForm();
LibertyComment.resetForm();
}
},
'cancelPreview': function(ani){
if ( $('comment_preview') != null){
if (ani == true){
MochiKit.Visual.blindUp( $('comment_preview'), {afterFinish: function(){
MochiKit.DOM.removeElement( $('comment_preview') );
}});
}else{
return MochiKit.DOM.removeElement( $('comment_preview') );
}
}
},
'displayPreview': function(rslt){
if ( $('comment_preview') == null){
var preview = DIV({'id':'comment_preview'}, null);
}else{
var preview = LibertyComment.cancelPreview();
}
preview.style.display = 'none';
var xml = rslt.responseXML;
preview.innerHTML = xml.documentElement.getElementsByTagName('content')[0].firstChild.nodeValue;
preview.style.marginLeft = (LibertyComment.REPLY_ID != LibertyComment.ROOT_ID)?"20px":'0';
MochiKit.DOM.insertSiblingNodesBefore( $(LibertyComment.FORM_DIV_ID), preview);
MochiKit.Visual.blindDown( preview, {afterFinish: function(){
if ( LibertyComment.BROWSER != "ie" ){
MochiKit.Visual.ScrollTo( preview );
}else{
//self.scrollTo( preview.offsetLeft, preview.offsetTop );
}
}});
},
'checkRslt': function(rslt){
var xml = rslt.responseXML;
var status = xml.documentElement.getElementsByTagName('code')[0].firstChild.nodeValue;
if (status == '200'){
LibertyComment.displayComment(rslt);
}else{
//if status is 400, 401, or 405 still call preview - allowing someone to save their typed text.
LibertyComment.displayPreview(rslt);
}
},
'displayComment': function(rslt){
var xml = rslt.responseXML;
var comment = DIV(null, null);
comment.innerHTML = xml.documentElement.getElementsByTagName('content')[0].firstChild.nodeValue;
comment.style.marginLeft = (LibertyComment.REPLY_ID != LibertyComment.ROOT_ID)?"20px":'0';
comment.style.display = 'none';
if (LibertyComment.SORT_MODE == "commentDate_asc"){
MochiKit.DOM.insertSiblingNodesBefore( $('comment_'+LibertyComment.REPLY_ID+'_footer'), comment );
}else{
MochiKit.DOM.insertSiblingNodesAfter( $('comment_'+LibertyComment.REPLY_ID), comment );
}
LibertyComment.cancelPreview( true );
MochiKit.Visual.blindUp( LibertyComment.FORM_DIV_ID, {afterFinish: function(){
LibertyComment.detachForm();
LibertyComment.resetForm();
MochiKit.Visual.blindDown( comment, {afterFinish: function(){
if ( LibertyComment.BROWSER != "ie" ){
MochiKit.Visual.ScrollTo( comment );
}else{
//self.scrollTo( comment.offsetLeft, comment.offsetTop );
}
}});
}});
},
/* an array of functions that will be called before form is posted
* comment formid is passed to each function
* example:
* func = function(formid){do something};
* LibertyComment.prepRequestSrvc.push(func);*/
"prepRequestSrvc": new Array()
}
|