The current functionality loads any active library on every page, but a common use case is JS inside a block referencing a library where the block only appears on one or a few pages. In order to conditionally load JS, one would have to use PHP in the block to call drupal_add_js(), or hard-code the link to the JS in the markup (losing the advantage of e.g. loading the JS in the page footer).

The suggested feature is to allow within each block config page the selection of one or more of the libraries that is otherwise inactive (i.e. not loaded on every page).

As far as implementation, this module could use hook_block_view_alter() to add the JS for each configured block.

Note there would probably need to be some method for resolving conflicting config (one block nees the libread in the HEAD, another in the footer), or perhaps we could enforce some simplifying assumptions such as putting all block-level JS in the footer?

Comments

pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new3.38 KB

This does most of what we need.

pwolanin’s picture

StatusFileSize
new95.91 KB
new3.42 KB

This patch put the settings in a separate fieldset. Here's a screen shot too.

pwolanin’s picture

StatusFileSize
new3.43 KB
new64.46 KB

Alternative version + screenshot putting this into the vertical tabs with for visibility. There is some logic grouping them together since no JS library should be enabled here unless you have configured one of the other visibility settings.

pwolanin’s picture

StatusFileSize
new5.77 KB

Also tweak the admin page to indicate a library is enabled for certain blocks.

pwolanin’s picture

StatusFileSize
new69.97 KB

Here's a screen shot of the admin page

pwolanin’s picture

Status: Needs review » Fixed

committed this patch. open a new issue for follow-ups

Status: Fixed » Closed (fixed)

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