[ 5 posts ]

Aneesh M J

  • Username: aneesh
  • Joined: Thu Aug 05, 2010 3:08 am
  • Posts: 31
  • Offline
  • Profile

YUI 2 patterns loader

Post Posted: Tue Aug 10, 2010 1:42 am
+0-
I am loading YUI 2 components locally in YUI 3. I have saved the pattern in a js file called "yui-2-pattern.js". It contains:

Code:
var YUI2_GROUP_PATTERNS = {
    combine: false,
    groups: {
        yui2: {
            base: '/Scripts/2.8.1/build/',
            patterns:  {
                'yui2-': {
                    configFn: function(me) {
                        if(/-skin|reset|fonts|grids|base/.test(me.name)) {
                           
                     me.type = 'css';
                     me.path = me.path.replace(/\.js/, '.css');
                     me.path = me.path.replace(/\/yui2-skin/, '/assets/skins/sam/yui2-skin');
                  }
                    }
                }
            }
        }
    }
}


How can I load this file and use like:

Code:
YUI(YUI2_GROUP_PATTERNS).use('yui2-container'........)


It is working if I include
<script type="text/javascript" src="/Scripts/YUI2-Patterns.js"></script>

But I dont want to load this pattern in this way. Please help..Thanks..

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 494
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile

Re: YUI 2 patterns loader

Post Posted: Tue Aug 10, 2010 6:23 am
+0-
Hey Aneesh,

The way I see it, YUI2_GROUP_PATTERNS (along with YUI_config or any other type of configuration), is part of your application layer, specifically the application configuration.

You can find a way to load that chunk dynamically, but you will get a performance penalty for sure, because of these:

1. To create an instance of Y you will have to load a file with the configuration first.
2. To load a configuration (on-demand) you might have to create an instance for that to use Y.get or you will have to do it manually, either way your application in on hold until that configuration gets loaded.

My recommendation is to create a simple config.js file, include it at the very top. This file is very tiny, should not be a problem if the file is cacheable.

Best Regards,
Caridy

Aneesh M J

  • Username: aneesh
  • Joined: Thu Aug 05, 2010 3:08 am
  • Posts: 31
  • Offline
  • Profile
Tags:

Re: YUI 2 patterns loader

Post Posted: Wed Aug 11, 2010 5:33 am
+0-
Thanks Caridy!!

So, you mean to say what I did is the best way to load this pattern.. right ?

I have a doubt. I loaded the config.js like this and using:

YUI(YUI2_GROUP_PATTERNS).use('yui2-container'........)

then, I want to load some page specific files. Then how can I combine it and use like:

YUI(YUI2_GROUP_PATTERNS + PAGE SPECIFIC PATTERN).use('yui2-container'........) ?

Last week only I started learning YUI.

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 494
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile

Re: YUI 2 patterns loader

Post Posted: Wed Aug 11, 2010 8:15 am
+0-
Hey Aneesh,

Every YUI instance accepts up to 5 configuration objects plus the global configuration. HEre is an example:

Code:
// Global variable that will be populated automatically as a configuration object by any Y instance in the page.
YUI_config = {
    filter: debug;
};

var YUI2_GROUP_PATTERNS = {
   combine: false
};

vra PAGE_SPECIFIC_PATTERN = {
    modules: {
      // blablabla
    }
};

// then, all intances uses YUI_config as the default config
YUI().use ();

// adding YUI2_GROUP_PATTERNS to the party, which means:
//  YUI_config + YUI2_GROUP_PATTERNS
YUI(YUI2_GROUP_PATTERNS).use ();

// And even more:
//  YUI_config + YUI2_GROUP_PATTERNS + PAGE_SPECIFIC_PATTERN + Manual obj
YUI(YUI2_GROUP_PATTERNS, PAGE_SPECIFIC_PATTERN, { '2in3': '2.8.0r4' }).use ();


Of course, in your case PAGE_SPECIFIC_PATTERN sounds more like YUI_config to set up the whole page through a global configuration. But I'm sure you get the idea.

Best Regards,
Caridy

Aneesh M J

  • Username: aneesh
  • Joined: Thu Aug 05, 2010 3:08 am
  • Posts: 31
  • Offline
  • Profile

Re: YUI 2 patterns loader

Post Posted: Thu Aug 12, 2010 10:17 pm
+0-
Thanks Caridy!! I will check that n let you know the feedback
  [ 5 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