Conventional jQuery function works using my_function() but elgg.my_plugin.my_function doesn't work?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
Here's a quick way to do modules.
Just throw your js into a real .js file in the view system
In your php when you need to load this js simply call
Elgg will automagically know where that file is, take care of the caching, everything. No need to use elgg_define_js if you use the view system.
In the js file itself:
Looks simple enough but I still wanna use what I know until it's deprecated.
is it not deprecated? I thought the old method was deprecated...
Either way, take the plunge, I just showed you how easy it is and once you do it you'll see it's much nicer :)
The old way *is* essentially deprecated since Elgg 1.9. But I'm afraid Elgg isn't in fact giving deprecation warnings about it. That needs to be fixed in one of the 2.x releases.
You know what, I probably need to use an AMD module to re-initialize a function.
@Matt Yeah I'm gonna switch to AMD since it looks easy enough! What will happen to js.php though?
@Juho are you saying elgg_extend_view('elgg.js', 'my_plugin/js'); will be deprecated?
Does 2.0 have a css folder just like js?
Extending the core js is still an ok solution if you need your js on *every* page. That's rarely the case though, most of the time you need just a small amount of js in a very specific place, and that's what modules are for. It keeps things lighter and more manageable.
We'll have to discuss what and how to encourage people to adopt AMD.
Re: css - it doesn't have auto-registered css at the moment as far as I know, I do far less with css than I do with js
Seems like AMD doesn't play well with functions. It fired up all 3 functions when it supposed to be fired by a trigger.
Yeah I just tried converting to AMD but it messed up all my jQuery functions. I'm going back to elgg_load_js() and use the old way.
My JS file will be loaded once since it's gonna be ajax driven.
AMD is just a specification for how to build js modules. It's not something that triggers functions on its own. There must be something wrong with your code itself.
@juho here's a sample of my code from memory, I'm not on the computer right now.
It fires every time the page loads. I even checked firebug and it shows Ajax calls.
- Previous
- 1
- 2
- 3
- 4
- Next
You must log in to post replies.