diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-07-01 15:37:10 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-07-01 15:37:10 +0000 |
commit | c11cb4ec24479e801076c094f043f2084b344d0c (patch) | |
tree | 5248d25917032a394ec350b65ebde88259168ffe /misc/drupal.js | |
parent | a3d75e547f62174fe9fa2b5c3f9684b620612b00 (diff) | |
download | brdo-c11cb4ec24479e801076c094f043f2084b344d0c.tar.gz brdo-c11cb4ec24479e801076c094f043f2084b344d0c.tar.bz2 |
- Patch #120360 by nedjo: enable AJAX by making all behaviours reattachable.
Diffstat (limited to 'misc/drupal.js')
-rw-r--r-- | misc/drupal.js | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/misc/drupal.js b/misc/drupal.js index 98441c7ec..0c155f7d6 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -1,6 +1,6 @@ // $Id$ -var Drupal = Drupal || { 'settings': {}, 'themes': {}, 'locale': {} }; +var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale': {} }; /** * Set the variable that indicates if JavaScript behaviors should be applied @@ -22,6 +22,43 @@ Drupal.extend = function(obj) { }; /** + * Attach all registered behaviors to a page element. + * + * Behaviors are event-triggered actions that attach to page elements, enhancing + * default non-Javascript UIs. Behaviors are registered in the Drupal.behaviors + * object as follows: + * @code + * Drupal.behaviors.behaviorName = function () { + * ... + * }; + * @endcode + * + * Drupal.attachBehaviors is added below to the jQuery ready event and so + * runs on initial page load. Developers implementing AHAH/AJAX in their + * solutions should also call this function after new page content has been + * loaded, feeding in an element to be processed, in order to attach all + * behaviors to the new content. + * + * Behaviors should use a class in the form behaviorName-processed to ensure + * the behavior is attached only once to a given element. (Doing so enables + * the reprocessing of given elements, which may be needed on occasion despite + * the ability to limit behavior attachment to a particular element.) + * + * @param context + * An element to attach behaviors to. If none is given, the document element + * is used. + */ +Drupal.attachBehaviors = function(context) { + context = context || document; + if (Drupal.jsEnabled) { + // Execute all of them. + jQuery.each(Drupal.behaviors, function() { + this(context); + }); + } +}; + +/** * Encode special characters in a plain-text string for display as HTML. */ Drupal.checkPlain = function(str) { @@ -362,6 +399,8 @@ if (Drupal.jsEnabled) { document.documentElement.className = 'js'; // 'js enabled' cookie document.cookie = 'has_js=1'; + // Attach all behaviors. + $(document).ready(Drupal.attachBehaviors); } /** |