easyui的window插件再次封装

说明:该插件弹出的弹出框在最顶层的页面中,而不是在当前页面所在的iframe中,它的可拖动范围是整个浏览器窗口;所以不能用JS的parent对象获取弹出它的父页面,这里用了一个笨方法,最多支持四级弹出框,即弹出框中再弹出弹出框的情况,笨方法也是方法,它很简单、很有效。

代码:

/**
* easyui的window插件再次封装
* 2014年11月10日
*/ SimpoWin = {
showWin: function showWindow(title, url, width, height) {
if (!top.SimpoWinId) top.SimpoWinId = 0;
var divId = "simpoWin" + top.SimpoWinId;
top.$("body").append('<div id="' + divId + '"></div>'); top.$('#' + divId).window({
modal: true,
title: title,
width: width,
height: height,
collapsible: false,
minimizable: false,
maximizable: false,
content: function () {
return '<iframe frameborder="0" src="' + url + '" style="width: ' + (width - 14).toString() + 'px; height: ' + (height - 39).toString() + 'px; margin: 0;">';
},
onClose: function () {
top.$('#' + divId).window('destroy');
top.SimpoWinId--;
}
}).window('open'); top.SimpoWinId++;
switch (top.SimpoWinId) {
case 1:
top.SimpoWinParent1 = window;
break;
case 2:
top.SimpoWinParent2 = window;
break;
case 3:
top.SimpoWinParent3 = window;
break;
default:
top.SimpoWinParent = window;
break;
}
}, closeWin: function () {
var divId = "simpoWin" + (top.SimpoWinId - 1).toString();
top.$('#' + divId).window('close');
}, GetWinParent: function () {
switch (top.SimpoWinId) {
case 1:
return top.SimpoWinParent1;
case 2:
return top.SimpoWinParent2;
case 3:
return top.SimpoWinParent3;
default:
return top.SimpoWinParent;
}
}
}

带回调函数版,支持传入url或div容器id:

/**
* easyui的window插件再次封装
* 2014年11月10日
*/ SimpoWin = {
showWin: function (title, url, width, height, okcallback, closecallback) {
if (!top.SimpoWinId) top.SimpoWinId = 0;
var divId = "simpoWin" + top.SimpoWinId;
top.$("body").append('<div id="' + divId + '"></div>'); top.$('#' + divId).window({
modal: true,
title: title,
width: width,
height: height,
collapsible: false,
minimizable: false,
maximizable: false,
content: function () {
return '<iframe frameborder="0" src="' + url + '" style="width: ' + (width - 14).toString() + 'px; height: ' + (height - 39).toString() + 'px; margin: 0;">';
},
onClose: function () {
top.$('#' + divId).window('destroy');
top.SimpoWinId--;
if (closecallback) closecallback();
}
}).window('open'); top.SimpoWinId++;
switch (top.SimpoWinId) {
case 1:
top.SimpoWinParent1 = window;
top.SimpoWinOKCallback1 = okcallback;
break;
case 2:
top.SimpoWinParent2 = window;
top.SimpoWinOKCallback2 = okcallback;
break;
case 3:
top.SimpoWinParent3 = window;
top.SimpoWinOKCallback3 = okcallback;
break;
default:
top.SimpoWinParent = window;
top.SimpoWinOKCallback = okcallback;
break;
}
}, closeWin: function () {
var divId = "simpoWin" + (top.SimpoWinId - 1).toString();
top.$('#' + divId).window('close');
}, OK: function (data) {
switch (top.SimpoWinId) {
case 1:
top.SimpoWinOKCallback1(data);
case 2:
top.SimpoWinOKCallback2(data);
case 3:
top.SimpoWinOKCallback3(data);
default:
top.SimpoWinOKCallback(data);
}
}, GetWinParent: function () {
switch (top.SimpoWinId) {
case 1:
return top.SimpoWinParent1;
case 2:
return top.SimpoWinParent2;
case 3:
return top.SimpoWinParent3;
default:
return top.SimpoWinParent;
}
}, showWin2: function (title, containerId, width, height, closecallback) {
top.$('#' + containerId).css("display", "");
var l = (top.$(top.window).width() - width) / 2;
var t = (top.$(top.window).height() - height) / 2 + top.$(top.document).scrollTop();
top.$('#' + containerId).window({
modal: true,
title: title,
width: width,
height: height,
left: l,
top: t,
collapsible: false,
minimizable: false,
maximizable: false,
onClose: function () {
if (closecallback) closecallback();
}
}).window('open');
}, closeWin2: function (containerId) {
top.$('#' + containerId).window('close');
}
}

如何使用:

1、引用该插件的JS文件

2、父页面代码:

SimpoWin.showWin("选择素材", "TextMessageList.aspx", 880, 580);

3、子页面代码:

var winParent = SimpoWin.GetWinParent();
winParent.setValue(val); //子页面操作父页面
SimpoWin.closeWin(); //关闭弹出框

easyui的window插件再次封装的更多相关文章

  1. javascript笔记——jqGrid再次封装

    xingrunzhao js插件再次封装 demo 'use strict'; /** * commerce grid框架 * 依赖jqgrid */ (function ($_self, jQuer ...

  2. JS弹出框插件zDialog再次封装

    zDialog插件网址:http://www.jq22.com/jquery-info2426 再次封装zDialog的代码: (function ($) { $.extend({ iDialog: ...

  3. ajax的再次封装!(改进版) —— new与不 new 有啥区别?

    生命不息重构不止! 上一篇写了一下我对ajax的再次封装的方法,收到了很多有价值的回复,比如有童鞋建议用$.extend,一开始还以为要做成插件呢,后来才知道,原来这个东东还可以实现合并.省着自己再去 ...

  4. quartz.net插件类库封装(含源码)

    1.前言 目录: 1.quartz.net任务调度:源码及使用文档 2.quartz.net插件类库封装 最近项目需要做一写任务作业调度的工作,最终选择了quartz.net这个插件,它提供了巨大的灵 ...

  5. ajax的再次封装!

    js的动态加载.缓存.更新以及复用 系列有点卡文,放心会继续的.先来点更基础的,为js的加载做点铺垫. jQuery的ajax本来就很方便了,为啥还要在进一步的封装呢?这个首先要看项目的具体需求了,如 ...

  6. easyUI的window包含一个iframe,在iframe中如何关闭window?

    easyUI的window包含一个iframe,在iframe中如何关闭window? parent.$('#win').window('close');

  7. easyui表单插件-包括日期时控件-列表

    ← jQuery EasyUI 表单插件 – Numberspinner 数值微调器 jQuery EasyUI 表单插件 - Timespinner 时间微调器  jQuery EasyUI 插件 ...

  8. Easyui 让Window弹出居中

    原文:Easyui 让Window弹出居中 easyui1.3.2版本,window的弹出不会居中了.而dialog是会居中的,我们必须为为window的open事件做扩展 代码如下:只要加入以下代码 ...

  9. EasyUI在window中使用kindeditor 4.1.10在IE9中不能回显、获得焦点编辑的问题

    描述 :kindeditor4.1.10版本是当前最新的版本,在浏览器兼容性和功能方面都是值得一赞的,在开发中能方便快捷的满足一些开发需求. 问题 :  问题总是有的.  在使用过程中,遇到EasyU ...

随机推荐

  1. Aoite 系列(03) - 一起来 Redis 吧!

    Aoite 是一个适于任何 .Net Framework 4.0+ 项目的快速开发整体解决方案.Aoite.Data 适用于市面上大多数的数据库提供程序,通过统一封装,可以在日常开发中简单便捷的操作数 ...

  2. C语言#自动生成四则运算的编程

    #include <iostream> #include <stdio.h> #include <stdlib.h> #include <time.h> ...

  3. Silverlight中文本框添加回车事件后,换行无法清除的解决方法

    在开发Silverlight的项目中,为了更好的用户体验,我们常要给一些控件添加一些快捷键.然而,在Silverlight中当用户回车提交后,光标停留在文本框的第二行怎么也清除不掉,经过一段时间研究, ...

  4. MySQL--将MySQL数据导入到SQL Server

    随着时代的进步,社会的发展,各种技术层出不穷五花八门乱七八糟数不胜数(写作文呢!!!) 不扯废话,简单而言,很多公司都会同时使用多种数据库,因此数据在不同数据库之间导入导出就成为一个让人蛋疼的问题,对 ...

  5. java提高篇(十六)-----异常(一)

         Java的基本理念是“结构不佳的代码不能运行”!!!!! 大成若缺,其用不弊. 大盈若冲,其用不穷. 在这个世界不可能存在完美的东西,不管完美的思维有多么缜密,细心,我们都不可能考虑所有的因 ...

  6. js模版引擎handlebars.js实用教程——if-判断的基本用法

    返回目录 <!DOCTYPE html> <html> <head> <META http-equiv=Content-Type content=" ...

  7. Atitit 软件项目非法模块与功能的管理与  监狱管理的对比 原理与概论attilax总结

    Atitit 软件项目非法模块与功能的管理与  监狱管理的对比 原理与概论attilax总结 软件项目中的非法模块非法功能非法分子与人类中的非法分子很是相似,必须要建议不同的的约束管理标准化... 软 ...

  8. Iframe去掉滚动条

    <html><head><title></title></head><body STYLE='OVERFLOW:SCROLL;OVER ...

  9. Java-集合-第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList(); l

    第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; ...

  10. HTTP协议从入门到大牛,初识HTTP协议(学习笔记)

    HTTP数据传输协议 当访问一个网页时,浏览器会向服务器发起一条HTTP请求,接着服务器会去寻找相应的资源,如果请求成功,就会把这个对象,对象类型,对象长度以及其他的信息放在HTTP响应中,发送给客户 ...