jquery.util.easyui.dialog
(function ($) {
var $parent = parent.$;
//获取弹出窗口数据集合
function getDialogs() {
var dialogs = $parent("#div_index_data").data("dialogs");
dialogs = dialogs || [];
if ($.util.isEmptyObjectOrNull(dialogs))
return [];
return dialogs;
}
//获取当前弹出窗口数据
function getCurrentDialog() {
var dialogs = getDialogs();
return dialogs[dialogs.length - 1] || {};
}
//获取当前弹出窗口Id
function getCurrentDialogId() {
return getCurrentDialog().id;
}
//添加弹出窗口数据,包括弹出窗口Id和jQuery对象
function addDialog(id) {
var data = getDialogs();
data.push({ id: id, caller: window });
$parent("#div_index_data").data("dialogs", data);
}
//移除当前弹出窗口数据
function removeCurrentDialog() {
var dialogs = getDialogs();
dialogs.pop();
}
//树形操作
$.easyui.dialog = function () {
return {
//添加弹出框
addDialog: function (id) {
addDialog(id);
return getCurrentDialog();
},
//获取原调用者window对象
getCaller: function () {
return getCurrentDialog().caller;
},
//获取原调用者jQuery对象
getCaller$: function () {
return getCurrentDialog().caller.$;
},
//获取弹出窗window对象
getCurrent: function () {
var dialogId = getCurrentDialogId();
return top.frames[dialogId + "_iframe"] ? (!top.frames[dialogId + "_iframe"].contentWindow ? top.frames[dialogId + "_iframe"] : top.frames[dialogId + "_iframe"].contentWindow) : top.contentWindow;
},
//获取弹出窗jQuery对象
getCurrent$: function () {
var dialogId = getCurrentDialogId();
return top.frames[dialogId + "_iframe"] ? (!top.frames[dialogId + "_iframe"].contentWindow ? top.frames[dialogId + "_iframe"].$ : top.frames[dialogId + "_iframe"].contentWindow.$) : top.contentWindow.$;
},
//打开弹出窗口
open: function (options) {
/// <summary>
/// 弹出模态窗,解决在Iframe中无法全屏遮罩,
/// 注意:仅支持url弹窗
/// </summary>
/// <param name="options" type="Object">
/// 1. title:标题
/// 2. url:网址
/// 3. buttons:显示在窗口底部的按钮区域div的id
/// 4. icon:图标class
/// 5. width:宽度
/// 6. height:高度
/// 7. onInit:初始化事件,返回false跳出执行
/// </param>
initOptions();
if (!options.onInit(options))
return;
var dialog = createDialow();
show();
addDialog(options.id);
//初始化参数
function initOptions() {
options = $.extend({
id: $.util.newGuid(""),
title: '',
url: '',
icon: 'icon-standard-common-window',
width: 600,
height: 360,
iframe: true,
closed: false,
maximizable: true,
resizable: true,
cache: false,
modal: true,
buttons: '',
onInit: function () {
return true;
},
closeCallback: function () { }
}, options || {});
}
//创建窗口div
function createDialow() {
if (options.iframe) {
return $parent("<div id='" + options.id + "' style='overflow:visible;'><iframe id='" + options.id + "_iframe' scrolling=\"auto\" frameborder=\"0\" style=\"width:100%;height:100%;\" src='" + options.url + "' ></iframe></div>").appendTo('body');
} else {
return $parent("<div id='" + options.id + "'></div>").appendTo('body');
}
}
//弹出窗口
function show() {
dialog.dialog({
title: options.title,
href: options.iframe ? "" : options.url,
width: options.width,
height: options.height,
closed: options.closed,
maximizable: options.maximizable,
resizable: options.resizable,
cache: options.cache,
modal: options.modal,
iconCls: options.icon,
buttons: options.buttons,
border: false,
onLoad: function () {
},
onClose: function () {
options.closeCallback();
$parent("#" + getCurrentDialogId()).dialog('destroy');
removeCurrentDialog();
}
});
}
},
openCommon: function (url, title, width, height, callBack) {
$.easyui.dialog.open({
title: title,
url: url,
width: width,
height: height,
buttons: [{
text: '确定',
iconCls: 'icon-standard-common-ok',
handler: function () {
callBack(getCurrentDialogId());
}
}, {
text: '取消',
iconCls: 'icon-standard-common-cancel',
handler: function () {
$.easyui.dialog.close();
}
}]
});
},
//关闭弹出窗口
close: function () {
var dialogId = getCurrentDialogId();
if (!dialogId)
return;
$parent('#' + dialogId).dialog('close');
},
//打开Tab页面
openTab: function (tabid, url, name, img) {
addDialog("tabs_iframe_" + tabid);
AddTabMenu(tabid, url, name, img, true, true, true);
},
//关闭当前Tab页面
closeTab: function () {
removeCurrentDialog();
ThisCloseTab();
}
}
}();
})(jQuery);