Drupal 7 API Change notification: JavaScript loading techniques (use drupal_add_library())
*We try to notify this list when API changes are made in Drupal 7, so contrib and custom developers have a chance to fix their code before they have the pain of figuring out why it's broken. * (issue <http://drupal.org/node/954804>) Contrib modules should not use drupal_add_js() for core JavaScript files (which are all now packaged as libraries). Instead, use drupal_add_library(). Failure to do this can mess up the weighting of javascript files. This is true of any JS file that is included in a library: use the library to load it. You may also be interested in general JS/CSS loading<http://drupal.org/update/modules/6/7#js_css_loading_change>upgrade information, and also in the D7 Javascript Handbook Page <http://drupal.org/node/756722>. Thanks, -Randy -- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
On Dec 12, 2010, at 1:22 PM, Randy Fay wrote:
(issue) Contrib modules should not use drupal_add_js() for core JavaScript files (which are all now packaged as libraries).
Which files are affected by this? -Mike __________________ Michael Prasuhn mike@mikeyp.net http://mikeyp.net
Looking through the patch in #12<http://drupal.org/node/954804#comment-3751412>, I see: + $libraries['drupal.ajax'] = array( + 'js' => array( + 'misc/ajax.js' => array('group' => JS_LIBRARY, 'weight' => 2), + ), + 'dependencies' => array( + array('system', 'drupal.progress'), + ), + ); + + // Drupal's batch API. + $libraries['drupal.batch'] = array( + 'title' => 'Drupal batch API', + 'version' => VERSION, + 'js' => array( + 'misc/batch.js' => array('cache' => FALSE), + ), + 'dependencies' => array( + array('system', 'drupal.progress'), + ), + ); + + // Drupal's progress indicator. + $libraries['drupal.progress'] = array( + 'title' => 'Drupal progress indicator', + 'version' => VERSION, + 'js' => array( + 'misc/progress.js' => array('cache' => FALSE), + ), + ); + + // Drupal's form library. + $libraries['drupal.form'] = array( + 'title' => 'Drupal form library', + 'version' => VERSION, + 'js' => array( + 'misc/form.js' => array('group' => JS_LIBRARY, 'weight' => 1), + ), + ); + + // Drupal's states library. + $libraries['drupal.states'] = array( + 'title' => 'Drupal states', + 'version' => VERSION, + 'js' => array( + 'misc/states.js' => array('group' => JS_LIBRARY, 'weight' => 1), + ), + ); + + // Drupal's collapsible fieldset. + $libraries['drupal.collapse'] = array( + 'title' => 'Drupal collapsible fieldset', + 'version' => VERSION, + 'js' => array( + 'misc/collapse.js' => array(), + ), + 'dependencies' => array( + // collapse.js relies on drupalGetSummary in form.js + array('system', 'drupal.form'), + ), + ); + + // Drupal's resizable textarea. + $libraries['drupal.textarea'] = array( + 'title' => 'Drupal resizable textarea', + 'version' => VERSION, + 'js' => array( + 'misc/textarea.js' => array(), + ), + ); + + // Drupal's autocomplete widget. + $libraries['drupal.autocomplete'] = array( + 'title' => 'Drupal autocomplete', + 'version' => VERSION, + 'js' => array( + 'misc/autocomplete.js' => array(), + ), + ); + // jQuery. $libraries['jquery'] = array( 'title' => 'jQuery', @@ -1087,7 +1170,7 @@ function system_library() { ); // jQuery Once. - $libraries['once'] = array( + $libraries['jquery.once'] = array( 'title' => 'jQuery Once', 'website' => 'http://plugins.jquery.com/project/once', 'version' => '1.2', @@ -1097,7 +1180,7 @@ function system_library() { ); // jQuery Form Plugin. - $libraries['form'] = array( + $libraries['jquery.form'] = array( 'title' => 'jQuery Form Plugin', 'website' => 'http://malsup.com/jquery/form/', 'version' => '2.49', @@ -1107,7 +1190,7 @@ function system_library() { ); // jQuery BBQ plugin. - $libraries['jquery-bbq'] = array( + $libraries['jquery.bbq'] = array( 'title' => 'jQuery BBQ', 'website' => 'http://benalman.com/projects/jquery-bbq-plugin/', 'version' => '1.2.1', @@ -1117,7 +1200,7 @@ function system_library() { ); // Vertical Tabs. - $libraries['vertical-tabs'] = array( + $libraries['drupal.vertical-tabs'] = array( 'title' => 'Vertical Tabs', 'website' => 'http://drupal.org/node/323112', 'version' => '1.0', @@ -1127,6 +1210,10 @@ function system_library() { 'css' => array( 'misc/vertical-tabs.css' => array(), ), + 'dependencies' => array( + // Vertical tabs relies on drupalGetSummary in form.js + array('system', 'drupal.form'), + ), ); // Farbtastic. @@ -1143,7 +1230,7 @@ function system_library() { ); // Cookie. - $libraries['cookie'] = array( + $libraries['jquery.cookie'] = array( 'title' => 'Cookie', 'website' => 'http://plugins.jquery.com/project/cookie', 'version' => '1.0', @@ -1533,6 +1620,15 @@ function system_library() { ), ); + // These library names are deprecated. Earlier versions of Drupal 7 didn't + // consistently namespace their libraries, so these names are included for + // backwards compatibility with those versions. + $libraries['once'] = &$libraries['jquery.once']; + $libraries['form'] = &$libraries['jquery.form']; + $libraries['jquery-bbq'] = &$libraries['jquery.bbq']; + $libraries['vertical-tabs'] = &$libraries['drupal.vertical-tabs']; + $libraries['cookie'] = &$libraries['jquery.cookie']; + return $libraries; } On Sun, Dec 12, 2010 at 2:34 PM, Michael Prasuhn <mike@mikeyp.net> wrote:
On Dec 12, 2010, at 1:22 PM, Randy Fay wrote:
(issue) Contrib modules should not use drupal_add_js() for core JavaScript files (which are all now packaged as libraries).
Which files are affected by this?
-Mike __________________ Michael Prasuhn mike@mikeyp.net http://mikeyp.net
-- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
I'm using the ajax contrib module to add ajax to a simple newsletter form. The current module seems to return the status message to the form, not into the regular message div at the top of the page. Is there any way to change where the status message appears on returning? Drupal 6.19 Ajax 6.x-1.14 -Don-
participants (3)
-
Don -
Michael Prasuhn -
Randy Fay