From 6e2a579955b04d4a0b26ad93387d15606bbe4596 Mon Sep 17 00:00:00 2001 From: Dav Glass Date: Mon, 29 Mar 2010 08:25:45 -0700 Subject: [PATCH] Adding QuickYUI example --- quickyui/index.htm | 27 +++++++++++++++++++++ quickyui/quickyui.js | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 quickyui/index.htm create mode 100644 quickyui/quickyui.js diff --git a/quickyui/index.htm b/quickyui/index.htm new file mode 100644 index 0000000..c16ae99 --- /dev/null +++ b/quickyui/index.htm @@ -0,0 +1,27 @@ + + + + QuickYUI Example + + + + + + + + + + diff --git a/quickyui/quickyui.js b/quickyui/quickyui.js new file mode 100644 index 0000000..c50e963 --- /dev/null +++ b/quickyui/quickyui.js @@ -0,0 +1,57 @@ + /** + * @property Y + * A single global instance of YUI + */ + Y = YUI(); + /** + * @property _cbs + * @private + * @type Array + * A simple array of callbacks passed to Y.ready + */ + Y._cbs = []; + /** + * @property _ready + * @private + * @type Boolean + * Flag to determine if the callback from use has fired. + */ + Y._ready = false; + /** + * @method _fireReady + * @private + * Fire all the stored callbacks from the .use callback. + */ + + Y._fireReady = function() { + if (Y._cbs.length) { + Y.each(Y._cbs, function(v, k) { + if (v) { + v.call(Y, Y); + Y._cbs[k] = null; + } + }); + Y._cbs = []; + } + }; + + /** + * @method ready + * Default listener for the .use callback. + * @param {Function} fn The function to execute when the .use callback is fired + */ + Y.ready = function(fn) { + if (Y._ready) { + fn.call(Y, Y); + } else { + Y._cbs.push(fn); + } + }; + + /* + * Here we use everything on the page and fire the .ready callbacks + */ + Y.use('*', function(Y) { + Y._ready = true; + Y._fireReady(); + });