2 Copyright (c) 2006, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
9 * The YAHOO object is the single global object used by YUI Library. It
10 * contains utility function for setting up namespaces, inheritance, and
11 * logging. YAHOO.util, YAHOO.widget, and YAHOO.example are namespaces
12 * created automatically for and used by the library.
17 if (typeof YAHOO == "undefined") {
19 * The YAHOO global namespace object
27 * Returns the namespace specified and creates it if it doesn't exist
29 * YAHOO.namespace("property.package");
30 * YAHOO.namespace("YAHOO.property.package");
32 * Either of the above would create YAHOO.property, then
33 * YAHOO.property.package
35 * Be careful when naming packages. Reserved words may work in some browsers
36 * and not others. For instance, the following will fail in Safari:
38 * YAHOO.namespace("really.long.nested.namespace");
40 * This fails because "long" is a future reserved word in ECMAScript
44 * @param {String*} arguments 1-n namespaces to create
45 * @return {Object} A reference to the last namespace object created
47 YAHOO.namespace = function() {
48 var a=arguments, o=null, i, j, d;
49 for (i=0; i<a.length; ++i) {
53 // YAHOO is implied, so it is ignored if it is included
54 for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; ++j) {
55 o[d[j]]=o[d[j]] || {};
64 * Uses YAHOO.widget.Logger to output a log message, if the widget is available.
68 * @param {String} msg The message to log.
69 * @param {String} cat The log category for the message. Default
70 * categories are "info", "warn", "error", time".
71 * Custom categories can be used as well. (opt)
72 * @param {String} src The source of the the message (opt)
73 * @return {Boolean} True if the log operation was successful.
75 YAHOO.log = function(msg, cat, src) {
76 var l=YAHOO.widget.Logger;
78 return l.log(msg, cat, src);
85 * Utility to set up the prototype, constructor and superclass properties to
86 * support an inheritance strategy that can chain constructors and methods.
90 * @param {Function} subc the object to modify
91 * @param {Function} superc the object to inherit
92 * @param {Object} overrides additional properties/methods to add to the
93 * subclass prototype. These will override the
94 * matching items obtained from the superclass
97 YAHOO.extend = function(subc, superc, overrides) {
98 var F = function() {};
99 F.prototype=superc.prototype;
100 subc.prototype=new F();
101 subc.prototype.constructor=subc;
102 subc.superclass=superc.prototype;
103 if (superc.prototype.constructor == Object.prototype.constructor) {
104 superc.prototype.constructor=superc;
108 for (var i in overrides) {
109 subc.prototype[i]=overrides[i];
115 * Applies all prototype properties in the supplier to the receiver if the
116 * receiver does not have these properties yet. Optionally, one or more
117 * methods/properties can be specified (as additional parameters). This
118 * option will overwrite the property if receiver has it already.
122 * @param {Function} r the object to receive the augmentation
123 * @param {Function} s the object that supplies the properties to augment
124 * @param {String*} arguments zero or more properties methods to augment the
125 * receiver with. If none specified, everything
126 * in the supplier will be used unless it would
127 * overwrite an existing property in the receiver
129 YAHOO.augment = function(r, s) {
130 var rp=r.prototype, sp=s.prototype, a=arguments, i, p;
132 for (i=2; i<a.length; ++i) {
144 YAHOO.namespace("util", "widget", "example");