Skip to content

Commit d1d0f72

Browse files
committed
Toast can be sticked
1 parent 994b76c commit d1d0f72

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
gen/
22
dist/
3-
node_modules/
3+
node_modules/
4+
playground/

src/toastr.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ angular.module('toastr', [])
1515
scope.messageClass = scope.options.messageClass;
1616

1717
scope.init = function() {
18-
timeout = createTimeout(scope.options.timeOut);
18+
if (scope.options.timeOut) {
19+
timeout = createTimeout(scope.options.timeOut);
20+
}
1921
};
2022

2123
element.on('mouseenter', function() {
@@ -29,6 +31,7 @@ angular.module('toastr', [])
2931
};
3032

3133
element.on('mouseleave', function() {
34+
if (scope.options.timeOut === 0 && scope.options.extendedTimeOut === 0) { return; }
3235
timeout = createTimeout(scope.options.extendedTimeOut);
3336
});
3437

test/toastr_spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,39 @@ describe('toastr', function() {
273273
var toast = openToast('error', 'message', 'title', options);
274274
expect(toast).toHaveClass(options.toastClass);
275275
});
276+
277+
it('can make a toast stick until is clicked or hovered (extended timeout)', function() {
278+
var options = {
279+
timeOut: 0
280+
};
281+
openToast('info', 'I don\'t want to go...', null, options);
282+
checkForEmptyTimeoutQueue();
283+
expect($document).toHaveToastOpen(1);
284+
clickToast();
285+
expect($document).toHaveToastOpen(0);
286+
287+
openToast('info', 'I don\'t want to go...', null, options);
288+
checkForEmptyTimeoutQueue();
289+
expect($document).toHaveToastOpen(1);
290+
hoverToast();
291+
leaveToast();
292+
timeoutFlush();
293+
expect($document).toHaveToastOpen(0);
294+
});
295+
296+
it('can make a toast stick until is clicked', function() {
297+
var options = {
298+
timeOut: 0,
299+
extendedTimeOut: 0
300+
};
301+
openToast('info', 'I don\'t want to go...', null, options);
302+
checkForEmptyTimeoutQueue();
303+
expect($document).toHaveToastOpen(1);
304+
hoverToast();
305+
leaveToast();
306+
expect($document).toHaveToastOpen(1);
307+
clickToast();
308+
expect($document).toHaveToastOpen(0);
309+
});
276310
});
277311
});

0 commit comments

Comments
 (0)