/[drupal]/contributions/modules/ahah_helper/ahah_helper.js
ViewVC logotype

Contents of /contributions/modules/ahah_helper/ahah_helper.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Fri Aug 29 18:58:21 2008 UTC (14 months, 3 weeks ago) by wimleers
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, DRUPAL-6--2-0, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/javascript
Initial commit of the AHAH helper module. By using this module, you will no longer have to write menu callbacks, you'll be able to write functional tests even for #ahah-powered form items, graceful degradation becomes easy and adding new #ahah-powered form items in an AHAH callback becomes supported. No core hacks. Sponsored by Mollom.
1 // $Id$
2
3 (function($) {
4
5 if (Drupal.jsEnabled) {
6 $(document).ready(function() {
7 if (Drupal.ahah != undefined) {
8
9 /**
10 * Override of Drupal.ahah.prototype.success. The only difference is that we
11 * allow for new Drupal.settings.
12 */
13 Drupal.ahah.prototype.success = function (response, status) {
14 var wrapper = $(this.wrapper);
15 var form = $(this.element).parents('form');
16 // Manually insert HTML into the jQuery object, using $() directly crashes
17 // Safari with long string lengths. http://dev.jquery.com/ticket/1152
18 var new_content = $('<div></div>').html(response.data);
19
20 // Restore the previous action and target to the form.
21 form.attr('action', this.form_action);
22 this.form_target ? form.attr('target', this.form_target) : form.removeAttr('target');
23 this.form_encattr ? form.attr('target', this.form_encattr) : form.removeAttr('encattr');
24
25 // Remove the progress element.
26 if (this.progress.element) {
27 $(this.progress.element).remove();
28 }
29 if (this.progress.object) {
30 this.progress.object.stopMonitoring();
31 }
32 $(this.element).removeClass('progress-disabled').attr('disabled', false);
33
34 // Add the new content to the page.
35 Drupal.freezeHeight();
36 if (this.method == 'replace') {
37 wrapper.empty().append(new_content);
38 }
39 else {
40 wrapper[this.method](new_content);
41 }
42
43 // Immediately hide the new content if we're using any effects.
44 if (this.showEffect != 'show') {
45 new_content.hide();
46 }
47
48 // Determine what effect use and what content will receive the effect, then
49 // show the new content. For browser compatibility, Safari is excluded from
50 // using effects on table rows.
51 if (($.browser.safari && $("tr.ahah-new-content", new_content).size() > 0)) {
52 new_content.show();
53 }
54 else if ($('.ahah-new-content', new_content).size() > 0) {
55 $('.ahah-new-content', new_content).hide();
56 new_content.show();
57 $(".ahah-new-content", new_content)[this.showEffect](this.showSpeed);
58 }
59 else if (this.showEffect != 'show') {
60 new_content[this.showEffect](this.showSpeed);
61 }
62
63 // Merge in new and changed settings, if any.
64 if (response.settings) {
65 $.extend(Drupal.settings, response.settings);
66 }
67
68 // Attach all javascript behaviors to the new content, if it was successfully
69 // added to the page, this if statement allows #ahah[wrapper] to be optional.
70 if (new_content.parents('html').length > 0) {
71 Drupal.attachBehaviors(new_content);
72 }
73
74 Drupal.unfreezeHeight();
75 };
76
77 }
78 });
79 }
80
81 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2