From d5a35a2c3ae5bfab9fa1d0803065df3401a6046b Mon Sep 17 00:00:00 2001 From: evecalm Date: Mon, 23 Jun 2014 17:43:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=94=AF=E6=8C=81iframe=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=20=E5=A6=82=E8=8B=A5=E6=9C=AA?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEiframe=E9=AB=98=E5=BA=A6,=20iframe=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=A4=A7=E5=B0=8F=E5=8F=98=E5=8C=96=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E7=88=B6=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E6=97=B6=E5=88=99=E8=87=AA=E5=8A=A8=E8=B0=83=E8=8A=82=E5=85=B6?= =?UTF-8?q?=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dialog-plus.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/dialog-plus.js b/src/dialog-plus.js index a4395ce..0138f93 100644 --- a/src/dialog-plus.js +++ b/src/dialog-plus.js @@ -56,6 +56,39 @@ dialog.oncreate = function (api) { if (!options.height) { api.height($iframe.contents().height()); + // 节流, 避免在事件流中频繁执行回调函数浪费浏览器资源 + // fn为回调函数; wait为回调执行的间隔时间, 单位ms; context为执行环境 + var throttle = function (fn, wait, context) { + var tid = null; + var lastTime; + context = context || this; + return function thrttl () { + var now = +new Date(); + if (!lastTime) lastTime = now; + var remain = wait - (now - lastTime); + if (remain <= 0) { + clearTimeout(tid); + tid = null; + fn.call(context); + lastTime = now; + } else if(!tid) { + tid = setTimeout(thrttl, remain); + } + } + } + // 调节iframe高度, 触发时每200ms执行一次 + var adjustHeight = throttle(function () { + // iframe高度取iframe内容高度和其父窗口高度的最小值 + // 120px 为对话框本身 header和footer占用高度 + api.height(Math.min($iframe.contents().height(), $(window).height() - 120)); + }, 200); + // iframe内容变化时调整iframe高度 + // 事件 DOMSubtreeModified 针对标准浏览器 + // 事件 propertychange 则针对IE + $iframe.contents().on('DOMSubtreeModified propertychange',adjustHeight); + // 父窗口大小改变时调整iframe大小 + $(window).on('resize', adjustHeight); + } } From cf1e5917b3d51263c27348d3759d794d9da2ed32 Mon Sep 17 00:00:00 2001 From: Saiya Date: Mon, 23 Jun 2014 17:55:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20scrolling=20=E4=B8=BA?= =?UTF-8?q?=20'yes'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iframe高度自适应是从自己的项目中扣出来的, 忘记改这关键配置项了 --- src/dialog-plus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dialog-plus.js b/src/dialog-plus.js index 0138f93..044cbc5 100644 --- a/src/dialog-plus.js +++ b/src/dialog-plus.js @@ -38,7 +38,7 @@ dialog.oncreate = function (api) { height: '100%', allowtransparency: 'yes', frameborder: 'no', - scrolling: 'no' + scrolling: 'yes' }) .on('load', function () { var test; From 28d588c32a63aab4a142f95db6474328c0fd1d2f Mon Sep 17 00:00:00 2001 From: evecalm Date: Fri, 18 Jul 2014 15:34:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fixed=20bug:=20=E4=BD=BF=E7=94=A8iframe?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E8=AF=9D=E6=A1=86=E5=9C=A8=E9=99=A4=E6=97=B6?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=BA=8B=E4=BB=B6=E7=BB=91=E5=AE=9A,=20?= =?UTF-8?q?=E9=81=BF=E5=85=8DjQuery=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dialog-plus.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dialog-plus.js b/src/dialog-plus.js index 0138f93..baba880 100644 --- a/src/dialog-plus.js +++ b/src/dialog-plus.js @@ -88,7 +88,11 @@ dialog.oncreate = function (api) { $iframe.contents().on('DOMSubtreeModified propertychange',adjustHeight); // 父窗口大小改变时调整iframe大小 $(window).on('resize', adjustHeight); - + // 在对话框移除时去掉事件绑定 + api.onbeforeremove = function () { + $iframe.contents().off('DOMSubtreeModified propertychange',adjustHeight); + $(window).off('resize', adjustHeight); + } } }