Reference #947710: Only add misc/collapse.js when needed..

Attached patch replaces 42 lines of code with one single line of code. You can simple use the #attached property to attach any javascript or css to any Form API item.

On top of this, the old method was not actually working on one site I tried this on.

Note this is Drupal 7 only.

Comments

mstrelan’s picture

StatusFileSize
new2.14 KB

It would appear that the theme function is only called after a cache flush because the filter is cached (obviously). This means you can't add the JS in the theme function, which I'm sure you already discovered, hence doing the preprocess.

I would suggest just add the JS on every page. It's going to be much more reliable and is only 3KB, and should be aggregated on production sites anyway. It also reduces the number of aggregate files that are created if the JS is on every page.

pukku’s picture

At this point, I agree. It's getting to be more trouble than it's worth to not include the file.

I'm going to push a new version shortly with this change.

Thanks,
Ricky

pukku’s picture

Assigned: Unassigned » pukku
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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