Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from mateu-aguilo-bosch/alert-timeouts
Browse files Browse the repository at this point in the history
Feature request - alert timeouts
  • Loading branch information
e0ipso committed Jul 22, 2014
2 parents 276f553 + c79b6b9 commit 7cb0bd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ If you need to add HTML to a message you can do so by passing in the `html` opti
messageCenterService.add('success', '<strong>HTML</strong> <em>is</em> <span>allowed</span>.', { html: true });
```

### Timer
You can add a timer to the alert so it auto dismisses. To do so, just add a timeout option in miliseconds.

```js
messageCenterService.add('success', 'Bye bye in 3s!', { timeout: 3000 });
```

## Directive
The directive `mcMessages` will allow you to place the messages wherever you want in your layout. Just drop `<mc-messages></mc-messages>` or `<div mc-messages></div>` somewhere in your partials and if there are any messages to be shown they will be shown there. Since it's a regular directive you can perform the common alterations and modifications to it to suit your needs.
Expand Down
9 changes: 7 additions & 2 deletions message-center.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var MessageCenterModule = angular.module('MessageCenterModule', []);

// Define a service to inject.
MessageCenterModule.
service('messageCenterService', ['$sce',
function ($sce) {
service('messageCenterService', ['$sce', '$timeout',
function ($sce, $timeout) {
return {
mcMessages: this.mcMessages || [],
status: {
Expand Down Expand Up @@ -38,6 +38,11 @@ MessageCenterModule.
};
messageObject.message = options.html ? $sce.trustAsHtml(message) : message;
messageObject.html = !!options.html;
if (angular.isDefined(options.timeout)) {
messageObject.timer = $timeout(function () {
messageObject.close();
}, options.timeout);
}
this.mcMessages.push(messageObject);
},
remove: function (message) {
Expand Down

0 comments on commit 7cb0bd2

Please sign in to comment.