You are here

function farm_client_js_deliver in farmOS 7

Page callback for delivering client JS.

This will load the JavaScript file for a client module and output the content as if it were being loaded directly from the web server. This allows the response to include receive the Access-Control-Allow-Origin and other headers added by farm_access_init().

Parameters

string $module: The machine name of the client module.

Return value

NULL|int This function will print the contents of the JavaScript file, if found, and will not return anything. Otherwise, it will return MENU_NOT_FOUND.

1 string reference to 'farm_client_js_deliver'
farm_client_menu in modules/farm/farm_client/farm_client.module
Implements hook_menu().

File

modules/farm/farm_client/farm_client.module, line 81
Farm Client module.

Code

function farm_client_js_deliver($module) {

  // Ask modules for client module info.
  $client_modules = module_invoke_all('farm_client_module_info');

  // If the requested module doesn't exist, or if it doesn't provide JS, bail
  // with a 404.
  if (!(array_key_exists($module, $client_modules) && !empty($client_modules[$module]['js']) && file_exists($client_modules[$module]['js']))) {
    return MENU_NOT_FOUND;
  }

  // Print the contents of the Javascript file and exit.
  drupal_add_http_header('Content-Type', 'application/javascript; utf-8');
  print file_get_contents($client_modules[$module]['js']);
  drupal_exit();
}