YUI 3 - plans to add to HEAD?

YUI 3 - plans to add to HEAD?

by Aaron Barnes -
Number of replies: 19
Are there any plans to run Moodle 2.0 on YUI3?

http://www.yuiblog.com/blog/2009/09/29/yui-3-0-0/
http://developer.yahoo.com/yui/3/

I know it's not backwards compatible (so would require a lot of work), but man does it look a lot friendlier than YUI2!
Average of ratings: -
In reply to Aaron Barnes

Re: YUI 3 - plans to add to HEAD?

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
YAY - they finally released it! That changes everything smile I am going to spent some time reviewing the changes today. I personally think that we should use it just because upgrading to it in the middle of 2.0 will not be possible, so we would be stuck with YUI 2 for a few more years.

I just hope there will not be many bits missing that are now available in 2.8.0

Petr
Average of ratings: Useful (1)
In reply to Aaron Barnes

Re: YUI 3 - plans to add to HEAD?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Well, yes, it sure looks good.

I guess it comes down to how much work it takes to implement in Moodle 2.0, and how much delay to the Moodle 2.0 schedule people are willing to accept.

I'm interested to see a discussion on this here.

Opinions? Facts?
In reply to Martin Dougiamas

Re: YUI 3 - plans to add to HEAD?

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If it's going to introduce massive backwards-compatibility issues, then if we don't do it before Moodle 2, we probably won't be able to do it for a long time afterwards. Since Moodle 2 already breaks backwards compatibility in it's own APIs, now seems like the "right time", if there ever is one.
In reply to Mark Johnson

Re: YUI 3 - plans to add to HEAD?

by Frank Ralf -
Here you'll find short summary of the major new features:
http://www.h-online.com/open/Yahoo-upgrades-its-YUI-web-framework--/news/114355

Quote:
"Access to DOM objects via CSS selectors, in a similar way to jQuery, and selection by element ID are now both supported within the Node class. Previously, developers using YUI had to use different methods for selecting through IDs, CSS classes or other CSS selectors.

YUI's event handling has also been enhanced with the use of a Facade Pattern, which makes it easier to apply callbacks to, not just single elements, but selections of elements"

My 2 €-cent:

1) Lack of backward compatibility is a major drawback, both from a technical standpoint but also with regard to the learning curve for developers.

2) If YUI's improvements are due to providing similar functionality as jQuery why not switch frameworks?

Frank
In reply to Aaron Barnes

Re: YUI 3 - plans to add to HEAD?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Extensive talk about this today in developer chat.

Currently they have not got a YUI 3 treeview, which is a serious problem for us. However, moving to YUI 3 before 2.0, rather than after, makes sense if possible. i think that is a fair summary of the discussion so far.
In reply to Tim Hunt

Re: YUI 3 - plans to add to HEAD?

by Mauno Korpelainen -

At least most of the YUI 2 Widgets are missing from current YUI 3.0.0. and won't be added before Q1 in 2010 (YUI 3.1.0)

http://yuilibrary.com/projects/yui3/roadmap

I was planning to use TabView in my coming TinyMCE math plugins but it's not a big problem to change the current scripts to use external libraries (if needed) or replace TabView code with other javascripts.

In reply to Mauno Korpelainen

Re: YUI 3 - plans to add to HEAD?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
This may not be a problem. Looks like we can migrate gradually and keep using YUI 2 widgets only where necessary:

http://yuilibrary.com/forum/viewtopic.php?f=92&t=1059
In reply to Martin Dougiamas

Re: YUI 3 - plans to add to HEAD?

by Sam Hemelryk -
+1 from me running with both and phasing out as widgets become stable
In reply to Martin Dougiamas

Re: YUI 3 - plans to add to HEAD?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Excellent! I think that lets us start the move to YUI 3 in Moodle 2.0 then.
In reply to Tim Hunt

Re: YUI 3 - plans to add to HEAD?

by Anita Mourya -

Can you please provide some code samples with file reference to use tabview from yui libararies in moodle2. I have tried but it always shows error "Y undefined" or "YUI3 undefined".

Any help on this?

In reply to Anita Mourya

Re: YUI 3 - plans to add to HEAD?

by Anita Mourya -

I have fixed this issue and pasting the code sample that worked for me.

YUI integration in moodle2

---------------------------------------------------------------------------------

Step 1:

Add a file or add code in file if it already exists

/mod/my/module.js

JAVASCRIPT code:

M.mod_my = {};


M.mod_my.init_tabview = function(Y) {
Y.use("tabview", function(Y) {
var tabview = new Y.TabView({srcNode:'#demo'});
tabview.render();
});
};

---------------------------------------------------------------------------------

Step 2:

/my/lib.php

PHP Code:


function my_initialise_tabview(moodle_page $PAGE) {
$PAGE->requires->js('/lib/yui/3.2.0/build/tabview/tabview-min.js');
$module = array(
'name'      => 'tabview',
'fullpath'  => '/lib/yui/3.2.0/build/yui/yui-min.js',
'requires'  => array('base', 'io', 'node', 'json', 'tabView')
);
$PAGE->requires->js_module($module);
$PAGE->requires->js_init_call('M.mod_my.init_tabview');
}

 

---------------------------------------------------------------------------------

Step 3:

Then in any file in my folder use following code to call tabs

/my/profile.php

PHP code:

my_initialise_tabview($PAGE);

HTML Code:

 

<div id="demo">
<ul>
<li><a href="#foo">foo</a></li>
<li><a href="#bar">bar</a></li>
<li><a href="#baz">baz</a></li>
</ul>

<div>
<div id="foo">
<p>foo content</p>
</div>
<div id="bar">
<p>bar content</p>
</div>
<div id="baz">

<p>baz content</p>
</div>
</div>
</div>

---------------------------------------------------------------------------------

 

Moodle Javascript Manual that helped me fix this issue

http://docs.moodle.org/en/Development:JavaScript_guidelines

In reply to Anita Mourya

Re: YUI 3 - plans to add to HEAD?

by Anita Mourya -

I missed the css file so the code for PHP function will become like

function my_initialise_tabview(moodle_page $PAGE)   {

$PAGE->requires->css('/lib/yui/3.2.0/build/tabview/assets/skins/sam/tabview.css');
$PAGE->requires->js('/lib/yui/3.2.0/build/tabview/tabview-min.js');
$module = array(
'name'      => 'tabview',
'fullpath'  => '/lib/yui/3.2.0/build/yui/yui-min.js',
'requires'  => array('base', 'io', 'node', 'json', 'tabView')
);
$PAGE->requires->js_module($module);
$PAGE->requires->js_init_call('M.mod_my.init_tabview');

}

In reply to Anita Mourya

Re: YUI 3 - plans to add to HEAD?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You should be able to do all that with just the js_init_call (after you have set up $module):

$PAGE->requires->js_init_call('M.mod_my.init_tabview', array(), $module);

The CSS should be included automatically, I think, but I can't remember how that bit of magic works.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: YUI 3 - plans to add to HEAD?

by Anita Mourya -

Thanks, the code you gave is also working.

One another question, what is the right way to use different stylesheets for tabview in various themes.

In reply to Anita Mourya

Re: YUI 3 - plans to add to HEAD?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That is a good question. I am afraid I don't know.

In reply to Anita Mourya

Re: YUI 3 - plans to add to HEAD?

by Sam Hemelryk -
Hi Anita,

I think the best way to go about this for you (it looks like you are working on a module correct?) is to do the following:

mod/my/styles.css - you should style the general look and feel in here, this of course is the main stylesheet for your module and will be loaded for every theme.

mod/my/styles_themename.css - replace themename with the name of the theme you are styling for and then add to and/or extend the styles you have in styles.css here. This stylesheet will only be loaded for the named theme.

Worth noting is that this doesn't require any JavaScript, the css files are loaded for all pages, regardless of whether your JS is going to be executed or not. This is done so that the styles are cached on the server by Moodle and in your clients browser, so while it does make the overall CSS larger it will be cached properly and should be faster for your users in the end.
You could also go about this by calling $PAGE->requires->css('/mod/my/styles.php'); and then write styles.php to server the correct CSS for the theme, however it would add more load than the above method and, and I think the above method will provide a clearer, more workable solution.

I think I may be able to help a bit with the JS as well, I'll post again about that shortly.

Cheers
Sam
In reply to Anita Mourya

Re: YUI 3 - plans to add to HEAD?

by Sam Hemelryk -
Hi Anita,

Whilst I see that what you've got works, there is an easier way around it that you may be interested in, or in fact there are two ways. I'll explain both here for yourself and anyone else who ends up here and I'll leave it up to you as to whether you decide to try either of them out.

First up, when working within a plugin (module/block/local) the js_init_call method if not given a module will automatically work out the path to your plugin and try to include a module.js file if it exists.
This means if you don't want to do anything flash, and you are happy with just using module.js and then doing the work in JS you can do the following:

PHP code:

$PAGE->requires->js_init_call('M.mod_my.init_tabview');


JS code: /mod/my/module.js

M.mod_my = M.mod_my || {};
M.mod_my.init_tabview = function(Y) {
Y.use("tabview", function(Y) {
var tabview = new Y.TabView({srcNode:'#demo'});
tabview.render();
});
};


HTML: Same as you had above.

What you can see from that is that in fact you only need one line of PHP and the function you already have within module.js.
Essentially by calling Y.use('tabview', function(){...}) you are requiring the one library you require.

Now lets say you wanted to include more libraries earlier on so that they loaded before you JS executed, or you wanted to name your JS file something other than module.js.
This is the second method that builds upon the first and does so by defining a JS module ($module) and passing that to the init call. Check out the following code example:

PHP code:

$module = array(
'name' => 'my_mod_alternative',
'fullpath' => '/mod/my/alternative.js',
'requires' => array('tabview')
);
$PAGE->requires->js_init_call('M.mod_my.init_tabview', null, true, $module);


JS code: /mod/my/alternative.js

M.mod_my = M.mod_my || {};
M.mod_my.init_tabview = function(Y) {
var tabview = new Y.TabView({srcNode:'#demo'});
tabview.render();
};


So a couple of things to note here, the first the PHP code now defines $module.
$module should be an array that contains the following:
  1. name This should be the name of your module... what ever you want it to be.
  2. fullpath This is the path to your JS file from Moodle's root directory.
  3. requires This is an optional array of YUI modules to include. In your example you only need to specify 'tabview' as that will include all of the modules it requires.


The second thing to notice is that within the JS code you no longer need the Y.use('tabview', function(){...}). This is because your $module asked for it to be loaded with all the other JS for the page.

Anyway, hope this all helps in some way.

Cheers
Sam
Average of ratings: Useful (1)
In reply to Sam Hemelryk

Re: YUI 3 - plans to add to HEAD?

by Anita Mourya -

Thanks Sam for your detailed explanation however I wanted some help on YUI left Nav and EXT Js libraries. Actually, I am using EXT Js 3.3.1 Formpanels for edit profile. But the Left Navigation does not work properly on this page. The collapse and Expand does not work. Could you help me if this is YUI issue or what?

I have tried including

"ext-3.3.1/adapter/yui/yui-utilities.js",
"ext-3.3.1/adapter/yui/ext-yui-adapter.js"

instead of

"ext-3.3.1/adapter/ext/ext-base.js"

But it still did not work in moodle 2.0.

Thanks for any help.