├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── messages.js
├── messages_list.html
├── messages_list.js
├── messages_tests.js
├── package.js
└── versions.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .build*
2 | flash-messages
3 | smart.lock
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "0.10"
4 | before_install:
5 | - "curl -L http://git.io/ejPSng | /bin/sh"
6 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Juan Camilo Mejia
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | flash-messages [](https://travis-ci.org/camilosw/flash-messages)
2 | ==============
3 |
4 |
5 | Package for displaying flash messages to the user. This is based on the chapter 'Creating a Meteorite Package' from the [Discover Meteor Book](http://www.discovermeteor.com/) and the [foundation-flash-messages](https://github.com/datariot/foundation-flash-messages) package.
6 |
7 | This package integrates well with [Bootstrap Alerts](http://getbootstrap.com/components/#alerts) styles, but Bootstrap is not a dependency.
8 |
9 | You can see a [demo](http://flash-messages-demo.meteor.com/) and their [source code](https://github.com/camilosw/flash-messages-demo).
10 |
11 | ## Note
12 |
13 | The syntax has changed on version 0.2.0
14 |
15 | ## Usage
16 |
17 | Include the template somewhere in your index.html file:
18 | ```javascript
19 | {{> flashMessages}}
20 | ```
21 | And then send messages:
22 | ```javascript
23 | FlashMessages.sendWarning("Message");
24 | FlashMessages.sendError("Message");
25 | FlashMessages.sendSuccess("Message");
26 | FlashMessages.sendInfo("Message");
27 | ```
28 |
29 | **Note:** sendAlert was deprecated, use sendWarning instead.
30 |
31 | You can also send a group of messages sending an array of strings. This will be rendered on a `ul` `li` list:
32 | ```javascript
33 | FlashMessages.sendInfo(["Message 1", "Message 2", "Message 3"]);
34 | ```
35 |
36 | Messages can also contain html:
37 | ```javascript
38 | FlashMessages.sendInfo("You can found Meteorhere");
39 | ```
40 |
41 | To clear messages:
42 | ```javascript
43 | FlashMessages.clear();
44 | ```
45 |
46 | Only the seen messages will be cleared.
47 |
48 | ## Configure
49 |
50 | You can configure globally the way the messages behave with FlashMessages.configure (the below sample shows the default values):
51 | ```javascript
52 | FlashMessages.configure({
53 | autoHide: true,
54 | hideDelay: 5000,
55 | autoScroll: true
56 | });
57 | ```
58 |
59 | - `autoHide`: set to `true` to make flash message fade after `hideDelay` milliseconds, set to `false` to require the user to click the close button on the message to dismiss it.
60 | - `hideDelay`: set the desired number of milliseconds for the flash message to be displayed (when `autoHide` is `true`).
61 | - `autoScroll`: set to `true` to enable auto scroll when a message is displayed, `false` to disable auto scroll. (**Note:** this can be set only globally.)
62 |
63 | You can also set individual options on messages. This will override global configuration:
64 | ```javascript
65 | FlashMessages.sendWarning("Message", { autoHide: false });
66 | FlashMessages.sendError("Message", { hideDelay: 2000 });
67 | FlashMessages.sendSuccess("Message", { autoHide: true, hideDelay: 8000 });
68 | ```
69 |
--------------------------------------------------------------------------------
/messages.js:
--------------------------------------------------------------------------------
1 | /**
2 | * flashMessages
3 | * { message: String,
4 | * style: String,
5 | * seen: Boolean }
6 | */
7 | flashMessages = new Mongo.Collection(null);
8 |
9 | FlashMessages = {
10 | // Deprecated, use sendWarning instead. sendWarning is more consistent with Boostrap classes.
11 | sendAlert: function(message, options) {
12 | sendMessage(message, '', options);
13 | console.log('Deprecated, use sendWarning instead of sendAlert');
14 | },
15 | sendWarning: function(message, options) {
16 | sendMessage(message, 'alert-warning', options);
17 | },
18 | sendError: function(message, options) {
19 | sendMessage(message, 'alert-error alert-danger', options);
20 | },
21 | sendSuccess: function(message, options) {
22 | sendMessage(message, 'alert-success', options);
23 | },
24 | sendInfo: function(message, options) {
25 | sendMessage(message, 'alert-info', options);
26 | },
27 | clear: function() {
28 | flashMessages.remove({seen: true});
29 | },
30 | configure: function(options) {
31 | this.options = this.options || {};
32 | _.extend(this.options, options);
33 | },
34 | options: {
35 | autoHide: true,
36 | hideDelay: 5000,
37 | autoScroll: true
38 | }
39 | }
40 |
41 | sendMessage = function(message, style, options) {
42 | options = options || {};
43 | options.autoHide = options.autoHide === undefined ? FlashMessages.options.autoHide : options.autoHide;
44 | options.hideDelay = options.hideDelay || FlashMessages.options.hideDelay;
45 | flashMessages.insert({ message: message, style: style, seen: false, options: options});
46 | }
--------------------------------------------------------------------------------
/messages_list.html:
--------------------------------------------------------------------------------
1 |
2 | {{#each messages}}
3 | {{> flashMessageItem}}
4 | {{/each}}
5 |
6 |
7 |
8 |