Revision: 944
Updated Code
at November 28, 2006 11:33 by kkaefer
Updated Code
In the page header: 26. Vastly extended <code>drupal_add_js()</code> Below: <h2>Vastly extended <code>drupal_add_js()</code></h2> <p>The function to add JavaScript to a Drupal page has been reworked:</p> <h3>Definition</h3> <p><small>drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE)</small><br /> <a href="http://api.drupal.org/api/HEAD/file/includes/common.inc">includes/common.inc</a>, line 1329</p> <h3>Description</h3> <p>Add a JavaScript file, setting or inline code to the page.</p> <p>The behavior of this function depends on the parameters it is called with. Generally, it handles the addition of JavaScript to the page, either as reference to an existing file or as inline code. The following actions can be performed using this function:</p> <ul> <li>Add a file ('core', 'module' and 'theme'): Adds a reference to a JavaScript file to the page. JavaScript files are placed in a certain order, from 'core' first, to 'module' and finally 'theme' so that files, that are added later, can override previously added files with ease.</li> <li>Add inline JavaScript code ('inline'): Executes a piece of JavaScript code on the current page by placing the code directly in the page. This can, for example, be useful to tell the user that a new message arrived, by opening a pop up, alert box etc.</li> <li>Add settings ('setting'): Adds a setting to Drupal's global storage of JavaScript settings. Per-page settings are required by some modules to function properly. The settings will be accessible at Drupal.settings.</li> </ul> <h3>Parameters</h3> <p>$data (optional) If given, the value depends on the $type parameter:</p> <ul> <li>'core', 'module' or 'theme': Path to the file relative to <a href="http://api.drupal.org/api/HEAD/function/base_path" title="Returns the base URL path of the Drupal installation. At the very least, this will always default to /." class="local">base_path</a>().</li> <li>'inline': The JavaScript code that should be placed in the given scope.</li> <li>'setting': An array with configuration options as associative array. The array is directly placed in Drupal.settings. You might want to wrap your actual configuration settings in another variable to prevent the pollution of the Drupal.settings namespace.</li> </ul>$type (optional) The type of JavaScript that should be added to the page. Allowed values are 'core', 'module', 'theme', 'inline' and 'setting'. You can, however, specify any value. It is treated as a reference to a JavaScript file. Defaults to 'module'. <p>$scope (optional) The location in which you want to place the script. Possible values are 'header' and 'footer' by default. If your theme implements different locations, however, you can also use these.</p> <p>$defer (optional) If set to TRUE, the defer attribute is set on the <script> tag. Defaults to FALSE. This parameter is not used with $type == 'setting'.</p> <p>$cache (optional) If set to FALSE, the JavaScript file is loaded anew on every page call, that means, it is not cached. Defaults to TRUE. Used only when $type references a JavaScript file.</p> <h3>Return value</h3> <p>If the first parameter is NULL, the JavaScript array that has been built so far for $scope is returned.</p> In the page header: 27. Removed <code>drupal_call_js()</code> Below: <h3>Removed <code> drupal_call_js()</code></h3> <p>As it is now very easy to attach JavaScript to a page, this function is not needed anymore. Use this syntax instead:</p> <?php drupal_add_js('myCustomFunction(your, parameters, here)', 'inline'); ?> <p>If you have more complex parameters that should be passed to the function, consider using <code>drupal_to_js()</code> to convert them to a JSON object before.</p> <p><strong>Note:</strong> It is recommended to not call functions in the page header directly. Instead use unobtrusive JavaScript that automatically runs when the page is loaded.</p>
Revision: 943
Updated Code
at August 22, 2006 11:19 by kkaefer
Updated Code
In the page header: 26. Vastly extended <code>drupal_add_js()</code> Below: <h2>Vastly extended <code>drupal_add_js()</code></h2> <p>The function to add JavaScript to a Drupal page has been reworked:</p> <h3>Definition</h3> <p><small>drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE)</small><br /> <a href="http://api.drupal.org/api/HEAD/file/includes/common.inc">includes/common.inc</a>, line 1329</p> <h3>Description</h3> <p>Add a JavaScript file, setting or inline code to the page.</p> <p>The behavior of this function depends on the parameters it is called with. Generally, it handles the addition of JavaScript to the page, either as reference to an existing file or as inline code. The following actions can be performed using this function:</p> <ul> <li>Add a file ('core', 'module' and 'theme'): Adds a reference to a JavaScript file to the page. JavaScript files are placed in a certain order, from 'core' first, to 'module' and finally 'theme' so that files, that are added later, can override previously added files with ease.</li> <li>Add inline JavaScript code ('inline'): Executes a piece of JavaScript code on the current page by placing the code directly in the page. This can, for example, be useful to tell the user that a new message arrived, by opening a pop up, alert box etc.</li> <li>Add settings ('setting'): Adds a setting to Drupal's global storage of JavaScript settings. Per-page settings are required by some modules to function properly. The settings will be accessible at Drupal.settings.</li> </ul> <h3>Parameters</h3> <p>$data (optional) If given, the value depends on the $type parameter:</p> <ul> <li>'core', 'module' or 'theme': Path to the file relative to <a href="http://api.drupal.org/api/HEAD/function/base_path" title="Returns the base URL path of the Drupal installation. At the very least, this will always default to /." class="local">base_path</a>().</li> <li>'inline': The JavaScript code that should be placed in the given scope.</li> <li>'setting': An array with configuration options as associative array. The array is directly placed in Drupal.settings. You might want to wrap your actual configuration settings in another variable to prevent the pollution of the Drupal.settings namespace.</li> </ul>$type (optional) The type of JavaScript that should be added to the page. Allowed values are 'core', 'module', 'theme', 'inline' and 'setting'. You can, however, specify any value. It is treated as a reference to a JavaScript file. Defaults to 'module'. <p>$scope (optional) The location in which you want to place the script. Possible values are 'header' and 'footer' by default. If your theme implements different locations, however, you can also use these.</p> <p>$defer (optional) If set to TRUE, the defer attribute is set on the <script> tag. Defaults to FALSE. This parameter is not used with $type == 'setting'.</p> <p>$cache (optional) If set to FALSE, the JavaScript file is loaded anew on every page call, that means, it is not cached. Defaults to TRUE. Used only when $type references a JavaScript file.</p> <h3>Return value</h3> <p>If the first parameter is NULL, the JavaScript array that has been built so far for $scope is returned.</p> In the page header: 27. Removed <code>drupal_call_js()</code> Below: <h3>Removed <code> drupal_call_js()</code></h3> <p>As it is now very easy to attach JavaScript to a page, this function is not needed anymore. Use this syntax instead:</p> <?php drupal_add_js('myCustomFunction(your, parameters, here)', 'inline'); ?> <p>If you have more complex parameters that should be passed to the function, consider using <code>drupal_to_js()</code> to convert them to a JSON object before.</p> <p><strong>Note:</strong> It is recommended to not call functions in the page header directly. Instead use unobtrusive JavaScript that automatically runs when the page is loaded.</p>
Revision: 942
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 22, 2006 11:16 by kkaefer
Initial Code
In the page header: 26. Vastly extended <code>drupal_add_js()</code> Below: <h2>Vastly extended <code>drupal_add_js()</code></h2> <p>The function to add JavaScript to a Drupal page has been reworked:</p> <h3>Definition</h3> <p><small>drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE)</small><br /> <a href="http://api.drupal.org/api/HEAD/file/includes/common.inc">includes/common.inc</a>, line 1329</p> <h3>Description</h3> <p>Add a JavaScript file, setting or inline code to the page.</p> <p>The behavior of this function depends on the parameters it is called with. Generally, it handles the addition of JavaScript to the page, either as reference to an existing file or as inline code. The following actions can be performed using this function:</p> <ul> <li>Add a file ('core', 'module' and 'theme'): Adds a reference to a JavaScript file to the page. JavaScript files are placed in a certain order, from 'core' first, to 'module' and finally 'theme' so that files, that are added later, can override previously added files with ease.</li> <li>Add inline JavaScript code ('inline'): Executes a piece of JavaScript code on the current page by placing the code directly in the page. This can, for example, be useful to tell the user that a new message arrived, by opening a pop up, alert box etc.</li> <li>Add settings ('setting'): Adds a setting to Drupal's global storage of JavaScript settings. Per-page settings are required by some modules to function properly. The settings will be accessible at Drupal.settings.</li> </ul> <h3>Parameters</h3> <p>$data (optional) If given, the value depends on the $type parameter:</p> <ul> <li>'core', 'module' or 'theme': Path to the file relative to <a href="http://api.drupal.org/api/HEAD/function/base_path" title="Returns the base URL path of the Drupal installation. At the very least, this will always default to /." class="local">base_path</a>().</li> <li>'inline': The JavaScript code that should be placed in the given scope.</li> <li>'setting': An array with configuration options as associative array. The array is directly placed in Drupal.settings. You might want to wrap your actual configuration settings in another variable to prevent the pollution of the Drupal.settings namespace.</li> </ul>$type (optional) The type of JavaScript that should be added to the page. Allowed values are 'core', 'module', 'theme', 'inline' and 'setting'. You can, however, specify any value. It is treated as a reference to a JavaScript file. Defaults to 'module'. <p>$scope (optional) The location in which you want to place the script. Possible values are 'header' and 'footer' by default. If your theme implements different locations, however, you can also use these.</p> <p>$defer (optional) If set to TRUE, the defer attribute is set on the <script> tag. Defaults to FALSE. This parameter is not used with $type == 'setting'.</p> <p>$cache (optional) If set to FALSE, the JavaScript file is loaded anew on every page call, that means, it is not cached. Defaults to TRUE. Used only when $type references a JavaScript file.</p> <h3>Return value</h3> <p>If the first parameter is NULL, the JavaScript array that has been built so far for $scope is returned.</p> In the page header: 27. Removed <code>drupal_call_js()</code> Below: <h3>Removed <code> drupal_call_js()</code> <p>As it is now very easy to attach JavaScript to a page, this function is not needed anymore. Use this syntax instead:</p> <?php drupal_add_js('myCustomFunction(your, parameters, here)', 'inline'); ?> <p>If you have more complex parameters that should be passed to the function, consider using <code>drupal_to_js()</code> to convert them to a JSON object before.</p> <p><strong>Note:</strong> It is recommended to not call functions in the page header directly. Instead use unobtrusive JavaScript that automatically runs when the page is loaded.</p>
Initial URL
Initial Description
Initial Title
Docs for drupal_add_js()
Initial Tags
drupal
Initial Language
HTML