You are here

function fb_add_js in Drupal for Facebook 5.2

Same name and namespace in other branches
  1. 5 fb.module \fb_add_js()
  2. 6.2 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.

See http://wiki.developers.facebook.com/index.php/Include_files

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

File

./fb.module, line 752

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('', NULL, NULL, TRUE);
    drupal_add_js(array(
      'fbjs' => array(
        'baseUrlFb' => $baseUrl,
        'baseUrl' => fb_scrub_urls($baseUrl),
      ),
    ), 'setting', 'fbml');
  }
  if ($filename && !$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;
  }
}