|
1 | 1 | /** |
2 | 2 | * angular-ui-notification - Angular.js service providing simple notifications using Bootstrap 3 styles with css transitions for animating |
3 | 3 | * @author Alex_Crack |
4 | | - * @version v0.2.0 |
| 4 | + * @version v0.3.5 |
5 | 5 | * @link https://github.com/alexcrack/angular-ui-notification |
6 | 6 | * @license MIT |
7 | 7 | */ |
@@ -46,23 +46,38 @@ angular.module('ui-notification').provider('Notification', function() { |
46 | 46 | var notify = function(args, t){ |
47 | 47 | var deferred = $q.defer(); |
48 | 48 |
|
49 | | - if (typeof args !== 'object') { |
| 49 | + if (typeof args !== 'object' || args === null) { |
50 | 50 | args = {message:args}; |
51 | 51 | } |
52 | 52 |
|
53 | 53 | args.scope = args.scope ? args.scope : $rootScope; |
54 | 54 | args.template = args.templateUrl ? args.templateUrl : options.templateUrl; |
55 | 55 | args.delay = !angular.isUndefined(args.delay) ? args.delay : delay; |
56 | | - args.type = t || options.type || ''; |
| 56 | + args.type = t || args.type || options.type || ''; |
57 | 57 | args.positionY = args.positionY ? args.positionY : options.positionY; |
58 | 58 | args.positionX = args.positionX ? args.positionX : options.positionX; |
59 | 59 | args.replaceMessage = args.replaceMessage ? args.replaceMessage : options.replaceMessage; |
60 | 60 | args.onClose = args.onClose ? args.onClose : options.onClose; |
61 | 61 | args.closeOnClick = (args.closeOnClick !== null && args.closeOnClick !== undefined) ? args.closeOnClick : options.closeOnClick; |
62 | 62 | args.container = args.container ? args.container : options.container; |
63 | 63 | args.priority = args.priority ? args.priority : options.priority; |
64 | | - |
65 | | - $http.get(args.template,{cache: $templateCache}).success(function(template) { |
| 64 | + |
| 65 | + var template=$templateCache.get(args.template); |
| 66 | + |
| 67 | + if(template){ |
| 68 | + processNotificationTemplate(template); |
| 69 | + }else{ |
| 70 | + // load it via $http only if it isn't default template and template isn't exist in template cache |
| 71 | + // cache:true means cache it for later access. |
| 72 | + $http.get(args.template,{cache: true}) |
| 73 | + .then(processNotificationTemplate) |
| 74 | + .catch(function(data){ |
| 75 | + throw new Error('Template ('+args.template+') could not be loaded. ' + data); |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + function processNotificationTemplate(template) { |
66 | 81 |
|
67 | 82 | var scope = args.scope.$new(); |
68 | 83 | scope.message = $sce.trustAsHtml(args.message); |
@@ -211,9 +226,7 @@ angular.module('ui-notification').provider('Notification', function() { |
211 | 226 |
|
212 | 227 | deferred.resolve(scope); |
213 | 228 |
|
214 | | - }).error(function(data){ |
215 | | - throw new Error('Template ('+args.template+') could not be loaded. ' + data); |
216 | | - }); |
| 229 | + } |
217 | 230 |
|
218 | 231 | return deferred.promise; |
219 | 232 | }; |
|
0 commit comments