computerminds/cm_tools — pull request #12 by jamsilver (2013-08-08 10:35:27+00:00)
Title: Add AjaxOperation framework

So basically this adds the gubbins for making custom Ajax requests to the server from javascript without particularly being in the context of a DOM element in the way Drupal.ajax assumes.

It also adds the server-side gubbins for specifying what should happen on this ajax request and what ajax commands should be returned.

See the PHPDoc at the top of includes/ajax_operations.inc for full details of how it all works.

The use case I am in which is using this is:

1. We have been provided with a flatbuild which has a custom jQueryUI tabs widget, it does an ajax request to get the contents of the request.

2. By swapping out it's call to jQuery.ajax() with CMToolsAjaxOperation() we get a couple of important bits of functionality for free that come with the Drupal Ajax framework:

- Auto-loading of any extra CSS and Javascript needed to display the tab not already on the page (very important)
- The ability to communicate in ajax commands - e.g. allowing arbitrary other functionality to be added/altered onto the ajax response

3. Through judicious use of the direct callback functionality/command which CMToolsAjaxOperation supports it wasn't even that difficult to swap out the call to jQuery.ajax() with Drupal.CMToolsAjaxOperation!!