I'm creating a local plugin walkthrough tutorial for my site, and it's working as it's supposed to. The problem is when I try to add a jquery function to some echoed html, I get an error that says, "ReferenceError: $ is not defined." That means that jquery hasn't loaded yet, right? But how can I make it load sooner? Am I loading it incorrectly?
This is how the plug-in works:
lib.php calls SKOTour.php, which creates an html ordered list whose visibility is then manipulated by SKOTour.js. The .js file is a jquery plugin and it loads and works properly. It's the jquery in the html ordered list that's giving me problems. I get the error immediately on refresh, before any of the page is visible onscreen.
I'm using Moodle 2.9 and a child of the BCU theme
My lib.php file basically contains:
defined('MOODLE_INTERNAL') or die;
global $CFG, $PAGE, $USER;
$PAGE->requires->jquery();
$PAGE->requires->jquery_plugin('SKOTour', 'local_tutorial');
require_once($CFG->dirroot . '/local/tutorial/SKOTour.php');
My SKOTour.php file basically contains:
global $CFG, $PAGE;
$PAGE->requires->jquery();
echo '<ol>
<li>
<h2>Collapse Blocks</h2>
<p>To save screen space, you can collapse a block. Click the button now.</p>
<p id="AfterClick1">You collapsed it! Click the button again.</p>
<p id="AfterClick2">You expanded it again!</p>
<script type="text/javascript">
$(document).ready(function(){ <-----HERE IS WHERE THE ERROR IS GENERATED
$("img.block-hider-hide").click(function(){
$("p#AfterClick1").show(500);
});
$("img.block-hider-show").click(function(){
$("p#AfterClick2").show(500);
});
});
</script>
</li>
</ol>';
SKOTour.js basically contains:
window.onload = (function ReadyTutorial() {
RunCourseTutorial();
function RunCourseTutorial() {
// all my code to "do stuff"
}
});