zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* jQuery EasyUI 1.3.6
* Copyright (c) 2009-2014 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact author: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* jQuery EasyUI combo Extensions 1.0 beta
* jQuery EasyUI combo 组件扩展
* jeasyui.extensions.combo.js
* 二次开发 流云
* 最近更新:2014-05-28
*
* 依赖项:
*   1、jquery.jdirk.js v1.0 beta late
*   2、jeasyui.extensions.js v1.0 beta late
*
* Copyright (c) 2013-2014 ChenJianwei personal All rights reserved.
* http://www.chenjianwei.org
*/
(function ($, undefined) {
 
    $.fn.combo.extensions = {};
 
    function setPrompt(target, prompt) {
        var t = $(target), opts = t.combo("options"), textbox = t.combo("textbox");
        opts.prompt = prompt;
        textbox.validatebox("setPrompt", prompt);
    };
 
    function setIcon(target, iconCls) {
        var t = $(target), state = $.data(target, "combo"), combo = state.combo;
        var arrow = combo.find("span.combo-arrow").removeAttr("class").addClass("combo-arrow");
        if (iconCls) { arrow.addClass(iconCls); }
        t.combo("options").iconCls = iconCls;
    }
 
    function setRequired(target, required) {
        var t = $(target), opts = t.combo("options"), textbox = t.combo("textbox");
        opts.required = textbox.validatebox("options").required = required;
    };
 
    var _destroy = $.fn.combo.methods.destroy;
    function destroy(target) {
        var t = $(target), opts = t.combo("options");
        if ($.isFunction(opts.onBeforeDestroy) && opts.onBeforeDestroy.call(target) == false) { return; }
        _destroy.call(target, t);
        if ($.isFunction(opts.onDestroy)) { opts.onDestroy.call(target); }
    };
 
    function getCombo(target) {
        return $.data(target, "combo").combo;
    };
 
 
    var _setValues = $.fn.combo.methods.setValues;
    function setValues(target, values) {
        var t = $(target), opts = t.combo("options");
        if (!opts.nullable && $.array.isNullOrEmpty(values)) {
            values = [null];
        }
        return _setValues.call(t, t, values);
    };
 
    function clear(target) {
        var state = $.data(target, "combo"), opts = state.options, combo = state.combo;
        if (opts.multiple) {
            combo.find("input.combo-value" + (opts.nullable ? "" : ":gt(0)")).remove();
        }
        combo.find("input.combo-value,input.combo-text").val("");
    };
 
 
 
 
    function initialize(target) {
        var t = $(target), state = $.data(target, "combo"),
            opts = t.combo("options"), panel = state.panel,
            combo = state.combo, //arrow = combo.find(".combo-arrow"),
            exts = opts.extensions ? opts.extensions : opts.extensions = {};
        if (!exts._initialized) {
            t.combo("textbox").focus(function () {
                if (opts.autoShowPanel && panel.is(":hidden")) { t.combo("showPanel"); }
            });
            if (opts.iconCls) { t.combo("setIcon", opts.iconCls); }
            if ($.util.browser.msie && combo._outerWidth() != opts.width) {
                $.util.exec(function () { t.combo("resize", opts.width); });
            }
            exts._initialized = true;
        }
    }
 
 
    var _combo = $.fn.combo;
    $.fn.combo = function (options, param) {
        if (typeof options == "string") {
            return _combo.apply(this, arguments);
        }
        options = options || {};
        return this.each(function () {
            var jq = $(this), hasInit = $.data(this, "combo") ? true : false,
                opts = hasInit ? options : $.extend({}, $.fn.combo.parseOptions(this), $.parser.parseOptions(this, [
                    "iconCls", { autoShowPanel: "boolean" }
                ]), options);
            _combo.call(jq, opts);
            initialize(this);
        });
    };
    $.union($.fn.combo, _combo);
 
 
    var defaults = $.fn.combo.extensions.defaults = {
        //  增加 easyui-combo 的自定义扩展属性;表示该 combo 组件的 iconCls 图标样式类;
        //  String 类型值,默认为 null。
        iconCls: null,
 
        //  增加 easyui-combo 的自定义扩展属性;表示该 combox 组件是否在 textbox 文本显示框获取焦点时自动执行 showPanel 方法显示下拉 panel 面板;
        //  Boolean 类型值,默认为 true。
        autoShowPanel: true,
 
        //  增加 easyui-combo 的自定义扩展属性;表示该 combox 组件是否允许值为 Null。
        //  注意:nullable 值为 true 时,表示当该 combo 组件没有值(例如执行 clear 方法后,或者 setValue/setValues 设置为的值为 null/undefined/空数组 后)时,
        //      该组件内的所有 input:hidden.combo-value DOM标签将会被清空。
        //      而当 nullable 的值设置为 false 时,在该 combo 组件没有值时,也会保留一个值为空字符串("")的 input:hidden.combo-value DOM标签。
        //  Boolean 类型值,默认为 true。
        nullable: true,
 
        onBeforeDestroy: function () { },
 
        onDestroy: function () { }
    };
 
    var methods = $.fn.combo.extensions.methods = {
        //  扩展 easyui-combo 组件的自定义方法;用于设置 easyui-combo 控件的右侧显示图标,该方法定义如下参数:
        //      iconCls:    String 类型的值,表示需要设置的图标的 css 类样式名,例如 "icon-ok", "icon-save"
        //  返回值:返回表示当前 easyui-combo 控件的 jQuery 链式对象。
        setIcon: function (jq, iconCls) { return jq.each(function () { setIcon(this, iconCls); }); },
 
        //  扩展 easyui-combo 组件的自定义方法;用于设置启用或者禁用 easyui-combo 控件的表单验证功能,该方法定义如下参数:
        //      required:   Boolean 类型的值,表示启用或者禁用 easyui-combo 控件的表单验证功能。
        //  返回值:返回表示当前 easyui-combo 控件的 jQuery 链式对象。
        setRequired: function (jq, required) { return jq.each(function () { setRequired(this, required); }); },
 
        //  扩展 easyui-combo 组件的自定义方法;用于设置该 combo 的 textbox 输入框的 prompt(输入提示文字) 值;该方法定义如下参数:
        //      prompt: String 类型值,表示要被设置的 prompt 值;
        //  返回值:返回表示当前 easyui-combo 控件的 jQuery 链式对象。
        setPrompt: function (jq, prompt) { return jq.each(function () { setPrompt(this, prompt); }); },
 
        destroy: function (jq) { return jq.each(function () { destroy(this); }); },
 
        combo: function (jq) { return getCombo(jq[0]); },
 
        //  重写 easyui-combo 组件的 setValues 方法,以支持相应扩展功能。
        setValues: function (jq, values) { return jq.each(function () { setValues(this, values); }); },
 
        //  重写 easyui-combo 组件的 setValues 方法,以支持相应扩展功能。
        clear: function (jq) { return jq.each(function () { clear(this); }); }
    };
    $.extend($.fn.combo.defaults, defaults);
    $.extend($.fn.combo.methods, methods);
 
 
 
 
 
    //  下面这段代码实现即使在跨 IFRAME 的情况下,一个 WEB-PAGE 中也只能同时显示一个 easyui-combo panel 控件。
    $.easyui.bindPageNestedFunc("mousedown", "jdirkCombo", "combo", function (win, e) {
        var jq = win.jQuery, p = jq(e.target).closest("span.combo,div.combo-p");
        if (p.length) {
            jq(p).find(".combo-f").each(function () {
                var panel = jq(this).combo("panel");
                if (panel.is(":visible")) {
                    panel.panel("close");
                }
            });
            if (e.target && e.target.ownerDocument == win.document) {
                return;
            }
        }
        jq("body>div.combo-p>div.combo-panel:visible").panel("close");
    });
 
 
})(jQuery);