|
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 | */ |
@@ -52,15 +52,30 @@ angular.module('ui-notification').provider('Notification', function() { |
52 | 52 | args.scope = args.scope ? args.scope : $rootScope; |
53 | 53 | args.template = args.templateUrl ? args.templateUrl : options.templateUrl; |
54 | 54 | args.delay = !angular.isUndefined(args.delay) ? args.delay : delay; |
55 | | - args.type = t || options.type || ''; |
| 55 | + args.type = t || args.type || options.type || ''; |
56 | 56 | args.positionY = args.positionY ? args.positionY : options.positionY; |
57 | 57 | args.positionX = args.positionX ? args.positionX : options.positionX; |
58 | 58 | args.replaceMessage = args.replaceMessage ? args.replaceMessage : options.replaceMessage; |
59 | 59 | args.onClose = args.onClose ? args.onClose : options.onClose; |
60 | 60 | args.closeOnClick = (args.closeOnClick !== null && args.closeOnClick !== undefined) ? args.closeOnClick : options.closeOnClick; |
61 | 61 | args.container = args.container ? args.container : options.container; |
62 | | - |
63 | | - $http.get(args.template,{cache: $templateCache}).success(function(template) { |
| 62 | + |
| 63 | + var template=$templateCache.get(args.template); |
| 64 | + |
| 65 | + if(template){ |
| 66 | + processNotificationTemplate(template); |
| 67 | + }else{ |
| 68 | + // load it via $http only if it isn't default template and template isn't exist in template cache |
| 69 | + // cache:true means cache it for later access. |
| 70 | + $http.get(args.template,{cache: true}) |
| 71 | + .then(processNotificationTemplate) |
| 72 | + .catch(function(data){ |
| 73 | + throw new Error('Template ('+args.template+') could not be loaded. ' + data); |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + |
| 78 | + function processNotificationTemplate(template) { |
64 | 79 |
|
65 | 80 | var scope = args.scope.$new(); |
66 | 81 | scope.message = $sce.trustAsHtml(args.message); |
@@ -193,9 +208,7 @@ angular.module('ui-notification').provider('Notification', function() { |
193 | 208 |
|
194 | 209 | deferred.resolve(scope); |
195 | 210 |
|
196 | | - }).error(function(data){ |
197 | | - throw new Error('Template ('+args.template+') could not be loaded. ' + data); |
198 | | - }); |
| 211 | + } |
199 | 212 |
|
200 | 213 | return deferred.promise; |
201 | 214 | }; |
|
0 commit comments