Skip to content
This repository was archived by the owner on Nov 11, 2022. It is now read-only.

Commit 391026f

Browse files
committed
introduced "newestOnTop" option. Closes #73
1 parent e0fb59d commit 391026f

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

dist/ngToast.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
combineDuplications: false,
2727
horizontalPosition: 'right', // right, center, left
2828
verticalPosition: 'top', // top, bottom,
29-
maxNumber: 0
29+
maxNumber: 0,
30+
newestOnTop: true
3031
};
3132

3233
function Message(msg) {
@@ -104,12 +105,9 @@
104105
}
105106

106107
var newMsg = new Message(msg);
107-
if (defaults.verticalPosition === 'bottom') {
108-
messages.unshift(newMsg);
109-
} else {
110-
messages.push(newMsg);
111-
}
108+
messages[defaults.newestOnTop ? 'unshift' : 'push'](newMsg);
112109
messageStack.push(newMsg.id);
110+
113111
return newMsg.id;
114112
},
115113
success: function(msg) {

dist/ngToast.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripts/provider.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
combineDuplications: false,
2121
horizontalPosition: 'right', // right, center, left
2222
verticalPosition: 'top', // top, bottom,
23-
maxNumber: 0
23+
maxNumber: 0,
24+
newestOnTop: true
2425
};
2526

2627
function Message(msg) {
@@ -98,12 +99,9 @@
9899
}
99100

100101
var newMsg = new Message(msg);
101-
if (defaults.verticalPosition === 'bottom') {
102-
messages.unshift(newMsg);
103-
} else {
104-
messages.push(newMsg);
105-
}
102+
messages[defaults.newestOnTop ? 'unshift' : 'push'](newMsg);
106103
messageStack.push(newMsg.id);
104+
107105
return newMsg.id;
108106
},
109107
success: function(msg) {

test/spec/service.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('ngToast:', function() {
2525

2626
ngToast.create({content: 'toast2'});
2727
expect(ngToast.messages.length).toBe(2);
28-
expect(ngToast.messages[1].content).toBe('toast2');
28+
expect(ngToast.messages[0].content).toBe('toast2');
2929
});
3030

3131
it('success should work', function () {
@@ -38,8 +38,8 @@ describe('ngToast:', function() {
3838
content: 'toast2'
3939
});
4040
expect(ngToast.messages.length).toBe(2);
41-
expect(ngToast.messages[1].content).toBe('toast2');
42-
expect(ngToast.messages[1].className).toBe('success');
41+
expect(ngToast.messages[0].content).toBe('toast2');
42+
expect(ngToast.messages[0].className).toBe('success');
4343
});
4444

4545
it('info should work', function () {
@@ -63,13 +63,15 @@ describe('ngToast:', function() {
6363
expect(ngToast.messages[0].className).toBe('danger');
6464
});
6565

66-
it('create should work in reverse order when vertical position is set as bottom', function () {
66+
it('should respect to newestOnTop flag', function () {
6767
ngToast.create('toast1');
6868

69-
ngToast.settings.verticalPosition = 'bottom';
7069
ngToast.create('toast2');
71-
expect(ngToast.messages.length).toBe(2);
7270
expect(ngToast.messages[0].content).toBe('toast2');
71+
72+
ngToast.settings.newestOnTop = false;
73+
ngToast.create('toast3');
74+
expect(ngToast.messages[2].content).toBe('toast3');
7375
});
7476

7577
it('create should dismiss first message when reached to max limit', function () {
@@ -79,7 +81,8 @@ describe('ngToast:', function() {
7981

8082
ngToast.create('toast3');
8183
expect(ngToast.messages.length).toBe(2);
82-
expect(ngToast.messages[0].content).toBe('toast2');
84+
expect(ngToast.messages[0].content).toBe('toast3');
85+
expect(ngToast.messages[1].content).toBe('toast2');
8386
});
8487

8588
it('dismiss should work', function () {
@@ -88,13 +91,13 @@ describe('ngToast:', function() {
8891

8992
ngToast.dismiss(-1); // non-existent id
9093
expect(ngToast.messages.length).toBe(2);
91-
expect(ngToast.messages[0].content).toBe('toast1');
92-
93-
ngToast.dismiss(toast1);
94-
expect(ngToast.messages.length).toBe(1);
9594
expect(ngToast.messages[0].content).toBe('toast2');
9695

9796
ngToast.dismiss(toast2);
97+
expect(ngToast.messages.length).toBe(1);
98+
expect(ngToast.messages[0].content).toBe('toast1');
99+
100+
ngToast.dismiss(toast1);
98101
expect(ngToast.messages.length).toBe(0);
99102
});
100103

0 commit comments

Comments
 (0)