1 | /* |
---|
2 | Copyright (c) 2006, Yahoo! Inc. All rights reserved. |
---|
3 | Code licensed under the BSD License: |
---|
4 | http://developer.yahoo.net/yui/license.txt |
---|
5 | Version: 0.11.4 |
---|
6 | */ |
---|
7 | |
---|
8 | /** |
---|
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. |
---|
13 | * @module YAHOO |
---|
14 | */ |
---|
15 | |
---|
16 | /** |
---|
17 | * The YAHOO global namespace object |
---|
18 | * @class YAHOO |
---|
19 | * @static |
---|
20 | */ |
---|
21 | if (typeof YAHOO == "undefined") { |
---|
22 | YAHOO = {}; |
---|
23 | } |
---|
24 | |
---|
25 | /** |
---|
26 | * Returns the namespace specified and creates it if it doesn't exist |
---|
27 | * |
---|
28 | * YAHOO.namespace("property.package"); |
---|
29 | * YAHOO.namespace("YAHOO.property.package"); |
---|
30 | * |
---|
31 | * Either of the above would create YAHOO.property, then |
---|
32 | * YAHOO.property.package |
---|
33 | * |
---|
34 | * Be careful when naming packages. Reserved words may work in some browsers |
---|
35 | * and not others. For instance, the following will fail in Safari: |
---|
36 | * |
---|
37 | * YAHOO.namespace("really.long.nested.namespace"); |
---|
38 | * |
---|
39 | * This fails because "long" is a future reserved word in ECMAScript |
---|
40 | * @method namespace |
---|
41 | * @static |
---|
42 | * @param {String} ns The name of the namespace |
---|
43 | * @return {Object} A reference to the namespace object |
---|
44 | */ |
---|
45 | YAHOO.namespace = function(ns) { |
---|
46 | |
---|
47 | if (!ns || !ns.length) { |
---|
48 | return null; |
---|
49 | } |
---|
50 | |
---|
51 | var levels = ns.split("."); |
---|
52 | var nsobj = YAHOO; |
---|
53 | |
---|
54 | // YAHOO is implied, so it is ignored if it is included |
---|
55 | for (var i=(levels[0] == "YAHOO") ? 1 : 0; i<levels.length; ++i) { |
---|
56 | nsobj[levels[i]] = nsobj[levels[i]] || {}; |
---|
57 | nsobj = nsobj[levels[i]]; |
---|
58 | } |
---|
59 | |
---|
60 | return nsobj; |
---|
61 | }; |
---|
62 | |
---|
63 | /** |
---|
64 | * Uses YAHOO.widget.Logger to output a log message, if the widget is available. |
---|
65 | * |
---|
66 | * @method log |
---|
67 | * @static |
---|
68 | * @param {string} sMsg The message to log. |
---|
69 | * @param {string} sCategory 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} sSource The source of the the message (opt) |
---|
73 | * @return {boolean} True if the log operation was successful. |
---|
74 | */ |
---|
75 | YAHOO.log = function(sMsg, sCategory, sSource) { |
---|
76 | var l = YAHOO.widget.Logger; |
---|
77 | if(l && l.log) { |
---|
78 | return l.log(sMsg, sCategory, sSource); |
---|
79 | } else { |
---|
80 | return false; |
---|
81 | } |
---|
82 | }; |
---|
83 | |
---|
84 | /** |
---|
85 | * Utility to set up the prototype, constructor and superclass properties to |
---|
86 | * support an inheritance strategy that can chain constructors and methods. |
---|
87 | * |
---|
88 | * @method extend |
---|
89 | * @static |
---|
90 | * @param {function} subclass the object to modify |
---|
91 | * @param {function} superclass the object to inherit |
---|
92 | */ |
---|
93 | YAHOO.extend = function(subclass, superclass) { |
---|
94 | var f = function() {}; |
---|
95 | f.prototype = superclass.prototype; |
---|
96 | subclass.prototype = new f(); |
---|
97 | subclass.prototype.constructor = subclass; |
---|
98 | subclass.superclass = superclass.prototype; |
---|
99 | if (superclass.prototype.constructor == Object.prototype.constructor) { |
---|
100 | superclass.prototype.constructor = superclass; |
---|
101 | } |
---|
102 | }; |
---|
103 | |
---|
104 | YAHOO.namespace("util"); |
---|
105 | YAHOO.namespace("widget"); |
---|
106 | YAHOO.namespace("example"); |
---|
107 | |
---|