jquery-ui widget源码

段恩
2023-12-01
<script>
    $.Widget = function () { }
    $.Widget._childConstructors = [];
    $.Widget.prototype = {
        widgetName: "widget",
        widgetEventPrefix: "",
        defaultElement: "<div>",
        options: {
            classes: {},
            disabled: false,
            create: null
        },
        _create: $.noop,
        _createWidget:function(){
            this._create();
        }
    };

    $.widget = function (name, base, prototype)
    {
        const constructor = function () {
            this._createWidget( options, element );
         }
        const proxiedPrototype = {};
        constructor.version = prototype.version;
        constructor[ '_proto' ] = assign({}, prototype);
        constructor[ '_childConstructors' ] = [];
        // 父类的prototype
        const basePrototype = new $.Widget();
        basePrototype.options = assign({}, basePrototype.options);
        // resizableRelatedOptions function类型
        // _create _init _createWrapper
        proxiedPrototype[ prop ] = (function (prop, fn)
        {
            function _super()
            {
                return $.Widget.prototype[ prop ].apply(this, arguments);
            }
            function _supperApply(args)
            {
                return $.Widget.prototype[ prop ].apply(this, args);
            }
            return function ()
            {
                var __super = this._super;
                var __superApply = this._supperApply;
                var returnValue;
                // 设置_super _superApply
                this._super = _super;
                this._superApply = _superApply;
                returnValue = value.apply(this, arguments);
                // 还原_super _superApply
                this._super = __super;
                this._superApply = __superApply;
                return returnValue;
            }
        })('_create', function () { });
        constructor.prototype = assign(
            basePrototype,
            { widgetEventPrefix: '' },
            proxiedPrototype,
            { constructor: constructor }
        );
        return constructor;
    }
    
	/**--------------------------------------------------------------------------------------------------------*/
	
	$.widget("ui.dialog", {
	version: "1.12.1",
	options: {},
	sizeRelatedOptions: {
		buttons: true,
		height: true,
		maxHeight: true,
		maxWidth: true,
		minHeight: true,
		minWidth: true,
		width: true
	},
	resizableRelatedOptions: {
		maxHeight: true,
		maxWidth: true,
		minHeight: true,
		minWidth: true
	},
	_create: function () {
		/**
			_create fn开始
			this._super = _super;
            this._superApply = _superApply;
            _create fn执行
			_createWrapper fn开始
			var __super = this._super;
            var __superApply = this._supperApply;
            _createWrapper fn结束
            _create fn结束
  		 */
		this._createWrapper();
	},
	_init: function () {
		if (this.options.autoOpen) {
			this.open();
		}
	},
	open: function () {},
	_createWrapper: function () {}
});
</script>
 类似资料: