Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增isAutoRemove配置;调整quickClose的行为 #243

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/dialog-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ define({
// 注意:css 只允许加载一个
cssUri: '../css/ui-dialog.css',

// 是否在tirgger一些未定义的事件的时候,自动在close之后remove掉弹窗
isAutoRemove: true,

// 模板(使用 table 解决 IE7 宽度自适应的 BUG)
// js 使用 i="***" 属性识别结构,其余的均可自定义
innerHTML:
Expand Down Expand Up @@ -90,4 +93,4 @@ define({
+ '</table>'
+'</div>'

});
});
16 changes: 13 additions & 3 deletions src/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ var artDialog = function (options, ok, cancel) {
// 快捷关闭支持:点击对话框外快速关闭对话框
if (options.quickClose) {
options.modal = true;
options.backdropOpacity = 0;
}


Expand Down Expand Up @@ -454,8 +453,19 @@ $.extend(prototype, {
_trigger: function (id) {
var fn = this.callbacks[id];

return typeof fn !== 'function' || fn.call(this) !== false ?
this.close().remove() : this;
if (typeof fn !== 'function' || fn.call(this) !== false) {

// 根据是否isAutoRemove来判断是否需要执行remove()
if (this.isAutoRemove) {
res = this.close().remove();
} else {
res = this.close();
}
} else {
res = this;
}

return res;
}

});
Expand Down
41 changes: 41 additions & 0 deletions test/isAutoRemove.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<button data-event="test">open dialog</button>
<script src="../lib/sea.js"></script>
<script>
seajs.config({
alias: {
"jquery": "jquery-1.10.2.js"
}
});
</script>

<script>
seajs.use(['jquery', '../src/dialog'], function ($, dialog) {


$('button[data-event=test]').on('click', function () {
var d = dialog({
title: '消息',
content: '风吹起的青色衣衫,夕阳里的温暖容颜,你比以前更加美丽,像盛开的花<br>——许巍《难忘的一天》',
quickClose: true,

/**
* 设定为false, 在没有设定cancel的时候 点击空白处关闭 不删除dialog的结构
* 设定为true, 在没有设定cancel的时候 点击空白处关闭 删除dialog结构
*/
isAutoRemove: true
});

d.show();
});

});
</script>
</body>
</html>