mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-12 03:30:12 +08:00
refactored yii module.
This commit is contained in:
@@ -7,24 +7,59 @@
|
|||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
* });
|
||||||
|
* ~~~
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
yii = (function ($) {
|
yii = (function ($) {
|
||||||
var pub = {
|
var pub = {
|
||||||
version: '2.0'
|
version: '2.0',
|
||||||
};
|
initModule: function (module) {
|
||||||
return pub;
|
if (module.isActive === undefined || module.isActive) {
|
||||||
})(jQuery);
|
if ($.isFunction(module.init)) {
|
||||||
|
|
||||||
jQuery(document).ready(function ($) {
|
|
||||||
// call the init() method of every module
|
|
||||||
var init = function (module) {
|
|
||||||
if ($.isFunction(module.init) && (module.trigger == undefined || $(module.trigger).length)) {
|
|
||||||
module.init();
|
module.init();
|
||||||
}
|
}
|
||||||
$.each(module, function () {
|
$.each(module, function () {
|
||||||
if ($.isPlainObject(this)) {
|
if ($.isPlainObject(this)) {
|
||||||
init(this);
|
pub.initModule(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
init(yii);
|
return pub;
|
||||||
|
})(jQuery);
|
||||||
|
|
||||||
|
jQuery(document).ready(function () {
|
||||||
|
yii.initModule(yii);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Yii validation module.
|
* Yii validation module.
|
||||||
*
|
*
|
||||||
* This is the JavaScript widget used by the yii\widgets\ActiveForm widget.
|
* This JavaScript module provides the validation methods for the built-in validaotrs.
|
||||||
*
|
*
|
||||||
* @link http://www.yiiframework.com/
|
* @link http://www.yiiframework.com/
|
||||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||||
|
|||||||
Reference in New Issue
Block a user