Skip to content

Commit 16143f5

Browse files
committedApr 19, 2018
Added onClose event
#1 @blindfish3
1 parent 76d7856 commit 16143f5

7 files changed

+305
-223
lines changed
 

‎demo/Snackbar.html

+9-2
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,16 @@ <h4 style="margin-bottom: 3px;">configuration</h4>
261261
<tr>
262262
<td>onActionClick</td>
263263
<td>
264-
<i>dismiss function</i>
264+
<i>function(ele)</i>
265265
</td>
266-
<td>Default action closes the notification. A function with the notification element as the argument.</td>
266+
<td>Default action closes the notification.</td>
267+
</tr>
268+
<tr>
269+
<td>onClose</td>
270+
<td>
271+
<i>function(ele)</i>
272+
</td>
273+
<td>Fires when the notification has been closed.</td>
267274
</tr>
268275
</tbody>
269276
</table>

‎dist/snackbar.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*!
2-
* Snackbar v0.1.9
2+
* Snackbar v0.1.10
33
* http://polonel.com/Snackbar
44
*
5-
* Copyright 2017 Chris Brame and other contributors
5+
* Copyright 2018 Chris Brame and other contributors
66
* Released under the MIT license
77
* https://github.com/polonel/Snackbar/blob/master/LICENSE
88
*/
@@ -40,7 +40,8 @@
4040
onActionClick: function(element) {
4141
element.style.opacity = 0;
4242
},
43-
onSecondButtonClick: function(element) {}
43+
onSecondButtonClick: function(element) {},
44+
onClose: function(element) {}
4445
};
4546

4647
Snackbar.show = function($options) {
@@ -100,7 +101,7 @@
100101
function() {
101102
if (Snackbar.current === this) {
102103
Snackbar.current.style.opacity = 0;
103-
// When natural remove event ocurs let's move the snackbar to its origins
104+
// When natural remove event occurs let's move the snackbar to its origins
104105
Snackbar.current.style.top = '-100px';
105106
Snackbar.current.style.bottom = '-100px';
106107
}
@@ -113,6 +114,9 @@
113114
'transitionend',
114115
function(event, elapsed) {
115116
if (event.propertyName === 'opacity' && this.style.opacity === '0') {
117+
if (typeof(options.onClose) === 'function')
118+
options.onClose(this);
119+
116120
this.parentElement.removeChild(this);
117121
if (Snackbar.current === this) {
118122
Snackbar.current = null;

‎dist/snackbar.min.js

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

‎dist/snackbar.min.js.map

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

‎package-lock.json

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

‎package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-snackbar",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"description": "Notifications insipired by Google Material Design",
55
"main": "src/js/snackbar.js",
66
"devDependencies": {
@@ -10,10 +10,9 @@
1010
"grunt-contrib-copy": "^0.8.2",
1111
"grunt-contrib-cssmin": "^0.14.0",
1212
"grunt-contrib-jshint": "^0.12.0",
13-
"grunt-contrib-sass": "^0.9.2",
1413
"grunt-contrib-uglify": "^0.11.1",
1514
"grunt-contrib-watch": "^0.6.1",
16-
"grunt-sass": "^2.0.0",
15+
"grunt-sass": "^2.1.0",
1716
"matchdep": "^1.0.0"
1817
},
1918
"scripts": {

‎src/js/snackbar.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*!
2-
* Snackbar v0.1.9
2+
* Snackbar v0.1.10
33
* http://polonel.com/Snackbar
44
*
5-
* Copyright 2017 Chris Brame and other contributors
5+
* Copyright 2018 Chris Brame and other contributors
66
* Released under the MIT license
77
* https://github.com/polonel/Snackbar/blob/master/LICENSE
88
*/
@@ -40,7 +40,8 @@
4040
onActionClick: function(element) {
4141
element.style.opacity = 0;
4242
},
43-
onSecondButtonClick: function(element) {}
43+
onSecondButtonClick: function(element) {},
44+
onClose: function(element) {}
4445
};
4546

4647
Snackbar.show = function($options) {
@@ -100,7 +101,7 @@
100101
function() {
101102
if (Snackbar.current === this) {
102103
Snackbar.current.style.opacity = 0;
103-
// When natural remove event ocurs let's move the snackbar to its origins
104+
// When natural remove event occurs let's move the snackbar to its origins
104105
Snackbar.current.style.top = '-100px';
105106
Snackbar.current.style.bottom = '-100px';
106107
}
@@ -113,6 +114,9 @@
113114
'transitionend',
114115
function(event, elapsed) {
115116
if (event.propertyName === 'opacity' && this.style.opacity === '0') {
117+
if (typeof(options.onClose) === 'function')
118+
options.onClose(this);
119+
116120
this.parentElement.removeChild(this);
117121
if (Snackbar.current === this) {
118122
Snackbar.current = null;

0 commit comments

Comments
 (0)
Please sign in to comment.