General developer forum

Can an activity module include javascript on a course page?

 
Picture of Dale Davies
Can an activity module include javascript on a course page?
 

I've developed an activity module and would like it to include some javascript on a course page. The purpose of which would be to add a menu item to the "Edit" menu next to each activity.

I can edit my theme to include the javascript using somehting like the following...

$PAGE->requires->js_call_amd('mod_linkdirectory/mainjs', 'initialise');

However I'd prefer to do it from the activity plugin itelf. Apologies if it is obvious but I'm just not seeing it.

Is this possible? 

 
Average of ratings: -
Picture of Sam Chaffee
Re: Can an activity module include javascript on a course page?
Core developersParticularly helpful Moodlers

Hi Dale,

Take a look at the callbacks that Moodle has available: https://docs.moodle.org/dev/Callbacks.

Something that might work is the before_footer callback which you would define in your activity plugin's lib.php file.

Cheers,

Sam

 
Average of ratings: Useful (1)
Picture of Dale Davies
Re: Can an activity module include javascript on a course page?
 

Aha, of course! That will work perfectly thanks smile

That's also a really useful wiki page!

 
Average of ratings: -