General developer forum

 
 
Rocking some shades
Block/YUI help please
 

Hi,

I'm trying to create a block with an AJAX call. I have managed this with jQuery before, but now I'm trying with YUI. I think I've managed to include the file correctly, but I'm doing an alert in the init function but nothing is being alerted.

My PHP:

$jsmodule = array(
            'name' => 'block_foobar',
            'fullpath' => '/blocks/foobar_plugin/module.js',
            'requires' => array('base', 'node', 'json')
        );
        
        $this->page->requires->js_init_call('M.block_foobar.init',
                                            NULL,
                                            false,
                                            $jsmodule);

My Javascript:

M.block_foobar={

    Y : null,

    init : function(Y){
        alert('hi');
        this.Y = Y;
     }

};

Also, there are no javascript errors in the firebug window.

Thanks in advance.

Michael

 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Block/YUI help please
Group Testers

This is the equivalent of ajax() in Jquery

 

http://yuilibrary.com/yui/docs/io/

 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Block/YUI help please
Group Testers

Hi Michael,

I have tried the same code you pasted and the alert function works just fine for me.

Make sure you are purging your cache everytime you amend the JS file

 

Regards,

Hittesh

 
Average of ratings:Useful (2)
Rocking some shades
Re: Block/YUI help please
 

I spent 2 hours trying to figure this out....

I can't believe I didn't make sure the cache was clear.

Thanks

 
Average of ratings: -
Picture of john saylor
Re: Block/YUI help please
 
haha- we've all been there. but look on the bright side, the next time you won't need the two hours to figure it out! experience is a very inefficient teacher, but sometimes extremely effective.
 
Average of ratings: -
Picture of Andrew Nicols
Re: Block/YUI help please
Group DevelopersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

Hi Michael,

I think that what you're doing *should* be working, but I guess something isn't quite right, most likely with the way that you're calling js_init_call. I would imagine that the reason you're not seeing any errors in the firebug is that it's not being included for some reason. Are you seeing any references to M.block_foobar in the page source? You shoudl at least see a call to your init function. If you're not, then I would imagine that you're somehow not calling the js_init_call at all.

You don't say what version of Moodle you're developing for, but I'd really recommend reading the latest version of the JS documentation, specifically the YUI Module documentation at http://docs.moodle.org/dev/YUI/Modules. Although it's still a work in progress (sorry - I will get around to finishing them soon) they should give you a point in the right direction to how we're pushing JS in Moodle now.

Best wishes,

Andrew

 
Average of ratings: -
Picture of Andrew Nicols
Re: Block/YUI help please
Group DevelopersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

Oh, and in your config.php, set $CFG->jsrev = -1; to ensure that you aren't caching within Moodle, and disable your browser cache in the browser's developer tools.

 
Average of ratings: -