Currently, Core’s JavaScript files are added in the module scope. This patch moves them to the core section.

CommentFileSizeAuthor
core-javascript.patch2.18 KBkkaefer

Comments

profix898’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good and moves the core js to where it belongs ... and thus enables modules to override core's js.

dries’s picture

I don't really have an opinion on this one. Can't other modules overwrite these when they are in the module-scope?

Looking at the implementation of drupal_add_js() and drupal_get_js() it is not clear why we differentiate between 'core' and 'module'. It doesn't seem to be documented properly.

Looking at the PHPdoc of drupal_add_js(), it is not clear what is meant with "The type of JavaScript that should be added to the page". Maybe we can extend this patch to clarify that a little? The documentation should mention 'how' and 'why' to use $type (i.e. practical advice that is useful for the developer).

If it has everything to do with the javascript files to be overwritable, then it should be documented.

That said, it looks rather arbitrary. As demonstrated by this patch ... maybe the better solution is to get rid of type 'core', 'theme' and 'module'?

profix898’s picture

The patch that introduced the new drupal_add_js() function was http://drupal.org/node/76637
Here is an abstract from that issue:

It now uses the same system as drupal_add_css() (different 'layers').

Adds a reference to a JavaScript file to the page header. JavaScript files are placed in a certain order from 'core' first, to 'module' and finally 'theme' so that files that are later added, can override previously added files with ease.

Not sure this is really useful, but since that got committed the residual calls should be moved into 'core' scope consequentially. I guess kkaefer is more capable of explaining things behind this idea ... and I agree a more detailed documentation on that could be helpful.

dries’s picture

Status: Reviewed & tested by the community » Needs work

Yep, so let's figure out why this is important, document it, and use the documentation to clean-up the calls in core. I'll mark this 'code needs work'.

kkaefer’s picture

Status: Needs work » Needs review

The reason we have core, module and theme for JavaScript files is simple: Modules could rely on core JavaScript files to be present (such as jQuery or drupal.js). core JavaScript files are inserted before module files are inserted.

profix898’s picture

I'm not a javascript expert, so please be gentle ;)
The question is: If you want to execute javascript within a page (by user (inter)-action), it is irrelevant in which order the js sources were added as long as they are available. The only point were order comes into focus is the autoAttach or $(document).ready(...) thing, right!? If you call $(document).ready(...) in (say) 3 different files, in which order are the functions called from jQuery then? In order they were added? Or in alphabetical order? In the last cases, the 'layers' concept was useless. Aside from that, are autoAttach calls ever dependent on each other (e.g. must autoAttach for fieldsets be executed before the one for autocomplete)?

adminfor@inforo.com.ar’s picture

Hi, first off all, I want to introduce me: I´m really new in PHP and Drupal (and, english is no my first language also :)
I´ve posted an issue 2 days ago and was finally fixed with a workaround. The issue is already open because some malfunction in drupal_add_js (I guess). I've heard you talked about core´s drupal_add_js. Please, could someone experienced take a look in drupal_add_js in order to confirm if is necessary the issue and to prevent future problems. The issue was posted in http://drupal.org/node/90302 .
Thanks in advance,
Gustavo

drumm’s picture

Version: x.y.z » 6.x-dev
Status: Needs review » Needs work

Why is upload core?

pancho’s picture

Version: 6.x-dev » 7.x-dev
Category: bug » task

Too late for D6. Bumping to D7. Also changing to task.

casey’s picture

Status: Needs work » Fixed

We have some constants for this now: http://api.drupal.org/api/function/drupal_add_js/7

Available constants are:

* JS_LIBRARY: Any libraries, settings, or jQuery plugins.
* JS_DEFAULT: Any module-layer JavaScript.
* JS_THEME: Any theme-layer JavaScript.

As @Dries suggested per #2: we got rid of type 'core', 'theme' and 'module'.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.