@@ -17,60 +17,81 @@ angular.module('angular-confirm', ['ui.bootstrap'])
1717 } ;
1818} ] )
1919. value ( '$confirmModalDefaults' , {
20- template : '<div class="modal-header"><h3 class="modal-title">{{data.title}}</h3></div><div class="modal-body">{{data.text}}</div><div class="modal-footer"><button class="btn btn-primary" ng-click="ok()">OK</button><button class="btn btn-warning" ng-click="cancel()">Cancel</button></div>' ,
20+ template : '<div class="modal-header"><h3 class="modal-title">{{data.title}}</h3></div>' +
21+ '<div class="modal-body">{{data.text}}</div>' +
22+ '<div class="modal-footer">' +
23+ '<button class="btn btn-primary" ng-click="ok()">{{data.ok}}</button>' +
24+ '<button class="btn btn-default" ng-click="cancel()">{{data.cancel}}</button>' +
25+ '</div>' ,
2126 controller : 'ConfirmModalController' ,
22- defaultTitle : 'Confirm'
27+ defaultLabels : {
28+ title :'Confirm' ,
29+ ok : 'OK' ,
30+ cancel : 'Cancel'
31+ }
2332} )
2433. factory ( '$confirm' , [ '$modal' , '$confirmModalDefaults' , function ( $modal , $confirmModalDefaults ) {
2534 return function ( data , settings ) {
2635 settings = angular . extend ( $confirmModalDefaults , ( settings || { } ) ) ;
27- data = data || { } ;
28-
29- data . title = data . title || settings . defaultTitle ;
30- delete settings . defaultTitle ;
31-
36+
37+ data = angular . extend ( { } , settings . defaultLabels , data || { } ) ;
38+
3239 if ( 'templateUrl' in settings && 'template' in settings ) {
3340 delete settings . template ;
3441 }
35-
42+
3643 settings . resolve = { data : function ( ) { return data ; } } ;
3744
3845 return $modal . open ( settings ) . result ;
3946 } ;
4047} ] )
4148. directive ( 'confirm' , [ '$confirm' , function ( $confirm ) {
42- return {
43- priority : 1 ,
44- restrict : 'A' ,
45- scope : {
46- confirmIf : "=" ,
47- ngClick : '&' ,
48- confirm : '@'
49- } ,
50- link : function ( scope , element , attrs ) {
51- function reBind ( func ) {
52- element . unbind ( "click" ) . bind ( "click" , function ( ) {
53- func ( ) ;
54- } ) ;
55- }
56-
57- function bindConfirm ( ) {
58- $confirm ( { text : scope . confirm } ) . then ( scope . ngClick ) ;
59- }
60-
61- if ( 'confirmIf' in attrs ) {
62- scope . $watch ( 'confirmIf' , function ( newVal ) {
63- if ( newVal ) {
64- reBind ( bindConfirm ) ;
65- } else {
66- reBind ( function ( ) {
67- scope . $apply ( scope . ngClick ) ;
68- } ) ;
69- }
70- } ) ;
71- } else {
72- reBind ( bindConfirm ) ;
73- }
49+ return {
50+ priority : 1 ,
51+ restrict : 'A' ,
52+ scope : {
53+ confirmIf : "=" ,
54+ ngClick : '&' ,
55+ confirm : '@' ,
56+ confirmTitle : '@' ,
57+ confirmOk : '@' ,
58+ confirmCancel : '@'
59+ } ,
60+ link : function ( scope , element , attrs ) {
61+ function reBind ( func ) {
62+ element . unbind ( "click" ) . bind ( "click" , function ( $event ) {
63+ $event . preventDefault ( ) ;
64+ func ( ) ;
65+ } ) ;
66+ }
67+
68+ function bindConfirm ( ) {
69+ var data = { text : scope . confirm } ;
70+ if ( scope . confirmTitle ) {
71+ data . title = scope . confirmTitle ;
72+ }
73+ if ( scope . confirmOk ) {
74+ data . ok = scope . confirmOk ;
75+ }
76+ if ( scope . confirmCancel ) {
77+ data . cancel = scope . confirmCancel ;
78+ }
79+ $confirm ( data ) . then ( scope . ngClick ) ;
80+ }
81+
82+ if ( 'confirmIf' in attrs ) {
83+ scope . $watch ( 'confirmIf' , function ( newVal ) {
84+ if ( newVal ) {
85+ reBind ( bindConfirm ) ;
86+ } else {
87+ reBind ( function ( ) {
88+ scope . $apply ( scope . ngClick ) ;
89+ } ) ;
90+ }
91+ } ) ;
92+ } else {
93+ reBind ( bindConfirm ) ;
7494 }
7595 }
96+ }
7697} ] ) ;
0 commit comments