Drupal 7 and ajax menu


Have you faced such a problem when you need to create a simple-simple ajax menu on a simple-simple website (Drupal 7)? You have a blog, you quickly assembled it from the modules, but here you have the ajax menu. And so we create a custom module, like this , attach event handlers to the menu links, send an ajax request, form a response on the server side, and again manually process the receipt of this response. Or we use the wonderful module of comrade Nick Denry, this one , but here the author writes in the last comment - “Currently, the module supports only the Basic Page type, the module is limited in its application. There are plans to finalize the module, but so far there is no time for their implementation, unfortunately. ”

Is it possible to make such a module on drupal 7, with which it would be possible to configure the usual ajax menu by writing a minimum of code?

  • Suppose this module should be universal for different themes, for different menu positions. Suppose that all CSS menu link selectors that should be processed by our module are specified in the module settings.
  • Assume that the structure of the pages of sites is also different. Blogs are different. Some ajax menus reload the content and for example leave the column on the right untouched; other ajax menus also update the column along with the content. There are many options, too, but let there be a second such setting in our module - areas reloaded by Ajax.
  • Do not forget also that on some sites the ajax-menu imitates a reboot by the browser, and on some not. Somewhere the address bar is updated, somewhere it is not updated. These two settings, in the presence of the first two, will not be difficult to add to our module.


I present to you the Ajax Regions module .
All module settings are collected on one module configuration page (admin / config / system / ajax_regions):
Ajax Regions module settings page

Perhaps, if you read the second paragraph above, you wondered in what form the “Ajax reloaded area” is indicated in the module settings. In the Ajax Regions module, you need to specify a set of names of drupal regions and their CSS selectors (selectors, of course, are also different for the same regions on different sites), in the form of a JSON object: {"region name1": " selector1 ”,“ name of region2 ”:“ selector2 ”...}. Each region, when processing an ajax request, will be placed in its own selector, and thus, we will be able to regulate what to do with the columns, whether it is worth updating them with the content, or not! If it is, then the regions of the columns should be placed in this JSON object, together with the region of the content.

For one ajax-menu, one line in the settings table of this module is usually enough. But if you have several ajax-menus, or you want to similarly handle internal links in the content, or within the same ajax-menu different links should behave fundamentally different, then you can create several lines.

As promised in the third paragraph, there are a couple of additional settings that often differ in different ajax-menus:

SET LOADING-INDICATOR - imitation of the page reload indicator by browser
UPDATE DOCUMENT TITLE - update the title of the page
UPDATE CURRENT ADDRESS - update the address bar of the browser
UPDATE ACTIVE LINKS - set the active link to the class “active” (useful for the standard Bartik theme)

As well as js-functions preceding and following ajax-loading, just in case .
Drupal.ajax_regions.before = function(link) {

Drupal.ajax_regions.after = function(link, response) {

Also popular now: