Elgg core does not contain any mechanism for dynamic resources loading in out-of-the-box version. There are plans of integrationg in future AMD AFAIR. For now you'll need to make up some mechanism on your own or search for plugin doing it (I think it should be possible to wrap such feature in plugin).
Second concern is if JS will actually run after document ready event has passed, or requires specific loading order. You need to handle such situations yourself regardless of mechanism.
Maybe there's some plugin doing that stuff already?
Have you tried the getScript() API in your ajax call?
My solution was create a view and include it if is a ajax request (detected with elgg_is_xhr function).
<?php
$is_ajax = elgg_extract('is_ajax', $vars, FALSE);
if ( !$is_ajax ) {
return TRUE;
}
global $CONFIG;
$itens = array('veeplay', 'swfobject');
?>
<script type="text/javascript">
$(function(){
<?php foreach ($itens as $name) {
$item = elgg_extract($name, $CONFIG->externals_map['js'], FALSE);
if ( $item and $item->url ) {
echo sprintf('$.getScript("%s");', $item->url);
}
} ?>
});
</script>
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.