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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/**
* 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 dialog Extensions 1.0 beta
* jQuery EasyUI dialog 组件扩展
* jeasyui.extensions.dialog.js
* 二次开发 流云
* 最近更新:2014-05-12
*
* 依赖项:
*   1、jquery.jdirk.js v1.0 beta late
*   2、jeasyui.extensions.js v1.0 beta late
*   3、jeasyui.extensions.linkbutton.js v1.0 beta late
*   4、jeasyui.extensions.menu.js v1.0 beta late
*   5、jeasyui.extensions.panel.js v1.0 beta late
*   6、jeasyui.extensions.window.js v1.0 beta late
*
* Copyright (c) 2013-2014 ChenJianwei personal All rights reserved.
* http://www.chenjianwei.org
*/
(function ($, undefined) {
 
 
    $.fn.dialog.extensions = {};
 
 
 
    var easyui = $.util.$.easyui ? $.util.$.easyui : $.easyui,
        cache = easyui.frameMapCache ? easyui.frameMapCache : easyui.frameMapCache = [];
 
    function resetCache(iframe) {
        var array = $.array.filter(cache, function (val) { return val.current == iframe; }), l = array.length;
        while (l--) { $.array.remove(cache, array[l]); };
    };
 
    var getParent = function () {
        var current = $.util.currentFrame;
        if (!current) { return $.util.top; }
        var p = $.array.first(cache, function (val) { return val.current == current; });
        return (p && p.parent && p.parent.contentWindow) ? p.parent.contentWindow : $.util.parent;
    };
    //  该属性仅可以在通过 $.easyui.showDialog 打开的 easyui-dialog 中的 iframe 中使用;
    //  该属性表示父级页面的 window 对象。
    $.easyui.parent = getParent();
 
    //  该方法仅可以在通过 $.easyui.showDialog 打开的 easyui-dialog 中的 iframe 中使用;
    //  关闭当前页面所在的 easyui-dialog 窗体。
    $.easyui.parent.closeDialog = $.easyui.closeCurrentDialog = function () {
        if ($.util.isUtilTop) { return; }
        $.easyui.parent.$($.util.currentFrame).closest("div.window-body").dialog("close");
    };
 
    $.easyui._showDialog = function (opts, currentFrame) {
        if (opts.onApply == null || opts.onApply == undefined) { opts.onApply = opts.onSave; }
        if (opts.onSave == null || opts.onSave == undefined) { opts.onSave = opts.onApply; }
 
        var _onClose = opts.onClose;
        opts.onClose = function () {
            if ($.isFunction(_onClose)) { _onClose.apply(this, arguments); }
            $.fn.dialog.defaults.onClose.apply(this, arguments);
            if (opts.autoDestroy) {
                $(this).dialog("destroy");
            }
        };
 
        var _onBeforeDestroy = opts.onBeforeDestroy;
        opts.onBeforeDestroy = function () {
            if (opts.iniframe) {
                var iframe = $(this).dialog("iframe");
                resetCache(iframe[0]);
            }
            var ret;
            if ($.isFunction(_onBeforeDestroy)) {
                ret = _onBeforeDestroy.apply(this, arguments);
            }
            if ($.fn.dialog.defaults.onBeforeDestroy.apply(this, arguments) == false) {
                return false;
            }
            return ret;
        };
 
        if (opts.locale) { opts.inline = true; }
        var dialog = $("<div></div>").appendTo(opts.locale ? opts.locale : "body");
 
        if (!$.util.likeArray(opts.toolbar)) { opts.toolbar = []; }
        if ($.isArray(opts.toolbar)) {
            $.each(opts.toolbar, function () {
                var handler = this.handler;
                if ($.isFunction(handler)) { this.handler = function () { handler.call(dialog, dialog); }; }
            });
            if (!opts.toolbar.length) { opts.toolbar = null; }
        }
 
        var buttons = [
            btnSave = {
                id: "save", text: opts.saveButtonText, iconCls: opts.saveButtonIconCls,
                index: opts.saveButtonIndex, hidden: opts.enableSaveButton ? false : true,
                handler: function (dia) {
                    var isFunc = $.isFunction(opts.onSave);
                    if (!isFunc || isFunc && opts.onSave.call(this, dia) !== false) {
                        $.util.exec(function () { dia.dialog("close"); });
                    }
                }
            },
            btnClose = {
                id: "close", text: opts.closeButtonText, iconCls: opts.closeButtonIconCls,
                index: opts.closeButtonIndex, hidden: opts.enableCloseButton ? false : true,
                handler: function (dia) { dia.dialog("close"); }
            },
            btnApply = {
                id: "apply", text: opts.applyButtonText, iconCls: opts.applyButtonIconCls,
                index: opts.applyButtonIndex, hidden: opts.enableApplyButton ? false : true,
                handler: function (dia) {
                    var isFunc = $.isFunction(opts.onApply);
                    if (!isFunc || isFunc && opts.onApply.call(this, dia) !== false) {
                        dia.applyButton.linkbutton("disable");
                    }
                }
            }
        ];
 
        if (!$.util.likeArrayNotString(opts.buttons)) { opts.buttons = []; }
        $.array.merge(opts.buttons, buttons);
        opts.buttons = $.array.filter(opts.buttons, function (val) { return $.util.parseFunction(val.hidden, val) ? false : true; });
        $.each(opts.buttons, function (i, btn) {
            var handler = btn.handler;
            if ($.isFunction(handler)) { btn.handler = function () { handler.call(this, dialog); }; }
        });
        $.array.sort(opts.buttons, function (a, b) {
            return ($.isNumeric(a.index) ? a.index : 0) - ($.isNumeric(b.index) ? b.index : 0);
        });
 
 
        if (!opts.buttons.length) { opts.buttons = null; }
 
        opts = dialog.dialog(opts).dialog("options");
 
        var dialogBody = dialog.dialog("body"),
            buttonbar = dialogBody.children(".dialog-button").each(function () {
                var color = dialog.css("border-bottom-color");
                $(this).addClass("calendar-header").css({ "height": "auto", "border-top-color": color });
            }),
            bottombuttons = buttonbar.children("a");
        if (opts.buttonsPlain) { bottombuttons.linkbutton("setPlain", true); }
        if (!opts.iniframe) {
            if (opts.href) {
                var toolbuttons = dialog.dialog("header").find(".panel-tool a");
                toolbuttons.attr("disabled", "disabled");
                bottombuttons.linkbutton("disable");
                var onLoad = opts.onLoad;
                opts.onLoad = function () {
                    if ($.isFunction(onLoad)) { onLoad.apply(this, arguments); }
                    $.util.exec(function () {
                        toolbuttons.removeAttr("disabled");
                        bottombuttons.linkbutton("enable");
                    });
                };
            }
        }
        var iframe = dialog.dialog("iframe");
        if (iframe.length) { cache.push({ current: iframe[0], parent: currentFrame }); }
 
        $.extend(dialog, {
            options: opts,
            iframe: iframe,
            buttons: bottombuttons,
            closeButtn: buttonbar.children("#close"),
            saveButton: buttonbar.children("#save"),
            applyButton: buttonbar.children("#apply"),
            save: function () { btnSave.handler(); },
            close: function () { btnClose.handler(); },
            apply: function () { btnApply.handler(); }
        });
 
        return dialog;
    };
 
    //  以 easyui-dialog 方法在当前浏览器窗口的顶级(可访问)窗体中弹出对话框窗口;该函数定义如下参数:
    //      options:    一个 JSON Object,具体格式参考 easyui-dialog 官方 api 中的属性列表。
    //          该参数在 easyui-dialog 官方 api 所有原属性列表基础上,增加如下属性:
    //          iniframe:
    //          enableSaveButton:
    //          enableApplyButton:
    //          enableCloseButton:
    //          onSave:
    //          onClose:
    //          saveButtonText:
    //          applyButtonText:
    //          closeButtonText:
    //          saveButtonIconCls:
    //          applyButtonIconCls:
    //          closeButtonIconCls:
    //          buttonsPlain:
    //      另,重写 easyui-dialog 官方 api 的 buttons 属性,使其不支持 String-jQuerySelector 格式
    //  备注:
    //  返回值:返回弹出的 easyui-dialog 的 jQuery 对象。
    $.easyui.showDialog = function (options) {
        var opts = $.extend({}, $.easyui.showDialog.defaults, options);
        if (opts.locale) { opts.topMost = false; }
        var currentFrame = $.util.currentFrame, fn = opts.topMost ? $.util.$.easyui._showDialog : $.easyui._showDialog;
        return fn(opts, currentFrame);
    };
 
 
 
    //  通过调用 $.easyui.showDialog 方法,以 easyui-dialog 的方式显示一个 JSON - Object 对象的所有属性值;该函数定义如下参数:
    //      options:    需要显示的 JSON - Object;
    //      dialogOption:  该参数可选,表示要打开的 easyui-dialog 的 options。
    //  备注:该方法一般用于对象值显示,例如可以用于项目开发过程中的参数显示调试。
    //  返回值:返回弹出的 easyui-dialog 的 jQuery 对象。
    $.easyui.showOption = function (options, dialogOption) {
        options = options || "无数据显示。";
        var opts = $.extend({
            topMost: $.easyui.showDialog.defaults.topMost,
            title: "显示 options 值",
            width: 480,
            height: 260,
            minWidth: 360,
            minHeight: 220,
            autoVCenter: false,
            autoHCenter: false,
            enableSaveButton: false,
            enableApplyButton: false
        }, dialogOption || {}), jq = opts.topMost ? $.util.$ : $;
        var content = jq("<table class=\"dialog-options-body\" ></table>"), type = jq.type(options);
        if ($.array.contains(["array", "object", "function"], type)) {
            for (var key in options) {
                content.append("<tr class=\"dialog-options-row\"><td class=\"dialog-options-cell\">" + key + ":</td><td class=\"dialog-options-cell-content\">" + $.string.toHtmlEncode(options[key]) + "</td></tr>");
            }
        } else {
            content.append("<tr class=\"dialog-options-row\"><td class=\"dialog-options-cell\">options:</td><td class=\"dialog-options-cell-content\">" + $.string.toHtmlEncode(String(options)) + "</td></tr>");
        }
        opts.content = content;
        return $.easyui.showDialog(opts);
    };
 
 
 
 
 
 
    function refresh(target, href) {
        var dia = $(target), opts = dia.dialog("options"), cp = dia.dialog("contentPanel"), coOpts = cp.panel("options");
        if (href) {
            opts.href = href;
        }
        coOpts.iniframe = opts.iniframe;
        cp.panel("refresh", opts.href);
    };
 
    function getContentPanel(target) {
        var state = $.data(target, "dialog");
        return state ? state.contentPanel : null;
    };
 
    function getIframe(target) {
        var panel = getContentPanel(target);
        return panel.panel("iframe");
    };
 
    function parseExtensionsBegin(options) {
        options._extensionsDialog = {
            href: options.href, content: options.content, iniframe: options.iniframe,
            bodyCls: options.bodyCls, bodyStyle: options.bodyStyle
        };
        options.bodyCls = null;
        options.bodyStyle = null;
        if (options.iniframe) {
            options.href = null;
            options.content = null;
            options.iniframe = false;
        }
    };
    function parseExtensionsEnd(target) {
        var d = $(target), opts = d.dialog("options"), cp = getContentPanel(target),
            exts = opts._extensionsDialog ? opts._extensionsDialog : opts._extensionsDialog = { href: opts.href, content: opts.content, iniframe: opts.iniframe };
        opts.href = exts.href; opts.content = exts.content; opts.iniframe = exts.iniframe;
        opts.bodyCls = exts.bodyCls; opts.bodyStyle = exts.bodyStyle;
        if (cp && cp.length) {
            if (opts.bodyCls) { cp.addClass(opts.bodyCls); }
            if (opts.bodyStyle) { cp.css(opts.bodyStyle); }
        }
        if (opts.iniframe) {
            refresh(target);
        }
    };
 
    var _dialog = $.fn.dialog;
    $.fn.dialog = function (options, param) {
        if (typeof options == "string") {
            return _dialog.apply(this, arguments);
        }
        options = options || {};
        return this.each(function () {
            var jq = $(this), hasInit = $.data(this, "dialog") ? true : false,
                opts = hasInit ? options : $.extend({}, $.fn.dialog.parseOptions(this), options);
            parseExtensionsBegin(opts);
            _dialog.call(jq, opts);
            parseExtensionsEnd(this);
        });
    };
    $.union($.fn.dialog, _dialog);
 
 
    var methods = $.fn.dialog.extensions.methods = {
        //  修复 easyui-dialog 组件的 options 方法返回的 width 和 height 属性不正确的 BUG
        options: function (jq) {
            var state = $.data(jq[0], "dialog"), opts = state.options,
                pp = jq.panel("options");
            $.extend(opts, {
                closed: pp.closed, collapsed: pp.collapsed, minimized: pp.minimized, maximized: pp.maximized,
                width: pp.width, height: pp.height
            });
            return opts;
        },
 
        //  扩展 easyui-dialog 控件的自定义方法;获取当前 easyui-dialog 控件的内容面板 panel 对象。
        contentPanel: function (jq) { return getContentPanel(jq[0]); },
 
        //  重写 easyui-panel 控件的自定义方法 iframe;获取当前 easyui-dialog 控件内容面板 panel 对象中的 iframe 对象。
        //  备注:如果 inirame: false,则该方法返回一个空的 jQuery 对象。
        iframe: function (jq) { return getIframe(jq[0]); },
 
        //  重写 easyui-dialog 控件的 refresh 方法,用于支持 iniframe 属性。
        refresh: function (jq, href) { return jq.each(function () { refresh(this, href); }); }
    };
    var defaults = $.fn.dialog.extensions.defaults = $.extend({}, $.fn.window.extensions.defaults, {
 
    });
 
    $.extend($.fn.dialog.defaults, defaults);
    $.extend($.fn.dialog.methods, methods);
 
 
 
    //  定义 $.easyui.showDialog 方法打开 easyui-dialog 窗体的默认属性。
    //  备注:该默认属性定义仅在方法 $.easyui.showDialog 中被调用。
    $.easyui.showDialog.defaults = {
        title: "新建对话框",
        iconCls: "icon-standard-application-form",
        width: 600,
        height: 360,
        modal: true,
        collapsible: false,
        maximizable: false,
        closable: true,
        draggable: true,
        resizable: true,
        shadow: true,
        minimizable: false,
 
        href: null,
 
        //  表示弹出的 easyui-dialog 窗体是否在关闭时自动销毁并释放浏览器资源;
        //  Boolean 类型值,默认为 true。
        autoDestroy: true,
 
        //  表示将要打开的 easyui-dialog 的父级容器;可以是一个表示 jQuery 元素选择器的表达式字符串,也可以是一个 html-dom 或 jQuery-dom 对象。
        //  注意:如果设置了该参数,则 topMost 属性将自动设置为 false。
        //      如果为 null 或者 undefined 则表示父级容器为 body 标签。
        locale: null,
 
        //  是否在顶级窗口打开此 easyui-dialog 组件。
        topMost: false,
 
        //  是否在iframe加载远程 href 页面数据
        iniframe: false,
 
        //  是否启用保存按钮,保存按钮点击后会关闭模式对话框
        enableSaveButton: true,
 
        //  是否启用应用按钮
        enableApplyButton: true,
 
        //  是否启用关闭按钮
        enableCloseButton: true,
 
        saveButtonIndex: 101,
 
        closeButtonIndex: 102,
 
        applyButtonIndex: 103,
 
        //  点击保存按钮触发的事件,如果该事件范围 false,则点击保存后窗口不关闭。
        onSave: null,
 
        //  点击应用按钮触发的事件,如果该事件范围 false,则点击应用后该按钮不被自动禁用。
        onApply: null,
 
        //  关闭窗口时应触发的事件,easyui-dialog本身就有
        onClose: null,
 
        //  保存按钮的文字内容
        saveButtonText: "确定",
 
        //  关闭按钮的文字内容
        closeButtonText: "取消",
 
        //  应用按钮的文字内容
        applyButtonText: "应用",
 
        //  保存按钮的图标样式
        saveButtonIconCls: "icon-save",
 
        //  应用按钮的图标样式
        applyButtonIconCls: "icon-ok",
 
        //  关闭按钮的图标样式
        closeButtonIconCls: "icon-cancel",
 
        //  底部工具栏的所有按钮是否全部设置 plain: true
        buttonsPlain: false
    };
 
})(jQuery);