YUI headaches

Re: YUI headaches

by Darko Miletić -
Number of replies: 0

Few things:

You should use jquery included in Moodle core. See http://docs.moodle.org/dev/jQuery for details on how to do that.

That document also states:

Can I use YUI loader to include jQuery? No. Moodle jQuery support is not compatible with sandboxing.

 

Now this is how your page should look like:

<?php
require_once('path/to/config.php');

global $PAGE, $ME, $OUTPUT;

require_login();

$PAGE->set_url($ME);
$PAGE->set_context(context_system::instance());
$PAGE->set_title('Some title');
$PAGE->set_heading('Some Heading');

// Base JS dependencies.
$PAGE->requires->jquery();
$PAGE->requires->js('/question/type/easyoname/yui/chemdoodle/ChemDoodleWeb-libs.js', true);
$PAGE->requires->js('/question/type/easyoname/yui/chemdoodle/ChemDoodleWeb.js', true);
$PAGE->requires->js('/question/type/easyoname/yui/chemdoodle/sketcher/ChemDoodleWeb-sketcher.js', true);

// Your module code that must be located in /question/type/easyoname/yui/chemdoodle/chemdoodle.js .
$PAGE->requires->yui_module('moodle-qtype_easyoname-chemdoodle',
    'M.qtype_easyoname.chemdoodle.init',
    null,
    null,
    true
);

echo $OUTPUT->header();

// Your stuff here.

echo $OUTPUT->footer();

And this is the base content of chemdoodle.js

YUI.add('moodle-qtype_easyone-chemdoodle', function(Y) {

        M.qtype_easyone = M.qtype_easyone || {};

        M.qtype_easyone.chemdoodle = {
            init: function() {
                // Place your code here.
            } // end init
        }; // end module

    }, '@VERSION@', {requires: ['node', 'console']}
);