function _fb_connect_add_js in Drupal for Facebook 7.3
Same name and namespace in other branches
- 6.3 fb_connect.module \_fb_connect_add_js()
- 6.2 fb_connect.module \_fb_connect_add_js()
This wrapper function around drupal_add_js() ensures that our settings are added once and only once when needed.
2 calls to _fb_connect_add_js()
- fb_connect_app_init in ./
fb_connect.module - Prepare for fbConnect use. Because a single Drupal might support multiple apps, we don't know in advance which is the fbConnect app.
- fb_connect_fb in ./
fb_connect.module - Implements hook_fb().
File
- ./
fb_connect.module, line 126 - Support for Facebook Connect features
Code
function _fb_connect_add_js($fb_app, $fb) {
$just_once =& drupal_static(__FUNCTION__);
if (fb_is_tab()) {
// Tabs are FBML.
return;
}
if (!isset($just_once)) {
// Drupal is inconsistent about appending a '/' at the end of urls.
$front_url = url('<front>');
$front_url .= substr($front_url, -1) == '/' ? '' : '/';
drupal_add_js(array(
'fb_connect' => array(
'front_url' => $front_url,
'fbu' => fb_facebook_user(),
'uid' => $GLOBALS['user']->uid,
),
), 'setting');
drupal_add_js(drupal_get_path('module', 'fb_connect') . '/fb_connect.js');
$just_once = TRUE;
}
// If we are not the global $_fb_app
if ($fb_app) {
$settings = fb_js_settings();
if (!isset($settings['fb_init_settings']['appId']) || $settings['fb_init_settings']['appId'] != $fb_app->id) {
// Ensure JS initializes with the proper apikey. We may reach this if
// there is no "primary" app.
// @TODO fb.module should have a helper to make this cleaner.
$settings['fb_init_settings']['appId'] = $fb_app->id;
fb_js_settings('apikey', $fb_app->apikey);
fb_js_settings('fbu', fb_facebook_user($fb));
fb_js_settings('fb_init_settings', $settings['fb_init_settings']);
// fb.module will add settings to footer.
}
}
}