We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Loading third party js (docs)

Developer Preview

Bjørn Børresen's avatar
Bjørn Børresen
629 posts
9 years ago
Bjørn Børresen's avatar Bjørn Børresen

https://docs.expressionengine.com/latest/development/legacy/libraries/cp.html#loading-third-party-javascript-files

This code will only work in the constructor. That could be mentioned in the docs.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

That shouldn’t be the case, seems odd. What’s happening when you use it in another method?

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
9 years ago
Bjørn Børresen's avatar Bjørn Børresen

Nothing happens .. I tested with a .js file with alert(”loaded”) in it .. and if I put it in the constructor i get the Alert, if I put it in a normal view function I get no alert.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

Is this a fieldtype by chance? Pascal is indicating that there was a bug with that addon type and JS package paths that should be fixed in the 3.1 DPs. What version are you encountering the issue on?

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
9 years ago
Bjørn Børresen's avatar Bjørn Børresen

3.1.0

Not a fieldtype, I’m encountering it in the control panel file of my addon.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

Which DP of 3.1? It looks fixed as of DP2+

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
9 years ago
Bjørn Børresen's avatar Bjørn Børresen

Hm, it says:

ExpressionEngine 3.1.0 build date: 12/15/2015 identifier: dp.5

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

Mind posting a copy of your add-on, or emailing it to me if it’s not open-source? .(JavaScript must be enabled to view this email address)

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
9 years ago
Bjørn Børresen's avatar Bjørn Børresen

I’ve sent you an email, Derek.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

That was weird, took me a bit to track to down. Looks like the issue is in your AddonBakery common class:

$this->EE->load->add_package_path(PATH_THIRD); // add common lib folder to package path

You’re setting an add-on package path to the root THIRD_PARTY folder, which makes that the last package path loaded before your MCP controller methods are called. So it doesn’t know which package to look for your file in the subsequent ee()->cp->load_package_js('simple_registration'); call. If you get rid of that, it works fine everywhere. 😊

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
9 years ago
Bjørn Børresen's avatar Bjørn Børresen

Thanks for looking into this, Derek. So that means you can’t add more than one package path? That code is used to be able to load the same lib from multiple add ons ..

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

You’re adding a package path that isn’t to a package, you’re just adding THIRD_PARTY. Your addon’s package path is already added. If you add another one afterwards, that package’s path will be the current path in context, making your addon’s package no longer the one in context.

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
9 years ago
Bjørn Børresen's avatar Bjørn Børresen
You’re adding a package path that isn’t to a package, you’re just adding THIRD_PARTY.

Yeah, that’s the intention 😊

Ok, cheers I’ll remove that code and drop the idea of a common shared lib .. it was always a hack :-(

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.