You can add your js through drupal_add_js()
function. You can control on which pages this js should be added by implementing different hook and calling drupal_add_js()
function in those hooks:
1) Use drupal_add_js() in hook_init() if you want to add this js on all drupal pages.
function mymoduel_init() {
drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/mymodule.js');
}
2) Use drupal_add_js() in hook_node_view() with content type condition check if you want to add this js on only specific content types.
function mymodule_node_view($node, $view_mode, $langcode) {
if($node->type == 'my_content_type') {
$node->content['#attached']['js'][] = array (
'type' => 'file',
'data' => drupal_get_path('module', 'mymodule') . '/js/mymodule.js',
);
}
}
3) Use drupal_add_js() in module's preprocess function if you want to add this js only on specific node
function mymodule_preprocess_page(&$variables) {
if (isset($variables['node']) && $variables['node']->nid == 'your node nid') {
// Add js
drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.awesome.js');
}
}
You can implement this preprocess_page at theme level like mytheme_preprocess_page($variable) in theme's template.php file.