Hi Kimber,
I believe that the reason you're not seeing jQuery is because you're not calling the page header in your output.
If you look at a typical Moodle PHP file, you'll see that it does a couple of things:
- require the config.php file
- login and capability checks
- outputs the page header
- outputs the content
- outputs the page footer
If you don't output the header then we don't output the main HTML structure (e.g. the head, title, CSS, base JavaScript, etc.).
I would still recommend looking at the AMD loading mechanisms.
There are two stages to loading JS in Moodle:
- in the header we load the YUI, and requireJS loaders, and the jQuery code; and
- in the footer we make use of those loaders.
We generally don't advise using jQuery without using the loader.
Typically a use of the requireJS loader looks something like:
require(['local_foo/yourjsfilename'], function(amd) { amd.init([]); });
It's just a really basic use of the loader to load some other code which actually does the work.
To generate this, you need to have something in your PHP call:
$PAGE->requires->js_call_amd('local_foo/yourjsfilename', 'init');
In your JS file, which will be located at local/foo/amd/src/yourjsfilename.js, you write:
require(['jquery'], function($) { return { init: function() { // Your code here. } } });
So essentially, in your case, you need to
- create the directory structure: local/tutorial/amd/src/
- create a file in that src folder (e.g. tutorial.js) and put the bigger block above in it, replacing 'Your code here.' with your code
- modify your file to include your code using the PAGE->requires code above.
Voila,
Andrew