| Page 1 of 1 | [ 4 posts ] |
Alberto SantiniYUI Contributor
|
I moved a few conditional IE scripts from html to yuiConfig:
Code: <!--[if lt IE 9]> <script src="js/es5-shim.min.js"></script> <![endif]--> <!--[if lt IE 8]> <script src="js/json2.js"></script> <![endif]--> The following result works fine, but I have an empty file (ie-fake.js): Code: ie: { base: 'js/ie/', modules: { 'ie-support': { path: 'ie-fake.js' }, 'es5-shim': { path: 'es5-shim.min.js', condition: { trigger: 'ie-support', test: function (Y) { return Y.UA.ie && Y.UA.ie < 9; }, when: "instead" } }, 'json2': { path: 'json2.js', condition: { trigger: 'ie-support', test: function (Y) { return Y.UA.ie && Y.UA.ie < 8; }, when: "instead" } } } }, ... 'trammi': { path: 'trammi.js', requires: [ 'ie-support', I read the following post "Loader: Conditional module loading": viewtopic.php?p=18485 I could not find a solution without a fake file. Any suggestion? Thanks, Alberto |
|
What you're seeing here is why YUI offers wrappers around a lot of increasingly-native functionality (Y.JSON being lightweight wrappers around native JSON parsing, Y.Array offering lightweight wrappers for the functional programming constructs introduced in newer browsers). It provides consistent API without modifying native objects or adding new globals, both of which can break other scripts.
Now, while what you've done here does work, like you said, it forces you to have an extra empty file hanging around. Personally, YUI provides the functionality provided in both es5-shim and json2 in other modules (json, json-parse, json-stringify for json2.js, various modules for es5-shim), so for a YUI application, I would never include these files, YUI's own module system will do better. If you're working in a mixed environment, which I suspect you might be and that's why you're doing this, this is probably the least-bad solution. |
|
As stated previously, you may not actually need these modules, but I think you could perform this conditional logic in your script instead of in the loader config. Just define the modules without the conditional stuff, then do something like this:
Code: YUI(YUI_config).use('any', 'modules', 'you', 'need', function (Y) { var ieSupport; if (Y.UA.ie && Y.UA.ie < 9) { ieSupport = ['es5-shim']; if (Y.UA.ie < 8) { ieSupport.push('json2'); } Y.use.apply(Y, ieSupport); } }); Conditional loading is a really nice feature of loader, but in this case this feels a little bit cleaner than forcing all non-ie browsers to request an empty file. |
Alberto SantiniYUI Contributor
|
@Jeff, @Steven thanks for the replies.
As you said, I need those scripts for a thirdy parties library (the client side of a web socket impl - dnode). The complete yuiConfig is the following one: https://github.com/albertosantini/node- ... iConfig.js I may not include those files and include a script, mapping es5/json2 capabilities with YUI features. I will review this detail later in the development. Regards, Alberto |
| Page 1 of 1 | [ 4 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group