@@ -17,56 +17,74 @@ angular.module('angular-confirm', ['ui.bootstrap'])
1717 } ;
1818} ] )
1919. value ( '$confirmModalDefaults' , {
20- template : '<div class="modal-header"><h3 class="modal-title">Confirm</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>' ,
21- controller : 'ConfirmModalController'
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>' ,
26+ controller : 'ConfirmModalController' ,
27+ defaults : {
28+ title :'Confirm' ,
29+ ok : 'OK' ,
30+ cancel : 'Cancel'
31+ }
2232} )
2333. factory ( '$confirm' , [ '$modal' , '$confirmModalDefaults' , function ( $modal , $confirmModalDefaults ) {
2434 return function ( data , settings ) {
2535 settings = angular . extend ( $confirmModalDefaults , ( settings || { } ) ) ;
26- data = data || { } ;
27-
36+ data = angular . extend ( { } , settings . defaults , data || { } ) ;
37+
2838 if ( 'templateUrl' in settings && 'template' in settings ) {
2939 delete settings . template ;
3040 }
31-
41+
3242 settings . resolve = { data : function ( ) { return data ; } } ;
3343
3444 return $modal . open ( settings ) . result ;
3545 } ;
3646} ] )
3747. directive ( 'confirm' , [ '$confirm' , function ( $confirm ) {
38- return {
39- priority : 1 ,
40- restrict : 'A' ,
41- scope : {
42- confirmIf : "=" ,
43- ngClick : '&' ,
44- confirm : '@'
45- } ,
46- link : function ( scope , element , attrs ) {
47- function reBind ( func ) {
48- element . unbind ( "click" ) . bind ( "click" , function ( ) {
49- func ( ) ;
50- } ) ;
51- }
52-
53- function bindConfirm ( ) {
54- $confirm ( { text : scope . confirm } ) . then ( scope . ngClick ) ;
55- }
56-
57- if ( 'confirmIf' in attrs ) {
58- scope . $watch ( 'confirmIf' , function ( newVal ) {
59- if ( newVal ) {
60- reBind ( bindConfirm ) ;
61- } else {
62- reBind ( function ( ) {
63- scope . $apply ( scope . ngClick ) ;
64- } ) ;
65- }
66- } ) ;
67- } else {
68- reBind ( bindConfirm ) ;
69- }
48+ return {
49+ priority : 1 ,
50+ restrict : 'A' ,
51+ scope : {
52+ confirmIf : "=" ,
53+ ngClick : '&' ,
54+ confirm : '@' ,
55+ confirmTitle : '@' ,
56+ confirmOk : '@' ,
57+ confirmCancel : '@'
58+ } ,
59+ link : function ( scope , element , attrs ) {
60+ function reBind ( func ) {
61+ element . unbind ( "click" ) . bind ( "click" , function ( $event ) {
62+ $event . preventDefault ( ) ;
63+ func ( ) ;
64+ } ) ;
65+ }
66+
67+ function bindConfirm ( ) {
68+ var data = { text : scope . confirm } ;
69+ scope . confirmTitle && ( data . title = scope . confirmTitle ) ;
70+ scope . confirmOk && ( data . ok = scope . confirmOk ) ;
71+ scope . confirmCancel && ( data . cancel = scope . confirmCancel ) ;
72+ $confirm ( data ) . then ( scope . ngClick ) ;
73+ }
74+
75+ if ( 'confirmIf' in attrs ) {
76+ scope . $watch ( 'confirmIf' , function ( newVal ) {
77+ if ( newVal ) {
78+ reBind ( bindConfirm ) ;
79+ } else {
80+ reBind ( function ( ) {
81+ scope . $apply ( scope . ngClick ) ;
82+ } ) ;
83+ }
84+ } ) ;
85+ } else {
86+ reBind ( bindConfirm ) ;
7087 }
7188 }
89+ }
7290} ] ) ;
0 commit comments