[ 8 posts ]

Neal Buckley

  • Username: neal
  • Joined: Mon Jun 27, 2011 9:33 am
  • Posts: 20
  • Offline
  • Profile

YUI3 Loader

Post Posted: Tue Aug 02, 2011 8:54 pm
+0-
Hi,

I have a question on yui3 loader. I am building custom shindig features and i plan to use loader utility to load additional java script files using the insert method. I have a gadget in which i want to include the script like this,

<!-- Load the YUI Loader script: -->
<script src="http://yui.yahooapis.com/2.9.0/build/yuiloader/yuiloader-min.js"></script>
But the script doesn't seem to load . Is there a best practice to follow to use loader functionality with shindig features? Also I came to know that loader functionaloity for yui3 comes with yui global object . is that true?

thanks,

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 619
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile

Re: YUI3 Loader

Post Posted: Wed Aug 03, 2011 5:01 am
+0-
Yes, in YUI3 you don't need to load specifically the loader module. Just insert the yui seed file.
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>

There are 2 ways you can do it: you can just use the Get utility or you can create your own custom modules and load them with YUI().use().

Neal Buckley

  • Username: neal
  • Joined: Mon Jun 27, 2011 9:33 am
  • Posts: 20
  • Offline
  • Profile

Re: YUI3 Loader

Post Posted: Wed Aug 03, 2011 7:30 am
+0-
thanks juan. In my case, since I am using gadgets I do not want to load the seed in the gadget file hence i am adding the seed as dependency in the shindig features and loading the seed content. now i want to use this load functionality to load a javascript dynamically in another javascript function. should i be able to do that? are there any examples doing this?

thanks in advance

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 619
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile

Re: YUI3 Loader

Post Posted: Wed Aug 03, 2011 7:39 am
+0-
Check out the links to the documentation I posted in my previous comment. In there you have two possible solutions to what you need, examples included.

Neal Buckley

  • Username: neal
  • Joined: Mon Jun 27, 2011 9:33 am
  • Posts: 20
  • Offline
  • Profile

Re: YUI3 Loader

Post Posted: Wed Aug 03, 2011 10:12 am
+0-
hi juan,

i looked at the examples and have written the below code but it doesn;t seem to load the js file. i might be missnig something here.

here is my code...is this the correct way?

var Y = YUI();
alert(Y);
YUI.add('mymodules-mod1', function(Y) {


},
'0.1.1' /* module version */,
{
fullpath: 'myfile.js'
});

i am expecting that myfile.js gets loaded. but i do not see that happening. I really do not need to load any modules nor have code in callback function. all I want is load the js file .

thank you

Neal Buckley

  • Username: neal
  • Joined: Mon Jun 27, 2011 9:33 am
  • Posts: 20
  • Offline
  • Profile

Re: YUI3 Loader

Post Posted: Wed Aug 03, 2011 12:07 pm
+0-
juan,

I tried using YUI.use() method but still the script doesn't seem to load.

my code here:


YUI({

modules: {
testmodule: {
fullpath: 'myfile.js'
}
}
}).use('testmodule', function(Y) {
// All YUI modules required to get drag and drop to work are now loaded.
});

this code is sitting in another js file and when that js file is loaded , i am assuming that myfile.js gets loaded. but looks like it is not loading.

I also tried using get utility and no luck.

can u pls advise?

thanks

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 619
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile
Tags:

Re: YUI3 Loader

Post Posted: Wed Aug 03, 2011 4:30 pm
+0-
Hey Neal,

The basic idea behind custom modules is this:

1) Create a file with your module
Code:
YUI.add('mymodule', function (Y) {
  Y.sayHi = function () { console.log('hi'); };
});


2) In your page/gadget/iframe insert the YUI seed file and add your module to the configuration of the YUI object. Then use() your module
Code:
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
<script>
YUI({
  modules: {
    mymodule: {
      fullpath: 'path/to/mymodule.js',
      requires: ['node']
    }
  }
}).use('mymodule', function (Y) {
  Y.sayHi();
});
</script>

You can do a lot with custom modules and they work really well with any gadget implementation. Just experiment with them!

Sridhar Jay

  • Username: Sridhar Jay
  • Joined: Wed Oct 19, 2011 12:10 am
  • Posts: 1
  • GitHub: Sridhar
  • Gists: Sridhar
  • IRC: Sri
  • Offline
  • Profile

Re: YUI3 Loader

Post Posted: Wed Oct 19, 2011 9:04 pm
+0-
Hi Juan,

I want to use YUI2 modules in YUI3 [ say yui2-carousel]. This is working fine, however, the YUI loader is getting files from Internet, making a request to yahooapis everytime I run my application.

I want to have these YUI2 modules locally and let the loader find these instead of the ones from yahoo site. Can u help me out on this?

Or is there any other way to prevent the loader to from getting js files from Internet?
  [ 8 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum