Experimental project

This is a sandbox project, which contains experimental code for developer use only.

from the project README:

Simple AJAX
-----------
Note: this module currently only works with html5 themes since it relies on the data-attributes parameters.

This module does nothing on it's own. It provides a simple way to load nodes, blocks, users and views via ajax. Links must have a class "simple_ajax" to be processed. They also must have some data attributes.

Node:
This will replace the $("#main-wrapper .content") html with the node 5 rendered using the "teaser" view_mode
< a href="node/5" class='simple_ajax' data-nid="5" data-view_mode="teaser" data-target="#main-wrapper .content" data-method='html'>node 5< /a>

User:
This will replace the $("#main-wrapper .content") html with the user 1 rendered using the "full" view_mode
< a href="user/1" class='simple_ajax' data-uid="1" data-view_mode="full" data-target="#main-wrapper .content" data-method='html'>user 1< /a>

Block:
This will append a block (module = "user", delta = "login") to the $("#main-wrapper .content") content
< a href="user/login" class='simple_ajax' data-module="user" data-delta="login" data-target="#main-wrapper .content" data-method='append'>login< /a>

View:
This will append a view (system name = "news", display_id = "default") to the $("#main-wrapper .content") content
< a href="news" class='simple_ajax' data-name="news" data-display_id="default" data-target="#main-wrapper .content" data-method='append'>news< /a>


AJAX call without link (javascript API)
---------------------------------------

You may need to do ajax calls without relying on links. Think about auto updating blocks for instance. There are 4 javascript methods:
Drupal.behaviors.simple_ajax.node_load(nid, view_mode, target, method, langcode = null);
Drupal.behaviors.simple_ajax.user_load(uid, view_mode, target, method);
Drupal.behaviors.simple_ajax.block_load(module, delta, target, method);
Drupal.behaviors.simple_ajax.view_load(name, display_id, target, method);

To load the node 1 with teaser view mode in $(".ajax-target")
Drupal.behaviors.simple_ajax.node_load(1, "teaser", ".ajax-target", "html");

other examples:
Drupal.behaviors.simple_ajax.block_load("user", "login", ".ajax-target", "html");
Drupal.behaviors.simple_ajax.view_load("news", "default", ".ajax-target", "html");
Drupal.behaviors.simple_ajax.user_load(1, "teaser", ".ajax-target", "html");


Transforming links with javascript
----------------------------------

If you manually transform or create links with javascript you may need to directly call the attach function:
$("body").append("<a href='node/1' class='simple_ajax' data-nid='1' data-view_mode='full' data-target='#main-content .inner' data-method='html'>node1</a>");
Drupal.behaviors.simple_ajax.attach($("body"));

Other AJAX modules:

Ajax Blocks (http://drupal.org/project/ajaxblocks)
- only blocks
- 6.x and 7.x versions

AJAXify (http://drupal.org/project/ajaxify)
- 5.x only

Ajax (http://drupal.org/project/ajax)
- 6.x only
- Focus on forms only

Ajax Load (http://drupal.org/project/ajax_load)
- 6.x but no 7.x release yet
- very general. Takes care of loading css and js like it is handled in core now.

Ajax regions (http://drupal.org/project/ajax_regions)
- 7.x only
- simply reload regions via ajax

Project information

  • Created by idflood on , updated