提交 f2646b3e 编写于 作者: C Catouse

* support display multiple messagers.

上级 9176ee01
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
'use strict'; 'use strict';
var id = 0; var id = 0;
var template = '<div class="messager messager-{type} {placement}" id="messager{id}" style="display:none"><div class="messager-actions"></div><div class="messager-content"></div></div>'; var template = '<div class="messager messager-{type} {placement}" id="messager{id}"><div class="messager-content"></div><div class="messager-actions"></div></div>';
var defaultOptions = { var defaultOptions = {
type: 'default', type: 'default',
placement: 'top', placement: 'top',
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
fade: true, fade: true,
scale: true scale: true
}; };
var lastMessager; var all = {};
var Messager = function(message, options) { var Messager = function(message, options) {
var that = this; var that = this;
...@@ -100,14 +100,6 @@ ...@@ -100,14 +100,6 @@
var that = this, var that = this,
options = this.options; options = this.options;
if(lastMessager) {
if(lastMessager.id == that.id) {
that.$.removeClass('in');
} else if(lastMessager.isShow) {
lastMessager.hide();
}
}
if(that.hiding) { if(that.hiding) {
clearTimeout(that.hiding); clearTimeout(that.hiding);
that.hiding = null; that.hiding = null;
...@@ -118,14 +110,18 @@ ...@@ -118,14 +110,18 @@
that.$.find('.messager-content').html(that.message); that.$.find('.messager-content').html(that.message);
} }
that.$.appendTo(options.parent).show(); if(that.isShow) return;
if(options.placement === 'top' || options.placement === 'bottom' || options.placement === 'center') { var placement = options.placement;
that.$.css('left', ($(window).width() - that.$.width()) / 2); var $parent = $(options.parent);
var $holder = $parent.children('.messagers-holder.' + placement);
if(!$holder.length) {
$holder = $('<div/>').attr('class', 'messagers-holder ' + placement).appendTo($parent);
} }
$holder.append(that.$);
if(options.placement === 'left' || options.placement === 'right' || options.placement === 'center') { if(placement === 'center') {
that.$.css('top', ($(window).height() - that.$.height()) / 2); var offset = $(window).height() - $holder.height();
$holder.css('top', Math.max(-offset, offset/2));
} }
that.$.addClass('in'); that.$.addClass('in');
...@@ -137,7 +133,6 @@ ...@@ -137,7 +133,6 @@
} }
that.isShow = true; that.isShow = true;
lastMessager = that;
}; };
Messager.prototype.hide = function() { Messager.prototype.hide = function() {
...@@ -145,7 +140,9 @@ ...@@ -145,7 +140,9 @@
if(that.$.hasClass('in')) { if(that.$.hasClass('in')) {
that.$.removeClass('in'); that.$.removeClass('in');
setTimeout(function() { setTimeout(function() {
var $parent = that.$.parent();
that.$.remove(); that.$.remove();
if(!$parent.children().length) $parent.remove();
}, 200); }, 200);
} }
......
...@@ -9,47 +9,19 @@ ...@@ -9,47 +9,19 @@
// Messager style for module messager.js // Messager style for module messager.js
.messager { .messager {
position: fixed; display: table;
color: @color-light; color: @color-light;
background-color: @color-dark; background-color: @color-dark;
background-color: rgba(0, 0, 0, 0.8); background-color: rgba(0, 0, 0, 0.8);
border-radius: @messager-radius; border-radius: @messager-radius;
max-width: 80%; margin: 10px;
z-index: 99999; pointer-events: auto;
&:extend(.clearfix all);
&.top {
top: 20px;
}
&.top-left {
top: 20px;
left: 20px;
}
&.top-right {
top: 20px;
right: 20px;
}
&.bottom {
bottom: 20px;
}
&.bottom-left {
bottom: 20px;
left: 20px;
}
&.bottom-right {
bottom: 20px;
right: 20px;
}
} }
.messager-content { .messager-content {
padding: 10px 20px; padding: 10px 15px;
float: left; display: table-cell;
vertical-align: top;
> [class^='icon-'] { > [class^='icon-'] {
display: inline-block; display: inline-block;
...@@ -58,7 +30,8 @@ ...@@ -58,7 +30,8 @@
} }
.messager-actions { .messager-actions {
float: right; display: table-cell;
vertical-align: top;
> .action { > .action {
color: #fafafa; color: #fafafa;
...@@ -87,6 +60,61 @@ ...@@ -87,6 +60,61 @@
.action-icon + .action-text {margin-left: 8px;} .action-icon + .action-text {margin-left: 8px;}
} }
.messagers-holder {
z-index: 99999;
position: fixed;
padding: 10px;
pointer-events: none;
.transition-fast(top);
&.top {
top: 0;
}
&.top-left {
top: 0;
left: 0;
}
&.top-right {
top: 0;
right: 0;
}
&.bottom {
bottom: 0;
}
&.bottom-left {
bottom: 0;
left: 0;
}
&.bottom-right {
bottom: 0;
right: 0;
}
&.top-right,
&.bottom-right {
.messager { margin-left: auto; }
}
&.center {
top: 0;
}
&.top,
&.bottom,
&.center {
left: 0;
right: 0;
.messager { margin: 10px auto; }
}
}
.messager-primary { .messager-primary {
background-color: @state-primary-inverse-bg; background-color: @state-primary-inverse-bg;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册