Skip to content

Commit

Permalink
增加 弹窗支持按钮点击后不关闭
Browse files Browse the repository at this point in the history
增加 弹窗显示后,body 内容不可以再滚动配置项
  • Loading branch information
sufangyu committed Apr 12, 2018
1 parent 7651e71 commit d17a9a5
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ Temporary Items
.apdisk

node_modules/
.idea/
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 2.1.0 (2018-04-12)
+ 增加 弹窗支持按钮点击后不关闭;
+ 增加 弹窗显示后,body 内容不可以再滚动配置项;
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ $(document).on('click', '#btn-01', function() {
<td>'提示'</td>
<td>标题文字</td>
</tr>
<tr>
<td>bodyNoScroll</td>
<td>false</td>
<td>body 内容不可以滚动</td>
</tr>
<tr>
<td>closeBtnShow</td>
<td>false</td>
Expand Down Expand Up @@ -269,3 +274,16 @@ npm install
grunt serve
```

**3、grunt 命令**
```
grunt serve // 浏览 Demo: 本地服务器
grunt dist // 开发环境: 生产实际项目使用代码
grunt src // 开发环境: 本地服务器; 实时刷新
```

## 最新版本
### 2.1.0 (2018-04-12)
+ 增加 弹窗支持按钮点击后不关闭;
+ 增加 弹窗显示后,body 内容不可以再滚动配置项;

[全部更新日志](https://github.com/sufangyu/dialog2/blob/master/Changelog.md)
3 changes: 1 addition & 2 deletions _config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dialog",
"description": "兼容jQuery与Zepto的移动端弹窗插件。",
"version": "2.0.0",
"version": "2.1.0",
"homepage": "https://github.com/sufangyu/dialog2",
"download": "https://github.com/sufangyu/dialog2/archive/master.zip",
"bugs": "https://github.com/sufangyu/dialog2/issues",
Expand All @@ -13,7 +13,6 @@

"dist": {
"dir": "dist"

},

"src":{
Expand Down
64 changes: 51 additions & 13 deletions dist/js/dialog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* dialog v2.0.0
* @date 2016-10-12
* @author 方雨_Yu
* dialog v2.1.0
* @date 2018-04-12
* @author 方雨_Yu
* @home https://github.com/sufangyu/dialog2
* @bugs https://github.com/sufangyu/dialog2/issues
* Licensed under MIT
Expand Down Expand Up @@ -31,6 +31,8 @@
*/
_init: function() {
var self = this;

console.log('初始化弹窗');

clearTimeout(self.autoCloseTimer);

Expand All @@ -39,6 +41,13 @@
self.platform = mobileUtil.platform; // 访问设备平台
self.dislogStyle = self.settings.style==='default' ? self.platform : self.settings.style; // 弹窗风格, 默认自动判断平台; 否则, 为指定平台


// 创建弹窗显示时, 禁止 body 内容滚动的样式并且添加到 head
if ($('#dialog-body-no-scroll').length === 0) {
var styleContent = '.body-no-scroll { position: absolute; overflow: hidden; width: 100%; }';
$('head').append('<style id="dialog-body-no-scroll">'+ styleContent +'</style>');
}

self._renderDOM();
self._bindEvents();
},
Expand All @@ -62,24 +71,30 @@

// 确定按钮关闭弹窗
self.$confirmBtn.on(mobileUtil.tapEvent, function(ev) {
self.closeDialog();
self.settings.onClickConfirmBtn();
var callback = self.settings.onClickConfirmBtn();
if (callback || callback === undefined) {
self.closeDialog();
}
}).on('touchend', function(ev) {
ev.preventDefault();
});

// 取消按钮关闭弹窗
self.$cancelBtn.on(mobileUtil.tapEvent, function(ev) {
self.closeDialog();
self.settings.onClickCancelBtn();
var callback = self.settings.onClickCancelBtn();
if (callback || callback === undefined) {
self.closeDialog();
}
}).on('touchend', function(ev) {
ev.preventDefault();
});

// 关闭按钮关闭弹窗
self.$closeBtn.on(mobileUtil.tapEvent, function(ev) {
self.closeDialog();
self.settings.onClickCloseBtn();
var callback = self.settings.onClickCloseBtn();
if (callback || callback === undefined) {
self.closeDialog();
}
}).on('touchend', function(ev) {
ev.preventDefault();
});
Expand Down Expand Up @@ -112,9 +127,11 @@
if (self.settings.buttons.length) {
$.each(self.settings.buttons, function(index, item) {
self.$dialogContentFt.children('button').eq(index).on(mobileUtil.tapEvent, function(ev) {
self.closeDialog();
item.callback();
ev.preventDefault();
var callback = item.callback();
if (callback || callback === undefined) {
self.closeDialog();
}
});
});
}
Expand Down Expand Up @@ -192,6 +209,10 @@
self.$dialog.append(self.$dialogContent);
$('body').append(self.$dialog);

if (self.settings.bodyNoScroll) {
$('body').addClass('body-no-scroll');
}

// 设置弹窗提示内容最大高度
if (self.settings.contentScroll) {
self._setDialogContentHeight();
Expand Down Expand Up @@ -235,7 +256,11 @@
// 设置弹窗提示内容最大高度
if (self.settings.contentScroll) {
self._setDialogContentHeight();
}
}

if (self.settings.bodyNoScroll) {
$('body').addClass('body-no-scroll');
}

break;
case 'toast':
Expand Down Expand Up @@ -263,6 +288,10 @@
self.$dialog.append(self.$dialogContent);
$('body').append(self.$dialog);

if (self.settings.bodyNoScroll) {
$('body').addClass('body-no-scroll');
}

break;
case 'notice':
// 添加 toast 类型弹窗标识
Expand Down Expand Up @@ -294,6 +323,10 @@
self.$dialog.append(self.$dialogContent);
$('body').append(self.$dialog);

if (self.settings.bodyNoScroll) {
$('body').addClass('body-no-scroll');
}

break;
default:
console.log('running default');
Expand Down Expand Up @@ -436,6 +469,10 @@
self.settings.onClosed();
// 重新初始化默认配置
self.settings = $.fn.dialog.defaults;

if (self.settings.bodyNoScroll) {
$('body').removeClass('body-no-scroll');
}
},

/**
Expand Down Expand Up @@ -593,6 +630,7 @@
style : 'default', // alert 与 confirm 弹窗的风格 [ default: 根据访问设备平台; ios: ios 风格; android: MD design 风格 ]
titleShow : true, // 是否显示标题
titleText : '提示', // 标题文字
bodyNoScroll : false, // body内容不可以滚动
closeBtnShow : false, // 是否显示关闭按钮
content : '', // 弹窗提示内容, 值可以是 HTML 内容
contentScroll: true, // alert 与 confirm 弹窗提示内容是否限制最大高度, 使其可以滚动
Expand Down Expand Up @@ -679,7 +717,7 @@
});

// 注册快捷事件 tapEvent, 调用: $element.tapEvent(fn);
['tapEvent'].forEach(function(eventName) {
;['tapEvent'].forEach(function(eventName) {
$.fn[eventName] = function(callback) {
return this.on(eventName, callback);
};
Expand Down
6 changes: 3 additions & 3 deletions dist/js/dialog.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/js/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $(function() {
/* ########## alert ########## */
$(document).on('click', '#btn-01', function() {
var dialog1 = $(document).dialog({
// content: '<input type="text" />'
content: '我是默认的弹窗。这里是提示信息内容'
// content: '我是默认的弹窗。这里是提示信息内容。我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。',
// content: '我是默认的弹窗。这里是提示信息内容。我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容我是默认的弹窗。这里是提示信息内容',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dialog",
"description": "兼容jQuery与Zepto的移动端弹窗插件。",
"version": "2.0.0",
"version": "2.1.0",
"homepage": "https://github.com/sufangyu/dialog2",
"author": {
"name": "方雨_Yu",
Expand Down
2 changes: 0 additions & 2 deletions src/css/dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
}

.dialog-content-ft {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
Expand All @@ -148,7 +147,6 @@
transform: scaleY(0.5);
}
.dialog-content-ft .dialog-btn {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
Expand Down
7 changes: 2 additions & 5 deletions src/css/tmpl.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ button {
}

a {
-webkit-transition: -webkit-transform 1s;
transition: transform 1s;
display: -webkit-box;
transition: -webkit-transform 1s;
transition: transform 1s;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
Expand Down Expand Up @@ -239,7 +238,6 @@ body {
.history-version li {
padding: 5px 0 5px 15px;
position: relative;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
Expand All @@ -263,7 +261,6 @@ body {
margin-right: 10px;
}
.history-version .time {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
Expand Down
Loading

0 comments on commit d17a9a5

Please sign in to comment.