You are here

function fb_add_js in Drupal for Facebook 6.2

Same name and namespace in other branches
  1. 5.2 fb.module \fb_add_js()
  2. 5 fb.module \fb_add_js()

Helper function for FBJS files.

Useful for adding Facebook Javascript, which will be incorporated into canvas pages or profile boxes. When included this way, javascript must be embedded inline, rather than refer to an external URL. So this function will actually read a local file and include the contents inline.

2 calls to fb_add_js()
fb_ahah_bind_form in ./fb_form.module
Support for AHAH in forms.
fb_canvas_footer in ./fb_canvas.module
Implementation of hook_footer().

File

./fb.module, line 907

Code

function fb_add_js($filename, $type) {
  static $cache;
  if (!$cache) {
    $cache = array();

    // Add the most basic file we need.
    $base_file = drupal_get_path('module', 'fb') . '/fb_fbml.js';
    $base_file .= "?v=" . filemtime($base_file);
    drupal_add_js($base_file, 'module', 'fbml');

    // Add some settings that FBJS code will often need.
    $baseUrl = url('', array(
      'absolute' => TRUE,
    ));
    drupal_add_js(array(
      'fbjs' => array(
        'baseUrlFb' => $baseUrl,
        'baseUrl' => fb_scrub_urls($baseUrl),
      ),
    ), 'setting', 'fbml');
  }
  if (!$cache[$filename]) {
    if (file_exists($filename)) {

      // Refresh facebook's cache when file changes
      $filename .= "?v=" . filemtime($filename);
    }

    // 'post_settings' is a hack to make our code come after settings. This is
    // ugly, but we're doing it because there is no "onready" in FBJS.
    drupal_add_js($filename, 'post_settings', 'fbml');
    $cache[$filename] = TRUE;
  }
}