My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* The Panda JavaScript Components Core Library
*
* For more information, visit our website at www.panda-js.org
*
* @package panda
* @namespace window
*/
window.panda = window.panda || (function () {
var app, util, service;

/** Application settings and helpers */
app = {
/**
* Namespace Initializer
*
* Looks at a string and prepares a namespace from it's components. If
* a sub-package already exists, it will leave it as is.
*
* Inspired by YUI's YAHOO.namespace() utility.
*
* @param {String} namespace
*/
namespace : function (namespace) {
var components = namespace.split(/[^a-z0-9]+/ig);
var context = window;

for (var i = 0, l = components.length; i < l; i += 1) {
var component = components[i];

if (!context[component]) {
context[component] = {};
}

context = context[component];
}

return context;
},

/**
* Module Factory
*
* Creates a new module from an object of arbitrary components.
*
* @param {Object} components
*/
module : function (components) {
if (typeof components === 'function') {
components = components();
}

components.extend = components.extend || function () {
if (arguments.length === 1) return util.extend(arguments[0], components);
};

return components;
}
};

/** Utility methods */
util = {
/**
* Generic object extender
*/
extend : function (sub, super) {
if (super) {
for (var name in super) {
if (!sub[name]) sub[name] = super[name];
}
}

return sub;
}
};

/** The exposed service */
window.panda = service = {
namespace : app.namespace,
module : app.module
};
})();

Change log

r135 by mgirouard on Jun 27, 2009   Diff
Creating the development branch.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2252 bytes, 82 lines
Powered by Google Project Hosting