Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

shortcuts to warning, info, danger and success #45

Merged
merged 4 commits into from
May 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,30 @@ ngToast is a simple Angular provider for toast notifications.
5. Inject ngToast provider in your controller:
```javascript
app.controller('myCtrl', function(ngToast) {

ngToast.create('a toast message...');

// create a toast with settings (settings doc: http://tamerayd.in/ngToast/#api)

var aToast = ngToast.create({
className: 'warning',
content: 'Another message as <a href="#" class="">HTML</a>'
});

// to clear a toast:
ngToast.dismiss(aToast);

// clear all toasts:
ngToast.dismiss();

// Create toasts styled with bootstrap alerts (see http://getbootstrap.com/components/#alerts)
ngToast.success('a toast message...');
ngToast.info('a toast message...');
ngToast.warning('a toast message...');
ngToast.danger('a toast message...');

//styled toasts also accept settings (settings doc: http://tameraydin.github.io/ngToast/#api)
ngToast.info({content: 'a toast message...', timeout: 10000});
});
```

Expand Down
17 changes: 17 additions & 0 deletions dist/ngToast.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@
}
messageStack.push(newMsg.id);
return newMsg.id;
},
createWithClassName: function(className, msg) {
msg = (typeof msg === 'string') ? {content: msg} : msg;
msg.className= className;
return this.create(msg);
},
success: function(msg) {
return this.createWithClassName('success',msg);
},
info: function(msg) {
return this.createWithClassName('info',msg);
},
warning: function(msg) {
return this.createWithClassName('warning',msg);
},
danger: function(msg) {
return this.createWithClassName('danger',msg);
}
};
}];
Expand Down
2 changes: 1 addition & 1 deletion dist/ngToast.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/scripts/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@
}
messageStack.push(newMsg.id);
return newMsg.id;
},
createWithClassName: function(className, msg) {
msg = (typeof msg === 'string') ? {content: msg} : msg;
msg.className= className;
return this.create(msg);
},
success: function(msg) {
return this.createWithClassName('success',msg);
},
info: function(msg) {
return this.createWithClassName('info',msg);
},
warning: function(msg) {
return this.createWithClassName('warning',msg);
},
danger: function(msg) {
return this.createWithClassName('danger',msg);
}
};
}];
Expand Down
44 changes: 43 additions & 1 deletion test/spec/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,49 @@ describe('ngToast:', function() {
expect(ngToast.messages.length).toBe(2);
expect(ngToast.messages[1].content).toBe('toast2');
});


it('createWithClassName and a string should work', function () {
ngToast.createWithClassName('info', 'toast1');
expect(ngToast.messages.length).toBe(1);
expect(ngToast.messages[0].content).toBe('toast1');
expect(ngToast.messages[0].className).toBe('info');
});

it('createWithClassName and an object should work', function () {
ngToast.createWithClassName('info', {content:'toast1'});
expect(ngToast.messages.length).toBe(1);
expect(ngToast.messages[0].content).toBe('toast1');
expect(ngToast.messages[0].className).toBe('info');
});

it('success should work', function () {
ngToast.success('toast1');
expect(ngToast.messages.length).toBe(1);
expect(ngToast.messages[0].content).toBe('toast1');
expect(ngToast.messages[0].className).toBe('success');
});

it('info should work', function () {
ngToast.info('toast1');
expect(ngToast.messages.length).toBe(1);
expect(ngToast.messages[0].content).toBe('toast1');
expect(ngToast.messages[0].className).toBe('info');
});

it('warning should work', function () {
ngToast.warning('toast1');
expect(ngToast.messages.length).toBe(1);
expect(ngToast.messages[0].content).toBe('toast1');
expect(ngToast.messages[0].className).toBe('warning');
});

it('danger should work', function () {
ngToast.danger('toast1');
expect(ngToast.messages.length).toBe(1);
expect(ngToast.messages[0].content).toBe('toast1');
expect(ngToast.messages[0].className).toBe('danger');
});

it('create should work in reverse order when vertical position is set as bottom', function () {
ngToast.create('toast1');

Expand Down