I have to include an external javascript file as part of a Drupal project I’m working on.
Unfortunately, this external file doesn’t make correct use of closures, for example:
(function($) {
function test() {...}
})(jQuery);
function test2() {
console.log($('#xyz').val());
}
Which leads to a ‘$ is undefined’ error whenever test2() is executed.
I know that Drupal makes sensible use of closures to allow harmonious coexistence of libraries, which is very useful, but in this case it’ll be a nightmare to get the team responsible for said external JS file to make the necessary changes (and will also involve trying to explain to the “experts” responsible).
Is there any way that I can give this external file access to use $ as a pointer to jQuery?
Ideally I’d like some solution which doesn’t involve a huge workaround at my end, but can still make use of the external version.
Failing that, I’ll just take a local copy, and fix accordingly.
Thanks!
Just assign a global.