1 of 2
1
Plugin: AJAX Babble
Posted: 19 April 2010 11:57 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

The attached add-on files may be out of date.  Please visit Devot-ee for the latest versions.

This plugin uses AJAX to submit comments. Supports pagination, scrolling newly submitted
comment into view and triggering search for certain comment through URL.

I. THE TAG exp:ajax_babble:script

This is a *single* tag.

PARAMETERS

1) form_id - required. Allows you to specify CSS id parameter of the form outputted by
exp:comment:form tag. Usually its value will be “comment_form”.

2) entry_id - required. Allows you to specify ID number of the entry being commented on.

3) comments_template_url - required. Allows you to specify URL of the comment template.
You must specify full URL, i.e. starting with “http”. This parameter accepts inside its value
the following ExpressionEngine variables: site_id, site_url, site_index, homepage.

4) comments_container_id - required. Allows you to specify CSS id parameter of the HTML element
inside which AJAX should output comments.

5) submit_button_id - required. Allows you to specify CSS id parameter of the submit button of the
comment form.

6) comments_number_id - optional. Allows you to specify CSS id parameter of the HTML element
inside which number of comments is displayed; this number will be updated when AJAX will submit a new
comment. This parameter supports pipe operator.

7) css_id_to_scroll - optional. Allows you to specify CSS id parameter of the comment which will
be scrolled into view after AJAX will load comments. Into view will be scrolled either
the newly submitted comment or the comment which was found by the search triggered by URL.

8) preview_template_url - optional. Allows you to specify URL of the preview template.
You must specify full URL, i.e. starting with “http”. This parameter accepts inside its value
the following ExpressionEngine variables: site_id, site_url, site_index, homepage.

9) preview_container_id - optional. Allows you to specify CSS id parameter of the HTML element
inside which AJAX should output comment preview.

10) preview_button_id - optional. Allows you to specify CSS id parameter of the preview button of the
comment form.

11) comments_progress_indicator_id - optional. Allows you to specify CSS id parameter of the HTML element
which will act as the indicator of comments being loaded.

12) preview_progress_indicator_id - optional. Allows you to specify CSS id parameter of the HTML element
which will act as the indicator of comment preview being loaded.

13) progress_indicator_class - optional. Allows you to specify CSS class parameter of the HTML element
which will act as the indicator of comments or comment preview being loaded.

14) comments_error_message_id - optional. Allows you to specify CSS id parameter of the HTML element
inside which an error message outputted when AJAX tried to load comments will be displayed.

15) preview_error_message_id - optional. Allows you to specify CSS id parameter of the HTML element
inside which an error message outputted when AJAX tried to load comment preview will be displayed.

16) error_message_class - optional.  Allows you to specify CSS class parameter of the HTML element
inside which an error message outputted when AJAX tried to load comments or comment
preview will be displayed.

17) add_callback_submit - optional. Allows you to specify name of javascript function which
will be executed when AJAX response will be outputted into container after submission of the new comment. This parameter supports pipe character, i.e. you can add several callback functions.

18) add_callback_paginate - optional. Allows you to specify name of javascript function which
will be executed when AJAX response will be outputted into container after clicking of some pagination link. This parameter supports pipe character, i.e. you can add several callback functions.

19) any name of javascript function which is used inside the value of “add_callback_submit” parameter or
“add_callback_paginate” parameter can be used as the name of a new parameter. The value of this parameter will
be used as argument of the relevant javascript function. E.g. if you have parameter

add_callback_submit="my_callback" 

then you can add parameter

my_callback="5" 

the number “5” will be used as the argument for “my_calback” function.
In case you need to call a function with several arguments, use javascript object.  E.g. if you have parameter

add_callback_submit="new_callback" 
then you can add parameter
new_callback='{"value1": null,"value2": "some_string"}' 

Continued in the next post.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 19 April 2010 11:58 AM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

II. THE TAG exp:ajax_babble:comments

This is a *tag pair* used to *wrap* the tag exp:comment:entries.

PARAMETERS

1) entry_id - required. This parameter *must* have the value {embed:entry_id}

2) limit - optional. Allows you to specify how many comments should be displayed on one page. Default is 100.
This parameter *must* have exactly the same value as “limit” parameter of exp:comment:entries tag which
is wrapped by exp:ajax_babble:comments tag.

3) max_pagination_links - optional. Allows you to specify how many pagination links should be
  displayed. Default value is “2”.

4) sort - optional. Allows you to specify how - ascendingly (asc)  or descendingly (desc) - comment entries
should be sorted. Default value is “desc”. This parameter *must* have exactly the same value as “sort” parameter
of exp:comment:entries tag which is wrapped by exp:ajax_babble:comments tag.

5) orderby - optional. This parameter sets the display order of the comments. Possible values are: date, email,
location, name, url. Default id “date”. This parameter *must* have exactly the same value as “orderby” parameter
of exp:comment:entries tag which is wrapped by exp:ajax_babble:comments tag.

6) search_trigger - optional. Allows you to specify the string in url which will trigger the search for
certain comment. E.g. if this parameter has the value “comment_”, then in case some segment is, say, “comment_255”,
the search will be triggered for the comment having ID number 255.

7) css_id_to_scroll - optional. Allows you to specify CSS id parameter of the comment which will
be scrolled into view after AJAX will load comments. Into view will be scrolled either
the newly submitted comment or the comment which was found by the search triggered by URL.
The value of this parameter *must* be the same as the value of
identically named parameter of exp:ajax_babble:script tag.

8) parse - required. This parameter *must* have the value “inward”.

VARIABLES

1) ajax_babble_entry_id - outputs entry_id number of the entry comments belong to. Used as the value of
of exp:comment:entries tag which is wrapped by exp:ajax_babble:comments tag.

2) ajax_babble_comment_id_to_scroll - comment id of the newly submitted comment or comment id of the
comment the search was triggered for by the string in URL. Used inside conditional which outputs
CSS ID parameter specified by “css_id_to_scroll” parameter of exp:ajax_babble:script tag.

3) ajax_babble_url_title - outputs url_title of the entry comments belong to.

4) ajax_babble_weblog_name - outputs short weblog name of the weblog entry being commented belongs to.

5) ajax_babble_segment_1, ajax_babble_segment_2, ajax_babble_segment_3, ajax_babble_segment_4, ajax_babble_segment_5,
ajax_babble_segment_6, ajax_babble_segment_7, ajax_babble_segment_8, ajax_babble_segment_9 - outputs segments of the URL
which was used to output *main* template.

6) ajax_babble_search_trigger_segment - outputs URL segment in which search triggering string is present.

7) ajax_babble_css_id_to_scroll - outputs the value of “css_id_to_scroll” parameter.


Continued in the next post.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 19 April 2010 11:59 AM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

III. MAIN TEMPLATE (E.G technical/for_tests)

<html>
<
head>

[removed]
//<![CDATA[
{embed="js/debugLog"}
//]]>
[removed]

<style>
.
pagination a {
cursor
pointer;
color:blue;
}

.pagination a:hover {
text
-decoration:underline;
}

div
.progress_indicator {
border
solid 1px green;
background-imageurl({site_url}images/ajax-loader.gif);
background-repeatno-repeat;
background-positioncenter;
height7em;
width35em;
text-aligncenter;
displayblock!important;
}

div
.indicator  {
display
none;
}

.ajax_error {
border
solid 1px red;
height7em;
width35em;
displayblock!important;
}
</style>

</
head>

<
body>

{exp:weblog:entries weblog="technical" url_title="dummy_entry" dynamic="off"}

<h1><a href="{title_permalink=blog/comments/index}">{title}</a></h1>

{article}


<p>{entry_date format=' %l, %F %d, %Y '} by {author} <span id="comments_number">{comment_total}</spancomments</p>



<
div id="preview_progress_indicator" class="indicator">
Loading comment preview...
</
div>

<
div id="preview_error_message" class="indicator">
<
h3 style="margin-bottom: 1em; color: #cc3300;">Error occurred:</h3>
</
div>

<
div id="preview_container">

</
div>

{exp:ajax_babble:script form_id="comment_form" entry_id="{entry_id}" comments_template_url="{homepage}/technical/for_tests2/" preview_template_url="{homepage}/technical/for_tests3/" comments_container_id="comments_container" preview_container_id="preview_container" submit_button_id="comments_submit_button" preview_button_id="comments_preview_button"  comments_number_id="comments_number" css_id_to_scroll="comment_to_scroll" comments_progress_indicator_id="comments_progress_indicator" preview_progress_indicator_id="preview_progress_indicator" progress_indicator_class="progress_indicator" comments_error_message_id="comments_error_message" preview_error_message_id="preview_error_message" error_message_class="ajax_error"}

{exp
:comment:form entry_id="{entry_id}"}

<h2>Post a Comment</h2>

{if logged_out}
<p>Name: <input type="text" name="name" value="{name}" size="50" /></p>

<
p>Email: <input type="text" name="email" value="{email}" size="50" /></p>

<
p>URL: <input type="text" name="url" value="{url}" size="50" /></p>
{/if}

<textarea name="comment" cols="50" rows="12"></textarea>

{if logged_out}
<p><input type="checkbox" name="save_info" value="yes" {save_info} /> Remember my personal information</p>
{/if}

<p><input type="checkbox" name="notify_me" value="yes" {notify_me} /> Notify me of follow-up comments?</p>

{if captcha}
<p>Submit the word you see below:<br />
{captcha}<br />
<
input type="text" name="captcha" value="" size="20" maxlength="20" style="width:140px;" /></p>
{/if}

<p><input type="submit" id="comments_submit_button" name="submit" value="Submit" />
<
input type="submit" id="comments_preview_button" name="preview" value="Preview" /></p>

{/exp:comment:form}

<div id="comments_progress_indicator" class="indicator">
Loading comments...
</
div>

<
div id="comments_error_message" class="indicator">
<
h3 style="margin-bottom: 1em; color: #cc3300;">Error occurred:</h3>
</
div>

<
div id="comments_container">
{embed="technical/for_tests2" entry_id="{entry_id}"}
</div>

{/exp:weblog:entries}

</body>
</
html
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 19 April 2010 12:01 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

IV. COMMENTS TEMPLATE (E.G technical/for_tests2)

<h2>Comments:</h2>

<
ul>

{exp:ajax_babble:comments entry_id="{embed:entry_id}" limit="5" search_trigger="comment_" orderby="date" sort="asc" parse="inward"}

{exp
:comment:entries entry_id="{ajax_babble_entry_id}" limit="5" orderby="date" sort="asc" paginate="top" dynamic="off"}

{paginate}
<class="pagination">Page {current_page} of {total_pages} pages {pagination_links}</p>
{/paginate}

<li {if "{ajax_babble_comment_id_to_scroll}"=="{comment_id}"}id="comment_to_scroll"{/if} class="comment-body">
<
div>{absolute_count}{url_or_email_as_author} at {comment_date format='%m/%d - %h:%i %A'} said:</div>
<
blockquote>{comment}</blockquote>
</
li>

{/exp:comment:entries}

{
/exp:ajax_babble:comments}

</ul

V. PREVIEW TEMPLATE (E.G technical/for_tests3)

{exp:comment:preview}

<ul>

<
li>

<
div>{url_or_email_as_author} at {comment_date format='%m/%d - %h:%i %A'} said:</div>

<
blockquote>{comment}</blockquote>

</
li>

</
ul>

{/exp:comment:preview} 

End of the description of plugin.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 19 April 2010 02:52 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  272
Joined  11-06-2007

Looks great, thanks for sharing.  Do you have any examples of this working on a live site?

Profile
 
 
Posted: 21 April 2010 10:02 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

Hi Joe,

You can test plugin here (both previewing and submitting comments). You also can trigger search for certain comment through URL by entering URLs which have as the last segment
comment_430, comment_431 etc.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 21 April 2010 10:06 AM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

Hi,

I released version 1.0.10 of AJAX Babble plugin. In this version a couple minor bugs were fixed and some minor polishing of javascript was done.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 21 April 2010 12:19 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  272
Joined  11-06-2007

@Laisvunas,

I just tested out the demo but am getting a response of “Loading comments…
No response from server.” when trying to submit a comment.

Profile
 
 
Posted: 21 April 2010 01:34 PM   [ Ignore ]   [ # 8 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  13771
Joined  04-15-2006

I’m also getting that response too.

I also tried this on a site and couldn’t get it to submit the comments at all. I got the Loading comments message but then nothing happens and no comment gets saved :-(

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

Profile
 
 
Posted: 22 April 2010 09:11 AM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

Hi Mark and Joe,

I just tested out the demo but am getting a response of “Loading comments…
No response from server.” when trying to submit a comment.

Oops! I unintentionally disabled submitting of comments for not logged-in visitors.

Try again, now it should work correctly.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 22 April 2010 09:14 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

Hi,

I released version 1.0.11 of AJAX Babble plugin. In this version I enhanced javascript’s handling of EE error messages in order to prevent outputting of them inside comment container.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 24 April 2010 11:03 AM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

Hi,

I released version 1.0.12 of AJAX Babble plugin. In this version a couple of minor improvements were made in javascript this plugin outputs.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 26 April 2010 10:52 AM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

Hi,

I released version 1.1 of AJAX Babble plugin. In this release two new parameters were added to exp:ajax_babble:script tag:

1) add_callback_submit - optional. Allows you to specify name of javascript function which
will be executed when AJAX response will be outputted into container after submission of the new comment.

2) add_callback_paginate - optional. Allows you to specify name of javascript function which
will be executed when AJAX response will be outputted into container after clicking of some pagination link.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 26 April 2010 08:11 PM   [ Ignore ]   [ # 13 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  526
Joined  09-06-2006

Another great addition to the EE arsenal.

I’ve just spent some time with v1.1 trying to get the add_callback_submit parameter to work. I’m trying to use it to call a jquery function that fades out the comment form after the comment was successfully sent and place the success/comment moderation message in its place but I keep getting and error. I’ve created a jQuery function named “comAway” but no matter how I format this I still get an error. Could you post a simple example?

 Signature 

Kyle Summer | smartpill design | New Haven, CT |  twitter

Profile
 
 
Posted: 26 April 2010 08:32 PM   [ Ignore ]   [ # 14 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4003
Joined  05-13-2004

This looks fantastic - as soon as I get free time (currently in extremely short supply) I will add this to my personal blog Repatriate Me!

 Signature 

web: Caffeine Creations twitter @CS_sean

Profile
 
 
Posted: 27 April 2010 08:11 AM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007
smartpill - 27 April 2010 12:11 AM

Another great addition to the EE arsenal.

I’ve just spent some time with v1.1 trying to get the add_callback_submit parameter to work. I’m trying to use it to call a jquery function that fades out the comment form after the comment was successfully sent and place the success/comment moderation message in its place but I keep getting and error. I’ve created a jQuery function named “comAway” but no matter how I format this I still get an error. Could you post a simple example?

It’s simple.

Create anywhere on the main template a function:

sript >
function 
my_callback() {
alert
("New comment submitted!");
}
</ script 

Then add this parameter to exp:ajax_babble:script tag:

add_callback_submit="my_callback" 
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 27 April 2010 10:02 AM   [ Ignore ]   [ # 16 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  526
Joined  09-06-2006
Laisvunas - 27 April 2010 12:11 PM
smartpill - 27 April 2010 12:11 AM

Another great addition to the EE arsenal.

I’ve just spent some time with v1.1 trying to get the add_callback_submit parameter to work. I’m trying to use it to call a jquery function that fades out the comment form after the comment was successfully sent and place the success/comment moderation message in its place but I keep getting and error. I’ve created a jQuery function named “comAway” but no matter how I format this I still get an error. Could you post a simple example?

It’s simple.

Create anywhere on the main template a function:

sript >
function 
my_callback() {
alert
("New comment submitted!");
}
</ script 

Then add this parameter to exp:ajax_babble:script tag:

add_callback_submit="my_callback" 

Ah. OK, it works if I put the function in the same template, but not if I put it in the main linked script, which is linked in the header, so I thought it should work. Is this a parsing order issue?

 Signature 

Kyle Summer | smartpill design | New Haven, CT |  twitter

Profile
 
 
Posted: 27 April 2010 10:08 AM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  02-02-2007

OK, it works if I put the function in the same template, but not if I put it in the main linked script, which is linked in the header, so I thought it should work.

What do you mean by putting “it in the main linked script, which is linked in the header”?

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 27 April 2010 10:41 AM   [ Ignore ]   [ # 18 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  526
Joined  09-06-2006
Laisvunas - 27 April 2010 02:08 PM

OK, it works if I put the function in the same template, but not if I put it in the main linked script, which is linked in the header, so I thought it should work.

What do you mean by putting “it in the main linked script, which is linked in the header”?

I have a template named entry which has jquery and my main site script (js_spd) externally linked in the header which contains the function.

<s ript type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></s ript>
<
s ript type="text/javascript" src="/index.php/common/js_spd/"></sc ipt

within spd_js script is

function comAway() { jQuery('#comment_form').hide() }

Then the template with the weblog:entries and ajax:babble is embedded into that.

{embed="common/_center" pagetype="blog"

When I try

add_callback_submit=“comAway”

like that, I get errors (see screenshot), when I put the function directly into the _center template above {exp:ajax_babble:script…} tag, it works.

 Signature 

Kyle Summer | smartpill design | New Haven, CT |  twitter

Profile
 
 
   
1 of 2
1