Hello, See my message to the documentation list about where to document everything ajax, ahax, js, and jquery. http://drupal.org/node/121997 Right now, I am trying hard to understand book.js and ... I just don't get it. In book.js, there is an ajax call: $.ajax({ url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val() +'/'+ $('#edit-book-bid').val(), dataType: 'json', success: function(data) { // Insert the new select, and remove the progress bar. $('#edit-book-plid-wrapper').after(data['book']).remove(); } in book_menu(), there is a menu callback, which I guess is the callback used by the js above: $items['book/js/form'] = array( 'page callback' => 'book_form_update', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, 'file' => 'book.pages.inc', ); But everything javascript and ajax being completely undocumented, I am having a hard time to connect the two together, even by looking at drupal.js, looking at the big documentation block above drupal_add_js() (in common.inc), which I don't understand at all (I told you it was too early to change my handle!!) How does this... $.ajax({ url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val()+'/'+ $('#edit-book-bid').val(), ...lead to the book/js/form callback??? I sense it is connected to Drupal.attachBehaviors (in drupal.js) and Drupal.behaviors.bookSelect (book.js), but I don't know how. As I always do, if you tell me both the answer and where to document this, I'll have a go at starting a documentation. Thanks and blessings, Augustin.
On Dec 27, 2007 6:16 AM, Augustin (Beginner) <drupal.beginner@wechange.org> wrote:
How does this...
$.ajax({ url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val()+'/'+ $('#edit-book-bid').val(),
...lead to the book/js/form callback???
JQuery's documentation might help- http://docs.jquery.com/Ajax/jQuery.ajax -- Neil Drumm http://delocalizedham.com
I just looked at the doc and I don't get it either. Honestly, this stuff is REALLY hard to follow if you're not a very experienced javascript/jquery programmer. To me it's all just gobbledygook. ;-) Neil Drumm wrote:
On Dec 27, 2007 6:16 AM, Augustin (Beginner) <drupal.beginner@wechange.org> wrote:
How does this...
$.ajax({ url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val()+'/'+ $('#edit-book-bid').val(),
...lead to the book/js/form callback???
JQuery's documentation might help- http://docs.jquery.com/Ajax/jQuery.ajax
-- Neil Drumm http://delocalizedham.com
-- Sean Robertson Web Developer NGP Software, Inc. seanr@ngpsoftware.com (202) 686-9330 http://www.ngpsoftware.com
On Friday 28 December 2007 05:27, Sean Robertson wrote:
I just looked at the doc and I don't get it either. Honestly, this stuff is REALLY hard to follow if you're not a very experienced javascript/jquery programmer. To me it's all just gobbledygook. ;-)
The essential difficulty is figuring out which part you don't understand. Does this help? http://api.drupal.org/api/file/developer/topics/javascript_startup_guide.htm... [Originally, I made the same colored version of book.js as I did for Drupal.jsEnabled but I deleted everything (didn't commit) when I found out that book.js was not supposed to be part of core anymore. That's actually how I found the bug.] Blessings, Augustin.
Neil, Earl, Peter, all, thanks for your replies. I have added your various links in the API section of the handbook: http://drupal.org/node/205296 As far as book.module is concerned, the bit that I missed was the #ahah part in the form: // Add a drop-down to select the destination book. $form['book']['bid'] = array( '#type' => 'select', '#title' => t('Book'), '#default_value' => $node->book['bid'], '#options' => $options, '#access' => (bool)$options, '#description' => t('Your page will be a part of the selected book.'), '#weight' => -5, '#attributes' => array('class' => 'book-title-select'), '#ahah' => array( 'path' => 'book/js/form', 'wrapper' => 'edit-book-plid-wrapper', 'effect' => 'slide', ), ); I found out that the #ahah attribute is completely undocumented, so I added a placeholder for it in the FAPI reference: http://api.drupal.org/api/file/developer/topics/forms_api_reference.html#aha... (my addition might take a few hours to appear). It's only a placeholder though. Someone more knowledgeable needs to complete the doc, there. If nobody does it, at least developers would be made aware that there is such a thing as #ahah in FAPI. Is that something new in Drupal 6 ? [edit: it seems to be. It is mentioned in a very unlikely place: http://drupal.org/node/114774#choice_check . Why not in Peter's AJAX page?] Blessings, Augustin.
Augustin (Beginner) wrote:
url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val() +'/'+ $('#edit-book-bid').val(),
The part that you're not seeing is that there are 'settings' that are set via inline javascript and there's a Drupal-side API to make this easy: drupal_add_js($some_array, 'setting'); So if: $some_array = array('book' => array('formCallback' => 'book/js')); That covers the first part of it. The it pulls the formId out of the settings and uses jQuery to find the form_build_id input in that form and take it's value, and after that you've got the book id from #edit-book-bid. Search book.module for drupal_add_js and look for the 'setting' call. I think it'll be more clear after that.
On Friday 28 December 2007 06:46, Earl Miles wrote:
Augustin (Beginner) wrote:
url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val() +'/'+ $('#edit-book-bid').val(),
The part that you're not seeing is that there are 'settings' that are set via inline javascript and there's a Drupal-side API to make this easy:
drupal_add_js($some_array, 'setting');
So if: $some_array = array('book' => array('formCallback' => 'book/js'));
That covers the first part of it.
Actually, no. It's nice that I learned the construction drupal_add_js($some_array, 'setting'); which I didn't know before. But book.module doesn't use the setting function. Its only call of drupal_add_js is to add some inline js. I knew there was something wrong with that module. I grep'ed everywhere, and searched the jquery docs, but there is no formCallback entity defined anywhere... though there WAS one. I spent 12 hours trying to understand book.js... just to figure out at the end that book.js is NOT actually used anymore. It's still part of a core D6 install only because, as I just found out, a patch was not fully applied. http://drupal.org/node/181125 book.js is no longer required. The job is done by FAPI and the new ahah functionality (which is still not documented anywhere), as I mentioned in the other email in this thread.
The it pulls the formId out of the settings and uses jQuery to find the form_build_id input in that form and take it's value, and after that you've got the book id from #edit-book-bid.
Search book.module for drupal_add_js and look for the 'setting' call. I think it'll be more clear after that.
Now that book.js is out of the picture, do I become clearer... :) Blessings, Augustin.
Augustin (Beginner) wrote:
Hello,
See my message to the documentation list about where to document everything ajax, ahax, js, and jquery. http://drupal.org/node/121997
Right now, I am trying hard to understand book.js and ... I just don't get it.
Hi all, I've added a page to document the javascript progressbar Home » Developing for Drupal » Module developer's guide » Javascript, jQuery and AJAX » Javascript in Drupal 5.0 Progressbar http://drupal.org/node/213374 It's my first contribution to the handbook - all constructive criticism appreciated :-) -- Sean Burlington www.practicalweb.co.uk London
participants (5)
-
Augustin (Beginner) -
Earl Miles -
Neil Drumm -
Sean Burlington -
Sean Robertson