Skip to content

Commit 8ea0ef4

Browse files
committed
Fixed an issue with duration incorrectly applied
1 parent effc4a5 commit 8ea0ef4

File tree

5 files changed

+270
-292
lines changed

5 files changed

+270
-292
lines changed

dist/snackbar.js

Lines changed: 132 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,162 @@
11
/*!
2-
* Snackbar v0.1.3
2+
* Snackbar v0.1.4
33
* http://polonel.com/Snackbar
44
*
55
* Copyright 2016 Chris Brame and other contributors
66
* Released under the MIT license
77
* https://github.com/polonel/Snackbar/blob/master/LICENSE
88
*/
99

10-
(function () {
11-
'use strict';
10+
(function (root, factory) {
11+
'use strict';
12+
13+
if (typeof define === 'function' && define.amd) {
14+
define([], function() {
15+
return (root.Snackbar = factory());
16+
});
17+
} else if(typeof module === 'object' && module.exports) {
18+
module.exports = (root.Snackbar = factory());
19+
} else {
20+
root.Snackbar = factory();
21+
}
1222

13-
var root = typeof self == 'object' && self.self === self && self ||
14-
typeof global == 'object' && global.global === global && global ||
15-
this;
23+
}(this, function() {
24+
var Snackbar = {};
1625

17-
var Snackbar = function (obj) {
18-
if (obj instanceof Snackbar) return Snackbar;
19-
if (!(this instanceof Snackbar)) return new Snackbar(obj);
20-
this._wrapped = obj;
21-
};
26+
Snackbar.current = null;
27+
var $defaults = {
2228

23-
if (typeof exports != 'undefined' && !exports.nodeType) {
24-
if (typeof module != 'undefined' && !module.nodeType && module.exports) {
25-
exports = module.exports = Snackbar;
26-
}
27-
exports.Snackbar = Snackbar;
28-
} else {
29-
root.Snackbar = Snackbar;
30-
}
29+
text: 'Default Text',
30+
textColor: '#ffffff',
3131

32-
Snackbar.current = null;
33-
var $defaults = {
32+
width: 'auto',
3433

35-
text: 'Default Text',
36-
textColor: '#ffffff',
34+
showAction: true,
35+
actionText: 'Dismiss',
36+
actionTextColor: '#4caf50',
3737

38-
width: 'auto',
38+
backgroundColor: '#323232',
3939

40-
showAction: true,
41-
actionText: 'Dismiss',
42-
actionTextColor: '#4caf50',
40+
pos: 'bottom-left',
4341

44-
backgroundColor: '#323232',
42+
duration: 5000,
4543

46-
pos: 'bottom-left',
44+
customClass: '',
4745

48-
duration: 5000,
46+
onActionClick: function (element) {
47+
element.style.opacity = 0;
48+
}
49+
};
4950

50-
customClass: '',
51+
Snackbar.show = function ($options) {
52+
var options = Extend(true, $defaults, $options);
5153

52-
onActionClick: function (element) {
53-
element.style.opacity = 0;
54-
}
55-
};
56-
57-
Snackbar.show = function ($options) {
58-
var options = Extend(true, $defaults, $options);
59-
60-
if (Snackbar.current) {
61-
Snackbar.current.style.opacity = 0;
62-
setTimeout(function () {
63-
var $parent = this.parentElement;
64-
if ($parent) // possible null if too many/fast Snackbars
65-
$parent.removeChild(this);
66-
}.bind(Snackbar.current), 500);
67-
}
54+
if (Snackbar.current) {
55+
Snackbar.current.style.opacity = 0;
56+
setTimeout(function () {
57+
var $parent = this.parentElement;
58+
if ($parent) // possible null if too many/fast Snackbars
59+
$parent.removeChild(this);
60+
}.bind(Snackbar.current), 500);
61+
}
6862

69-
Snackbar.snackbar = document.createElement('div');
70-
Snackbar.snackbar.className = 'snackbar-container ' + options.customClass;
71-
Snackbar.snackbar.style.width = options.width;
72-
var $p = document.createElement('p');
73-
$p.style.margin = 0;
74-
$p.style.padding = 0;
75-
$p.style.color = options.textColor;
76-
$p.style.fontSize = '14px';
77-
$p.style.fontWeight = 300;
78-
$p.style.lineHeight = '1em';
79-
$p.innerHTML = options.text;
80-
Snackbar.snackbar.appendChild($p);
81-
Snackbar.snackbar.style.background = options.backgroundColor;
82-
if (options.showAction) {
83-
var actionButton = document.createElement('button');
84-
actionButton.className = 'action';
85-
actionButton.innerHTML = options.actionText;
86-
actionButton.style.color = options.actionTextColor;
87-
actionButton.addEventListener('click', function () {
88-
options.onActionClick(Snackbar.snackbar);
89-
});
90-
Snackbar.snackbar.appendChild(actionButton);
91-
}
63+
Snackbar.snackbar = document.createElement('div');
64+
Snackbar.snackbar.className = 'snackbar-container ' + options.customClass;
65+
Snackbar.snackbar.style.width = options.width;
66+
var $p = document.createElement('p');
67+
$p.style.margin = 0;
68+
$p.style.padding = 0;
69+
$p.style.color = options.textColor;
70+
$p.style.fontSize = '14px';
71+
$p.style.fontWeight = 300;
72+
$p.style.lineHeight = '1em';
73+
$p.innerHTML = options.text;
74+
Snackbar.snackbar.appendChild($p);
75+
Snackbar.snackbar.style.background = options.backgroundColor;
76+
if (options.showAction) {
77+
var actionButton = document.createElement('button');
78+
actionButton.className = 'action';
79+
actionButton.innerHTML = options.actionText;
80+
actionButton.style.color = options.actionTextColor;
81+
actionButton.addEventListener('click', function () {
82+
options.onActionClick(Snackbar.snackbar);
83+
});
84+
Snackbar.snackbar.appendChild(actionButton);
85+
}
9286

93-
setTimeout(function () {
94-
if (Snackbar.current === this) {
95-
Snackbar.current.style.opacity = 0;
96-
}
87+
setTimeout(function () {
88+
if (Snackbar.current === this) {
89+
Snackbar.current.style.opacity = 0;
90+
}
91+
92+
}.bind(Snackbar.snackbar), options.duration);
93+
94+
Snackbar.snackbar.addEventListener('transitionend', function (event, elapsed) {
95+
if (event.propertyName === 'opacity' && this.style.opacity === 0) {
96+
this.parentElement.removeChild(this);
97+
if (Snackbar.current === this) {
98+
Snackbar.current = null;
99+
}
100+
}
101+
}.bind(Snackbar.snackbar));
102+
103+
Snackbar.current = Snackbar.snackbar;
104+
105+
if (options.pos === 'top-left' || options.pos === 'top-center' || options.pos === 'top' || options.pos === 'top-right')
106+
Snackbar.snackbar.style.top = '-100px';
107+
108+
document.body.appendChild(Snackbar.snackbar);
109+
var $bottom = getComputedStyle(Snackbar.snackbar).bottom;
110+
var $top = getComputedStyle(Snackbar.snackbar).top;
111+
Snackbar.snackbar.style.opacity = 1;
112+
Snackbar.snackbar.className = 'snackbar-container ' + options.customClass + ' snackbar-pos ' + options.pos;
113+
if (options.pos === 'top-left' || options.pos === 'top-right')
114+
Snackbar.snackbar.style.top = 0;
115+
else if (options.pos === 'top-center' || options.pos === 'top')
116+
Snackbar.snackbar.style.top = '25px';
117+
else if (options.pos === 'bottom-center' || options.pos === 'bottom')
118+
Snackbar.snackbar.style.bottom = '-25px';
119+
};
97120

98-
}.bind(Snackbar.snackbar), $options.duration);
121+
Snackbar.close = function () {
122+
if (Snackbar.current)
123+
Snackbar.current.style.opacity = 0;
124+
};
99125

100-
Snackbar.snackbar.addEventListener('transitionend', function (event, elapsed) {
101-
if (event.propertyName === 'opacity' && this.style.opacity === 0) {
102-
this.parentElement.removeChild(this);
103-
if (Snackbar.current === this) {
104-
Snackbar.current = null;
105-
}
106-
}
107-
}.bind(Snackbar.snackbar));
108-
109-
Snackbar.current = Snackbar.snackbar;
110-
document.body.style.overflow = 'hidden';
111-
112-
if (options.pos === 'top-left' || options.pos === 'top-center' || options.pos === 'top' || options.pos === 'top-right')
113-
Snackbar.snackbar.style.top = '-100px';
114-
115-
document.body.appendChild(Snackbar.snackbar);
116-
var $bottom = getComputedStyle(Snackbar.snackbar).bottom;
117-
var $top = getComputedStyle(Snackbar.snackbar).top;
118-
Snackbar.snackbar.style.opacity = 1;
119-
Snackbar.snackbar.className = 'snackbar-container ' + options.customClass + ' snackbar-pos ' + options.pos;
120-
if (options.pos === 'top-left' || options.pos === 'top-right')
121-
Snackbar.snackbar.style.top = 0;
122-
else if (options.pos === 'top-center' || options.pos === 'top')
123-
Snackbar.snackbar.style.top = '25px';
124-
else if (options.pos === 'bottom-center' || options.pos === 'bottom')
125-
Snackbar.snackbar.style.bottom = '-25px';
126-
127-
setTimeout(function () {
128-
document.body.style.overflow = 'auto';
129-
}, 500);
130-
};
131-
132-
Snackbar.close = function () {
133-
if (Snackbar.current)
134-
Snackbar.current.style.opacity = 0;
135-
};
136-
137-
// Pure JS Extend
138-
// http://gomakethings.com/vanilla-javascript-version-of-jquery-extend/
139-
var Extend = function () {
140-
141-
var extended = {};
142-
var deep = false;
143-
var i = 0;
144-
var length = arguments.length;
145-
146-
if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
147-
deep = arguments[0];
148-
i++;
149-
}
126+
// Pure JS Extend
127+
// http://gomakethings.com/vanilla-javascript-version-of-jquery-extend/
128+
var Extend = function () {
129+
130+
var extended = {};
131+
var deep = false;
132+
var i = 0;
133+
var length = arguments.length;
150134

151-
var merge = function (obj) {
152-
for (var prop in obj) {
153-
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
154-
if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
155-
extended[prop] = extend(true, extended[prop], obj[prop]);
156-
} else {
157-
extended[prop] = obj[prop];
158-
}
135+
if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
136+
deep = arguments[0];
137+
i++;
159138
}
160-
}
161-
};
162139

163-
for (; i < length; i++) {
164-
var obj = arguments[i];
165-
merge(obj);
166-
}
140+
var merge = function (obj) {
141+
for (var prop in obj) {
142+
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
143+
if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
144+
extended[prop] = extend(true, extended[prop], obj[prop]);
145+
} else {
146+
extended[prop] = obj[prop];
147+
}
148+
}
149+
}
150+
};
151+
152+
for (; i < length; i++) {
153+
var obj = arguments[i];
154+
merge(obj);
155+
}
167156

168-
return extended;
157+
return extended;
169158

170-
};
159+
};
171160

172-
return Snackbar;
173-
})();
161+
return Snackbar;
162+
}));

dist/snackbar.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)