/[drupal]/contributions/modules/fb/fb_ahah_forms.js
ViewVC logotype

Contents of /contributions/modules/fb/fb_ahah_forms.js

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Jul 10 06:38:21 2008 UTC (16 months, 2 weeks ago) by yogadex
Branch: MAIN
CVS Tags: DRUPAL-5--0-1, DRUPAL-5--0-2, HEAD
Branch point for: DRUPAL-5, DRUPAL-5--2
File MIME type: text/javascript
Initial support for AHAH in forms in FBML.  Using FBJS and an abstraction layer similar to that used in the ahah_forms module.
1
2 /**
3 * The FBJS code here is based on ahah_forms.js. This code is somewhat
4 * limited by restrictions of Facebook Javascript. For instance, we cannot
5 * support the selector options of the original ahah_forms module. Only where
6 * the element and target are specified by id will this work.
7 */
8
9 var Ahah = Ahah || {};
10
11 Ahah.update = function(e) {
12
13 e.preventDefault(); // prevent click from submitting.
14 var target = e.target;
15 var element = target.fb_ahah_element;
16 var wrapper = document.getElementById(element.wrapper);
17 var imgSrc = Drupal.settings.fbjs.baseUrl + Drupal.settings.ahah.basePaths['module'] + '/lib/loading.gif';
18
19 // let user know something is going on
20 e.target.setDisabled(true);
21
22 wrapper.setStyle('opacity', '0.3');
23
24 var progress = document.createElement('div').setClassName('ahah_progress').setStyle({position: 'absolute', opacity: '1'});
25 progress.setInnerXHTML('<img src="' + imgSrc + '" />');
26 wrapper.insertBefore(progress);
27
28 var uri = Drupal.settings.fbjs.baseUrlFb + element.path;
29
30 var ajax = new Ajax();
31 ajax.responseType = Ajax.RAW;
32 ajax.onerror = function() {
33 new Dialog().showMessage("onerror called!", 'foo');
34 };
35
36 ajax.ondone = function(data) {
37 // Can't use e.target here.
38 target.setDisabled(false);
39 wrapper.setStyle({opacity: '1'});
40
41 wrapper.setInnerXHTML(data);
42 //new Dialog().showMessage("ondone called!", data);
43
44 // In case the new data includes AHAH elements, we need to process them again
45 Ahah.attach_all_bindings();
46 };
47
48 // TODO: make requireLogin dynamic
49 //ajax.requireLogin = false;
50 ajax.post(uri);
51 };
52
53
54 Ahah.attach_to_element = function(element) {
55 // The original ahah_forms supported versatile selectors. In facebook, we can only find elements by id.
56 if (element.id) {
57 var elem_id = element.id;
58 var elem = document.getElementById(elem_id);
59 if (!elem.fb_ahah_element) {
60 // Store data that we'll need during the event.
61 elem.fb_ahah_element = element;
62 // Make sure we are called during the event.
63 elem.addEventListener(element.event, Ahah.update);
64 }
65 }
66 };
67
68 /**
69 * Attach listeners to all elements
70 */
71 Ahah.attach_all_bindings = function( ) {
72 var element;
73 // Drupal.ahah.elements is an array of arrays of elements
74 for (var i in Drupal.settings.ahah.bindings ) {
75 for (var j in Drupal.settings.ahah.bindings[i] ) {
76 if (!isNaN(j)) {
77 element = Drupal.settings.ahah.bindings[i][j];
78 if (element) {
79 Ahah.attach_to_element( element );
80 }
81 }
82 }
83 }
84 };
85
86
87 Ahah.attach_all_bindings();
88 //new Dialog().showMessage("fbjs is alive", "foo");
89

  ViewVC Help
Powered by ViewVC 1.1.2