Currently, Core’s JavaScript files are added in the module scope. This patch moves them to the core section.
| Comment | File | Size | Author |
|---|---|---|---|
| core-javascript.patch | 2.18 KB | kkaefer |
Currently, Core’s JavaScript files are added in the module scope. This patch moves them to the core section.
| Comment | File | Size | Author |
|---|---|---|---|
| core-javascript.patch | 2.18 KB | kkaefer |
Comments
Comment #1
profix898 commentedPatch looks good and moves the core js to where it belongs ... and thus enables modules to override core's js.
Comment #2
dries commentedI 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'?
Comment #3
profix898 commentedThe patch that introduced the new
drupal_add_js()function was http://drupal.org/node/76637Here is an abstract from that issue:
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.
Comment #4
dries commentedYep, 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'.
Comment #5
kkaefer commentedThe reason we have
core,moduleandthemefor JavaScript files is simple: Modules could rely oncoreJavaScript files to be present (such as jQuery ordrupal.js).coreJavaScript files are inserted beforemodulefiles are inserted.Comment #6
profix898 commentedI'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)?Comment #7
adminfor@inforo.com.ar commentedHi, 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
Comment #8
drummWhy is upload core?
Comment #9
panchoToo late for D6. Bumping to D7. Also changing to task.
Comment #10
casey commentedWe 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'.