From a77d36748217a13e81d4d98f0833a39e75613bfd Mon Sep 17 00:00:00 2001 From: zhaiyb Date: Mon, 25 Sep 2017 14:42:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0dialog=E8=83=BD=E5=90=A6?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/Dialog.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ui/Dialog.js b/src/ui/Dialog.js index 7562e20..79a858d 100644 --- a/src/ui/Dialog.js +++ b/src/ui/Dialog.js @@ -28,7 +28,8 @@ function Dialog(dialog, options) { theme: window.bizui.theme, title: '', buttons: [], - destroyOnClose: false + destroyOnClose: false, + canClose: true }; this.options = $.extend(defaultOption, options || {}); this.init(this.options); @@ -47,7 +48,7 @@ Dialog.prototype = { * @param {Object} options 参数 * @private */ - init: function(options) { + init: function (options) { // 在 body 下创建对话框和遮罩层 this.$container = $('
'); this.$mask = $(''); @@ -59,11 +60,11 @@ Dialog.prototype = { .html([ '
', '', this.$main.attr('data-title') || options.title, '', - '
', + options.canClose ? '' : '', '
', '
' ].join('')) - .on('click.bizDialog', '.biz-dialog-close', function() { + .on('click.bizDialog', '.biz-dialog-close', function () { self.close(); }); this.$container.find('.biz-dialog-content').append(this.$main.show()); // 把目标元素移至 $container 中 @@ -112,7 +113,7 @@ Dialog.prototype = { /** * 打开对话框 */ - open: function() { + open: function () { var index = this.options.zIndex || ++currentIndex; this.$mask.css({ @@ -133,7 +134,7 @@ Dialog.prototype = { /** * 关闭对话框 */ - close: function() { + close: function () { var result = true; if (typeof this.options.onBeforeClose == 'function') { result = this.options.onBeforeClose(); @@ -157,15 +158,15 @@ Dialog.prototype = { * 更新按钮 * @param {Array} buttonOption 底部按钮的 option 数组 */ - updateButtons: function(buttonOption) { + updateButtons: function (buttonOption) { buttonOption = buttonOption || []; var bottom = this.$container.find('.biz-dialog-bottom'), self = this; bottom.find('button').bizButton('destroy').off().remove(); - $.each(buttonOption, function(index, buttonOption) { + $.each(buttonOption, function (index, buttonOption) { var button = $('').appendTo(bottom).bizButton(buttonOption); if (buttonOption.onClick) { - button.click(function(e) { + button.click(function (e) { buttonOption.onClick.call(self, e); }); } @@ -177,7 +178,7 @@ Dialog.prototype = { * @param {String} [title] 标题 * @return {String} */ - title: function(title) { + title: function (title) { var titleElement = this.$container.find('.biz-panel-title-text'); if (undefined === title) { return titleElement.html(); @@ -188,7 +189,7 @@ Dialog.prototype = { /** * 销毁 */ - destroy: function() { + destroy: function () { if (this.options.draggable) { this.draggable.destroy(); } @@ -200,7 +201,7 @@ Dialog.prototype = { } }; -var alert = function(options) { +var alert = function (options) { if (!jQuery.isPlainObject(options)) { options = { content: options @@ -221,7 +222,7 @@ var alert = function(options) { buttons: [{ text: options.okText, theme: options.theme, - onClick: function() { + onClick: function () { this.close(); } }] @@ -229,7 +230,7 @@ var alert = function(options) { alert.bizDialog('open'); }; -var confirm = function(options) { +var confirm = function (options) { var defaultOption = { content: '', okText: '确定', @@ -245,7 +246,7 @@ var confirm = function(options) { buttons: [{ text: options.okText, theme: options.theme, - onClick: function() { + onClick: function () { var result = true; if (typeof options.onOK == 'function') { result = options.onOK(); @@ -258,7 +259,7 @@ var confirm = function(options) { }, { text: options.cancelText, theme: 'gray', - onClick: function() { + onClick: function () { this.close(); } }] @@ -267,9 +268,9 @@ var confirm = function(options) { }; $.extend($.fn, { - bizDialog: function(method) { + bizDialog: function (method) { var internal_return, args = arguments; - this.each(function() { + this.each(function () { var instance = $(this).data(dataKey); if (instance) { if (typeof method === 'string' && typeof instance[method] === 'function') { From 823b9066b17a47a413dd38b81ccb8114800da872 Mon Sep 17 00:00:00 2001 From: zhaiyb Date: Mon, 25 Sep 2017 14:49:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=A4=B1?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/Dialog.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ui/Dialog.js b/src/ui/Dialog.js index 79a858d..ed494ea 100644 --- a/src/ui/Dialog.js +++ b/src/ui/Dialog.js @@ -48,7 +48,7 @@ Dialog.prototype = { * @param {Object} options 参数 * @private */ - init: function (options) { + init: function(options) { // 在 body 下创建对话框和遮罩层 this.$container = $('
'); this.$mask = $(''); @@ -64,7 +64,7 @@ Dialog.prototype = { '
', '
' ].join('')) - .on('click.bizDialog', '.biz-dialog-close', function () { + .on('click.bizDialog', '.biz-dialog-close', function() { self.close(); }); this.$container.find('.biz-dialog-content').append(this.$main.show()); // 把目标元素移至 $container 中 @@ -113,7 +113,7 @@ Dialog.prototype = { /** * 打开对话框 */ - open: function () { + open: function() { var index = this.options.zIndex || ++currentIndex; this.$mask.css({ @@ -134,7 +134,7 @@ Dialog.prototype = { /** * 关闭对话框 */ - close: function () { + close: function() { var result = true; if (typeof this.options.onBeforeClose == 'function') { result = this.options.onBeforeClose(); @@ -158,15 +158,15 @@ Dialog.prototype = { * 更新按钮 * @param {Array} buttonOption 底部按钮的 option 数组 */ - updateButtons: function (buttonOption) { + updateButtons: function(buttonOption) { buttonOption = buttonOption || []; var bottom = this.$container.find('.biz-dialog-bottom'), self = this; bottom.find('button').bizButton('destroy').off().remove(); - $.each(buttonOption, function (index, buttonOption) { + $.each(buttonOption, function(index, buttonOption) { var button = $('').appendTo(bottom).bizButton(buttonOption); if (buttonOption.onClick) { - button.click(function (e) { + button.click(function(e) { buttonOption.onClick.call(self, e); }); } @@ -178,7 +178,7 @@ Dialog.prototype = { * @param {String} [title] 标题 * @return {String} */ - title: function (title) { + title: function(title) { var titleElement = this.$container.find('.biz-panel-title-text'); if (undefined === title) { return titleElement.html(); @@ -189,7 +189,7 @@ Dialog.prototype = { /** * 销毁 */ - destroy: function () { + destroy: function() { if (this.options.draggable) { this.draggable.destroy(); } @@ -201,7 +201,7 @@ Dialog.prototype = { } }; -var alert = function (options) { +var alert = function(options) { if (!jQuery.isPlainObject(options)) { options = { content: options @@ -222,7 +222,7 @@ var alert = function (options) { buttons: [{ text: options.okText, theme: options.theme, - onClick: function () { + onClick: function() { this.close(); } }] @@ -230,7 +230,7 @@ var alert = function (options) { alert.bizDialog('open'); }; -var confirm = function (options) { +var confirm = function(options) { var defaultOption = { content: '', okText: '确定', @@ -246,7 +246,7 @@ var confirm = function (options) { buttons: [{ text: options.okText, theme: options.theme, - onClick: function () { + onClick: function() { var result = true; if (typeof options.onOK == 'function') { result = options.onOK(); @@ -259,7 +259,7 @@ var confirm = function (options) { }, { text: options.cancelText, theme: 'gray', - onClick: function () { + onClick: function() { this.close(); } }] @@ -268,9 +268,9 @@ var confirm = function (options) { }; $.extend($.fn, { - bizDialog: function (method) { + bizDialog: function(method) { var internal_return, args = arguments; - this.each(function () { + this.each(function() { var instance = $(this).data(dataKey); if (instance) { if (typeof method === 'string' && typeof instance[method] === 'function') {