22 angular . module ( 'toastr' , [ ] )
33 . factory ( 'toastr' , toastr ) ;
44
5- toastr . $inject = [ '$animate' , '$compile ' , '$document' , '$rootScope' , '$sce' , 'toastrConfig' , '$q' ] ;
5+ toastr . $inject = [ '$animate' , '$injector ' , '$document' , '$rootScope' , '$sce' , 'toastrConfig' , '$q' ] ;
66
7- function toastr ( $animate , $compile , $document , $rootScope , $sce , toastrConfig , $q ) {
7+ function toastr ( $animate , $injector , $document , $rootScope , $sce , toastrConfig , $q ) {
88 var container , index = 0 , toasts = [ ] ;
99 var containerDefer = $q . defer ( ) ;
1010
115115 container . addClass ( options . positionClass ) ;
116116 container . css ( { 'pointer-events' : 'auto' } ) ;
117117
118- var body = $ document. find ( 'body' ) . eq ( 0 ) ;
118+ var target = document . querySelector ( options . target ) ;
119119
120- $animate . enter ( container , body ) . then ( function ( ) {
120+ if ( ! target ) {
121+ throw 'Target for toasts doesn\'t exist' ;
122+ }
123+
124+ $animate . enter ( container , target ) . then ( function ( ) {
121125 containerDefer . resolve ( ) ;
122126 } ) ;
123127
200204 }
201205
202206 function createToastEl ( scope ) {
203- var angularDomEl = angular . element ( '<div toast></div>' ) ;
207+ var angularDomEl = angular . element ( '<div toast></div>' ) ,
208+ $compile = $injector . get ( '$compile' ) ;
204209 return $compile ( angularDomEl ) ( scope ) ;
205210 }
206211
210215 }
211216 }
212217} ( ) ) ;
218+
213219( function ( ) {
214220 angular . module ( 'toastr' )
215221 . constant ( 'toastrConfig' , {
233239 tapToDismiss : true ,
234240 timeOut : 5000 ,
235241 titleClass : 'toast-title' ,
236- toastClass : 'toast'
242+ toastClass : 'toast' ,
243+ target : 'body'
237244 } ) ;
238245} ( ) ) ;
246+
239247( function ( ) {
240248 angular . module ( 'toastr' )
241249 . directive ( 'toast' , toast ) ;
242250
243- toast . $inject = [ '$compile ' , '$interval' , 'toastr' ] ;
251+ toast . $inject = [ '$injector ' , '$interval' , 'toastr' ] ;
244252
245- function toast ( $compile , $interval , toastr ) {
253+ function toast ( $injector , $interval , toastr ) {
246254 return {
247255 replace : true ,
248256 templateUrl : 'templates/toastr/toastr.html' ,
257265 scope . messageClass = scope . options . messageClass ;
258266
259267 if ( wantsCloseButton ( ) ) {
260- var button = angular . element ( scope . options . closeHtml ) ;
268+ var button = angular . element ( scope . options . closeHtml ) ,
269+ $compile = $injector . get ( '$compile' ) ;
261270 button . addClass ( 'toast-close-button' ) ;
262271 button . attr ( 'ng-click' , 'close()' ) ;
263272 $compile ( button ) ( scope ) ;
306315 }
307316 }
308317} ( ) ) ;
318+
309319angular . module ( "toastr" ) . run ( [ "$templateCache" , function ( $templateCache ) { $templateCache . put ( "templates/toastr/toastr.html" , "<div class=\"{{toastClass}} {{toastType}}\" ng-click=\"tapToast()\">\n <div ng-switch on=\"allowHtml\">\n <div ng-switch-default ng-if=\"title\" class=\"{{titleClass}}\">{{title}}</div>\n <div ng-switch-default class=\"{{messageClass}}\">{{message}}</div>\n <div ng-switch-when=\"true\" ng-if=\"title\" class=\"{{titleClass}}\" ng-bind-html=\"title\"></div>\n <div ng-switch-when=\"true\" class=\"{{messageClass}}\" ng-bind-html=\"message\"></div>\n </div>\n</div>" ) ; } ] ) ;
0 commit comments