| Page 1 of 1 | [ 4 posts ] |
|
Hi,
I have a javascript function called get_detail_validator that I'm using in multiple location in my app, each time in a YUI.use block. This method uses Y.io, which has as consequence that I cannot define it as a plain function in my js file. The solution I've used is to create a module for my app modeled after the yql module (http://github.com/davglass/yui-yql/blob/master/yql.js ) Code: YUI.add('madb', function(Y) { if (!YUI.madb_forms) { YUI.madb = {}; } var get_detail_validator= function (detail_id) { // blabla Y.io(check_url, cfg); //blabla } YUI.madb = { get_detail_validator: get_detail_validator } }, '1.0', { requires: ['io-base'], skinnable: false} ); With this in place I can call the method Code: YUI.madb.get_detail_validator(345); Can someone confirm this is the right way to go? Thanks in advance Raph |
Daniel Cook
|
I would not add it to the global YUI but rather to the local Y instance (Y.madb). That way it will only be used within the 'use' method.
Minor question, why do you check for 'madb_forms'? |
|
in the first part of the YQL stuff dav is defining a global object for callbacks so I don't think you need this part
if (!YUI.madb_forms) { YUI.madb = {}; } and daniel is correct you would want to add your function to the Y instance not directly to the YUI global variable so the module stuff can manage it. You can use the namespace function to make a hole for yourself that won't overwrite stuff, in case you want to incrementally add more functions to that madb namespace var get_detail_validator = function(...) { ... }; Y.namespace('madb'); // makes Y.madb object if it doesn't exist Y.madb.get_detail_validator = get_detail_validator; then in the use statement for an instance where you want to use it: Code: YUI({ 'madb':{ fullpath:'/path to the stuff', requires: ['io-base'] } }).use ('madb', function(Y) { // io-base and madb available in Y via hot combo loader action Y.madb.get_detail_validator(...) { }; }); substitute does a similar deal as well. FYI there are some form modules in the Gallery under F maybe someone has already done what you need. |
|
Satake wrote: in the first part of the YQL stuff dav is defining a global object for callbacks so I don't think you need this part if (!YUI.madb_forms) { YUI.madb = {}; } Thanks for the clarification. Satake wrote: FYI there are some form modules in the Gallery under F maybe someone has already done what you need. Yes, this code is using gallery-form by Greg Hinch. It's working great indeed. Raph |
| 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 |
© YUI Library - Site Credits
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group