Integrating JavaScript to Drupal 7 – GSoC – week #10

The retriview events from tables was success.s the integrating timelineJS was taken place through out the week. But it wasn’t success.

The simplest method to add JavaScript and CSS to a page is by adding them to the
.info files for a module. When JavaScript and CSS files are specified in a .info file they
are added to all pages and configured to use preprocessing (more on that later). An
example that adds a script and CSS file looks like:
scripts[] = foo.js
stylesheets[screen][] = bar.css

The most common method of adding JavaScript to a page is by using the function
drupal_add_js(). This utility function provides the ability to add files (both
external to Drupal and within the file system), add inline JavaScript, and pass
variables between PHP and JavaScript.

Adding a file is the default behavior of drupal_add_js() and drupal_add_css()Adding a JavaScript file and a CSS file to a page would look like the following:

$path = drupal_get_path(‘module’, ‘hello_world’);
drupal_add_js($path . ‘/hello_world.js’);
drupal_add_css($path . ‘/hello_world.css’);

 

Drupal provides a means of passing variables from PHP to JavaScript using
drupal_add_js(). Many applications want to pass configuration information
to JavaScript that runs on a page. This function is the means in Drupal to pass
that information easily.
Drupal calls the variables passed from PHP to JavaScript settings. A simple example
of a setting that passes the text “Hello World!” from PHP to JavaScript would
look like:
drupal_add_js(array(‘helloWorld’ => “Hello World!”), ‘setting’); 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s