I have set up a Drupal 7 web site with a few custom blocks and menus written by me.
I have a non-Drupal PHP script displaying users (some of them are external, i.e. not stored in drupal tables) as a table with the DataTables jQuery plugin.
I would like to rewrite that script as a Drupal menu, so that it can be called as http://preferans.de/top.
The content of my.module is the following.
function my_menu() {
$items['top'] = array (
'title' => 'Top',
'description' => 'Top',
'page callback' => 'my_top_callback',
'access callback' => TRUE,
'file' => 'my.top.inc',
'file path' => drupal_get_path('module', 'my'),
'type' => MENU_CALLBACK,
);
return $items;
}
The content of my.top.inc is the following.
function my_top_callback() {
return array (
'top_table' => array (
'#type' => 'markup',
'#markup' => generate_html_table_with_php(),
),
);
}
My problem is that I don't understand how to add the CSS and JavaScript code, so that it is available for the /top page, but not for any other Drupal paths.
I should probably call:
drupal_add_css('/demo_table_jui.css', 'file');
drupal_add_css('/smoothness/jquery-ui-1.8.4.custom.css', 'file');
drupal_add_js('/jquery.dataTables.min.js', 'file');
drupal_add_js('
$(document).ready(function() {
$("#rating").dataTable( {
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
', 'inline');
(Please see the head-section of my original non-Drupal script).
How do I limit these calls to the /top page and where should I perform these calls? Should I put them in a hook, or by adding some properties to my menu?
'file path'
is not necessary, if the file is inside the directory containing the module that defines the menu callback.