You are here

function fb_add_js in Drupal for Facebook 5

Same name and namespace in other branches
  1. 5.2 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. 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.

1 call to fb_add_js()
fb_ahah_bind_form in ./fb_form.module
Support for AHAH in forms.

File

./fb.module, line 664

Code

function fb_add_js($filename) {
  static $cache;
  if (!$cache) {

    // Add some settings
    $baseUrl = url('', NULL, NULL, TRUE);
    drupal_add_js(array(
      'fbjs' => array(
        'baseUrlFb' => $baseUrl,
        'baseUrl' => fb_scrub_urls($baseUrl),
      ),
    ), 'setting', 'fbjs');
    $cache = array();
  }
  if (!$cache[$filename]) {
    $fh = fopen($filename, 'r');
    $js = fread($fh, filesize($filename));
    fclose($fh);
    drupal_add_js($js, 'inline', 'fbjs');
    $cache[$filename] = TRUE;
  }
}