problem updating a plugins js from 1.7 to 1.8

Hi

 

I have a plugin that used to just extend the js/elgg.php view with the js it needed to load in. The problem is that I can't simply says elgg_register_js() since there is some php in the js, some variables and stuff that are loaded into the script. So how can I get the php-js lazy-loaded when I need it? ( and no I don't like just extending the view, because then it will load at all pages and that's both bad practice causing me problems, and inefficient). 

 

Thank you!

  • A few misconceptions:

    1. elgg_register_js() can point to the url of a JS view (more on that in a second). The JS view can use PHP.
    2. There is no client side lazy loading JS system in place. elgg_register_js() will register JS to be loaded on pages drawn when elgg_load_js() is called.
    3. Static views (like the CSS and the JS you extend) will be cached on the server and client side. Yes, it's good to keep JS slim, but unless you have KBs of JS, it shouldn't be a huge problem.
    With that out of the way, here's an example of how to register a JS simplecache URL to be loaded. This is from the the Wire plugin:
    // register the wire's JavaScript
    $thewire_js = elgg_get_simplecache_url('js', 'thewire');
    elgg_register_js('elgg.thewire', $thewire_js, 'footer');
    elgg_load_js('elgg.thewire');
    The call to elgg_get_simplecache_url() is what allows the JS view to be cacheable. That functions looks for views at <viewtype>/js/<name>, so the view file for the wire is at mod/thewire/views/default/js/thewire.php
Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.