Skip to content

Commit

Permalink
v6.0.1
Browse files Browse the repository at this point in the history
1. 进一步完善焦点管理,避免抢夺开发者自己设置的焦点#67
2. 修复对话框内容使用 html5 data-id 属性冲突的问题#78
3. 改善 Esc 快捷键与 cancel 的问题#36
  • Loading branch information
唐斌 committed Mar 16, 2014
1 parent 54daf34 commit e6cb6ac
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 18 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,27 @@ artDialog v6 —— 经典的网页对话框组件,内外皆用心雕琢。

测试通过:IE6-IE11、Chrome、Firefox、Safari、Opera

## 更新历史

6.0.1

1. 进一步完善焦点管理,避免抢夺开发者自己设置的焦点[#67](https://github.com/aui/artDialog/issues/67)
2. 修复对话框内容使用 html5 data-id 属性冲突的问题[#78](https://github.com/aui/artDialog/issues/78)
3. 改善 Esc 快捷键与 cancel 的问题[#36](https://github.com/aui/artDialog/issues/36)

6.0.0

1. 功能增强:支持定义左下角的区域 HTML、支持 12 个方向的气泡对话框、支持无标题栏与按钮区的对话框
2. 更好的交互体验:更加先进的焦点管理,支持无障碍访问
3. 面向未来:基于 HTML5 Dialog 的 API
4. 模块化:支持 AMD、CMD 规范
5. 可选增强插件:拖拽支持、简化框架页面调用

## 授权协议

免费,且开源,基于[LGPL](./LICENSE.md)协议。

## 支持开源
## 支持我们

[贡献代码](https://github.com/aui/artDialog) || [捐赠一杯咖啡](https://me.alipay.com/planeart) || [商业授权](./LICENSE.md)

Expand Down
1 change: 1 addition & 0 deletions src/dialog-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
define(function (require) {

var $ = require('jquery');
var dialog = require('./dialog');
var drag = require('./drag');

Expand Down
34 changes: 19 additions & 15 deletions src/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ artDialog.create = function (options) {


// 按钮组点击
$popup.on('click', '[data-id]', function (event) {
$popup.on('click', '[data-dialog-button]', function (event) {
var $this = $(this);
if (!$this.attr('disabled')) {// IE BUG
that._trigger($this.data('id'));
that._trigger($this.data('dialog-button'));
}

event.preventDefault();
Expand All @@ -192,23 +192,21 @@ artDialog.create = function (options) {

// ESC 快捷键关闭对话框
this._esc = function (event) {
var target = event.target;
var nodeName = target.nodeName;
var rinput = /^input|textarea$/i;
var isTop = Popup.current === that;
var keyCode = event.keyCode;

// 避免输入状态中 ESC 误操作关闭
if (!isTop || rinput.test(nodeName) && target.type !== 'button') {
return;
}

if (keyCode === 27) {
if (isTop && keyCode === 27 && that.options.cancel !== false) {
that._trigger('cancel');
}
};


// 避免使用 keyup 事件,否则中文输入法可能出问题
// @see: https://www.imququ.com/post/60.html
$(document).on('keydown', this._esc);


// 对话框卸载的时候进行清理
this.addEventListener('remove', function () {
$(document).off('keydown', this._esc);
delete artDialog.list[this.id];
Expand Down Expand Up @@ -385,7 +383,7 @@ $.extend(prototype, {
html +=
'<button'
+ ' type="button"'
+ ' data-id="' + val.id + '"'
+ ' data-dialog-button="' + val.id + '"'
+ (val.disabled ? ' disabled' : '')
+ (val.autofocus ? ' autofocus class="ui-dialog-autofocus"' : '')
+ '>'
Expand Down Expand Up @@ -418,9 +416,11 @@ $.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) {
this.close().remove();
}

}

});
Expand Down Expand Up @@ -460,6 +460,10 @@ artDialog.defaults = defaults;



Popup.dialog = artDialog;
artDialog.Popup = Popup;


return artDialog;

});
Expand Down
6 changes: 4 additions & 2 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ $.extend(Popup.prototype, {
blur: function () {

var activeElement = this.__activeElement;
var isBlur = arguments[0];
var isBlur = arguments[0] !== false;
var node = this.node;
var active = this.__getActive();


if (isBlur !== false) {
if (isBlur && ($.contains(node, active) || active == node)) {
this.__focus(activeElement);
}

Expand Down
40 changes: 40 additions & 0 deletions test/focus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<button data-event="test">open dialog</button> <input id="input" />
<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 () {
$('#input').focus();
var d = dialog({
quickClose: true,
autofocus: false,
content: '输入错误,请重新输入',
okValue: '确 定',
onclose: function () {
$('#input').focus();
},
follow: $('#input')[0]
});

d.show();
});

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

0 comments on commit e6cb6ac

Please sign in to comment.