You are here

function js_injector_init in JS injector 7

Same name and namespace in other branches
  1. 6.2 js_injector.module \js_injector_init()
  2. 6 js_injector.module \js_injector_init()
  3. 7.2 js_injector.module \js_injector_init()

Implements hook_init(). Checks to see whether any JS files should be added to the current page, based on rules configured by the site administrator.

File

./js_injector.module, line 47
Allows administrators to inject JS into the page output based on configurable rules. Useful for adding simple JS tweaks without modifying a site's official theme.

Code

function js_injector_init() {
  $js_rules = _js_injector_load_rule();
  foreach ($js_rules as $js_rule) {
    if (_js_injector_evaluate_rule($js_rule)) {
      $filepath = _js_injector_rule_path($js_rule['crid']);
      drupal_add_js($filepath, array(
        'type' => 'file',
        'group' => JS_THEME,
        'media' => $js_rule['media'],
        'preprocess' => $js_rule['preprocess'],
      ));
    }
  }
}