/** * 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 = $("
").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("