Posted by joshk on December 9, 2009 at 11:31pm
Jump to:
| Project: | Chaos tool suite (ctools) |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | joshk |
| Status: | closed (fixed) |
Issue Summary
I think it would be the beez kneez to ship ctools with a sample module that shows how to use the AWESOME POWER of the ajax and modal functionalities. I saw Roger present this in NYC, and wrote such a module on the plane to NOLA. I'm open to suggestions of other things we should show off how to do, but here's a first attempt.
This could also be merged with the existing sample module rather than starting as it's own.
| Attachment | Size |
|---|---|
| ctools_ajax_sample.tgz | 1.83 KB |
Comments
#1
Thanks for this piece of code Josh!
It helped me to prepare my own demo modules to the session of Drupal camp.
I discovered a little bug in your code that was difficult to track, but I found finally the reason:
This is a piece of code from ctools.module file:
function ctools_js_load($js) {if ($js == 'ajax') {
return TRUE;
}
return 0;
}
It makes that the argument that you pass to the callback function converts to TRUE or 0
In your code you have:
function ctools_ajax_sample_hello($js = NULL) {$output = '<h1>Hello World</h1>';
if ($js == 'ajax') {
When should be directly if ($js). yeah! that easy
That condition is stopping your code from working when javascript disabled.
This conversion of "ajax" to TRUE only happens if you use in the hook menu the argument %ctools_js
If you use any other name, it will not happen.
So I avoided to use %ctools_js to do it more "cross-drupal-compatible", because it seems Drupal 7 AJAX framework won't have these conversions.
Here the slides and demo code I prepared, hope it helps someone:
http://www.drupro.com/blog/david-corbacho/drupal-ajax-new-way
#2
Cleaned up, added to, and committed.
#3
Automatically closed -- issue fixed for 2 weeks with no activity.