| 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 |
|