yii.js 1.93 KB
Newer Older
Qiang Xue committed
1 2 3 4 5 6 7 8 9
/**
 * Yii JavaScript module.
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
Qiang Xue committed
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

/**
 * yii is the root module for all Yii JavaScript modules.
 * It implements a mechanism of organizing JavaScript code in modules through the function "yii.initModule()".
 *
 * Each module should be named as "x.y.z", where "x" stands for the root module (for the Yii core code, this is "yii").
 *
 * A module may be structured as follows:
 *
 * ~~~
 * yii.sample = (function($) {
 *     var pub = {
 *         // whether this module is currently active. If false, init() will not be called for this module
 *         // it will also not be called for all its child modules. If this property is undefined, it means true.
 *         isActive: true,
 *         init: function() {
 *             // ... module initialization code go here ...
 *         },
 *
 *         // ... other public functions and properties go here ...
 *     };
 *
 *     // ... private functions and properties go here ...
 *
 *     return pub;
Qiang Xue committed
35
 * })(jQuery);
Qiang Xue committed
36 37 38 39 40 41 42 43
 * ~~~
 *
 * Using this structure, you can define public and private functions/properties for a module.
 * Private functions/properties are only visible within the module, while public functions/properties
 * may be accessed outside of the module. For example, you can access "yii.sample.init()".
 *
 * You must call "yii.initModule()" once for the root module of all your modules.
 */
Qiang Xue committed
44 45
yii = (function ($) {
	var pub = {
Qiang Xue committed
46 47 48 49 50 51 52 53 54 55 56 57 58
		version: '2.0',
		initModule: function (module) {
			if (module.isActive === undefined || module.isActive) {
				if ($.isFunction(module.init)) {
					module.init();
				}
				$.each(module, function () {
					if ($.isPlainObject(this)) {
						pub.initModule(this);
					}
				});
			}
		}
Qiang Xue committed
59
	};
Qiang Xue committed
60
	return pub;
Qiang Xue committed
61
})(jQuery);
Qiang Xue committed
62

Qiang Xue committed
63 64
jQuery(document).ready(function () {
	yii.initModule(yii);
Qiang Xue committed
65
});