Last active
August 29, 2015 14:17
-
-
Save pinalbhatt/6c5bfa72273a4f64fc6c to your computer and use it in GitHub Desktop.
AngularJS Toastr App [PBDesk.Toastr]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Depends on Toastr JS Library | |
https://github.com/CodeSeven/toastr | |
<link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" rel="stylesheet"> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script> | |
*/ | |
(function () { | |
'use strict'; | |
angular.module('PBDesk.Toastr', []) | |
.constant('Toastr', window.toastr) | |
.factory('ToastrFactory', ToastrFactory); | |
ToastrFactory.$inject = ['Toastr']; | |
function ToastrFactory(Toastr) { | |
var service = { | |
toastr: Toastr, | |
setOptions: setOptions, | |
popSuccess: popSuccess, | |
popError: popError, | |
popWarning: popWarning, | |
popInfo: popInfo | |
}; | |
return service; | |
function setOptions(toastrOptions) { | |
if (toastrOptions !== 'undefined') { | |
Toastr.options = toastrOptions; | |
} | |
else { | |
Toastr.options = { | |
"closeButton": true, | |
"debug": false, | |
"newestOnTop": true, | |
"progressBar": true, | |
"positionClass": "toast-bottom-right", | |
"preventDuplicates": false, | |
"onclick": null, | |
"showDuration": "300", | |
"hideDuration": "1000", | |
"timeOut": "5000", | |
"extendedTimeOut": "1000", | |
"showEasing": "swing", | |
"hideEasing": "linear", | |
"showMethod": "fadeIn", | |
"hideMethod": "fadeOut" | |
}; | |
} | |
} | |
function popSuccess(msg, title, options) { | |
pop('success', msg, title, options); | |
} | |
function popError(msg, title, options) { | |
pop('error', msg, title, options); | |
} | |
function popWarning(msg, title, options) { | |
pop('warning', msg, title, options); | |
} | |
function popInfo(msg, title, options) { | |
pop('info', msg, title, options); | |
} | |
function pop(popType, msg, title, options) { | |
setOptions(options); | |
Toastr[popType](msg, title); | |
} | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular | |
.module('PBDesk.Toastr') | |
.controller('ToastrTestController', ToastrTestController); | |
ToastrTestController.$inject = ['$scope', 'Toastr', 'ToastrFactory']; | |
function ToastrTestController($scope, Toastr, ToastrFactory) { | |
$scope.title = 'Toastr Test'; | |
$scope.pop = function () { | |
Toastr.info('msg', 'ttl'); | |
ToastrFactory.toastr.warning('warning'); | |
ToastrFactory.popSuccess('smag', 'stitle'); | |
ToastrFactory.popError('smag', 'stitle'); | |
ToastrFactory.popWarning('smag', 'stitle'); | |
ToastrFactory.popInfo('smag', 'stitle'); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment