Skip to content

Commit

Permalink
Adding QuickYUI example
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Mar 29, 2010
1 parent 08a29f9 commit 6e2a579
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
27 changes: 27 additions & 0 deletions quickyui/index.htm
@@ -0,0 +1,27 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>QuickYUI Example</title>
</head>
<body>


<script src="http://yui.yahooapis.com/combo?3.1.0pr2/build/yui/yui-min.js&3.1.0pr2/build/oop/oop-min.js&3.1.0pr2/build/dom/dom-min.js&3.1.0pr2/build/event/event-min.js&3.1.0pr2/build/event-custom/event-custom-min.js&3.1.0pr2/build/event/event-base-min.js&3.1.0pr2/build/pluginhost/pluginhost-min.js&3.1.0pr2/build/node/node-min.js&3.1.0pr2/build/event/event-delegate-min.js&3.1.0pr2/build/attribute/attribute-base-min.js&3.1.0pr2/build/base/base-min.js&3.1.0pr2/build/event/event-resize-min.js&3.1.0pr2/build/dd/dd-min.js"></script>
<script src="./quickyui.js"></script>
<script>

Y.ready(function() {
Y.one('body').setStyle('backgroundColor', 'red').append('<p>Ready #1 called</p>');
});

Y.ready(function() {
Y.one('body').setStyle('backgroundColor', 'blue').append('<p>Ready #2 called</p>');
});
Y.ready(function() {
Y.one('body').setStyle('color', 'white').append('<p>Ready #3 called</p>');
});

</script>
</body>
</html>

57 changes: 57 additions & 0 deletions 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();
});

0 comments on commit 6e2a579

Please sign in to comment.