diff options
| author | wjames5 <will@tekimaki.com> | 2008-12-14 04:40:42 +0000 |
|---|---|---|
| committer | wjames5 <will@tekimaki.com> | 2008-12-14 04:40:42 +0000 |
| commit | c17c639a39396cded390eb6eff0e398a07b96b39 (patch) | |
| tree | a99bc7444d0e92c79961cc0c6a1b7f96dc683ed3 /scripts | |
| parent | 083838fc0350eaefbc9250ae10a01197be863cf9 (diff) | |
| download | liberty-c17c639a39396cded390eb6eff0e398a07b96b39.tar.gz liberty-c17c639a39396cded390eb6eff0e398a07b96b39.tar.bz2 liberty-c17c639a39396cded390eb6eff0e398a07b96b39.zip | |
create service for ajax comments so that fck editor (or any other add on) can do waht it needs to do before posting via ajax
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/LibertyComment.js | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/scripts/LibertyComment.js b/scripts/LibertyComment.js index 7c4b03a..e933df7 100644 --- a/scripts/LibertyComment.js +++ b/scripts/LibertyComment.js @@ -35,33 +35,37 @@ LibertyComment = { form_div.style.display = "none"; document.body.appendChild( form_div ); }, - 'previewComment': function(){ - var f = MochiKit.DOM.formContents( $(LibertyComment.FORM_ID) ); - for (n in f[0]){ - if (f[0][n] == 'post_comment_submit' || f[0][n] == 'post_comment_cancel'){ f[1][n] = null; } - } + "sendRequest": function(formdata, callback){ var url = bitRootUrl+"liberty/ajax_comments.php"; - var data = queryString(f); + 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',data.length); - var post = sendXMLHttpRequest(req,data); - post.addCallbacks(LibertyComment.displayPreview); + 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 f = MochiKit.DOM.formContents( $(LibertyComment.FORM_ID) ); + 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; } } - var url = bitRootUrl+"liberty/ajax_comments.php"; - var data = queryString(f); - var req = getXMLHttpRequest(); - req.open('POST', url, true); - req.setRequestHeader('Content-type','application/x-www-form-urlencoded'); - req.setRequestHeader('Content-Length',data.length); - var post = sendXMLHttpRequest(req,data); - post.addCallbacks(LibertyComment.checkRslt); + LC.sendRequest(f,LC.checkRslt); }, 'cancelComment': function(ani){ LibertyComment.cancelPreview(true); @@ -146,5 +150,11 @@ LibertyComment = { } }}); }}); - } + }, + /* 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() } |
