This repository was archived by the owner on Apr 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +35
-25
lines changed Expand file tree Collapse file tree 1 file changed +35
-25
lines changed Original file line number Diff line number Diff line change @@ -37,31 +37,41 @@ angular.module('angular-confirm', ['ui.bootstrap'])
3737} )
3838. directive ( 'confirm' , function ( $confirm ) {
3939 return {
40- priority : 1 ,
41- restrict : 'A' ,
42- scope : {
43- confirmIf : "=" ,
44- ngClick : '&' ,
45- confirm : '@'
46- } ,
47- link : function ( scope , element , attrs ) {
48-
49-
50- scope . $watch ( 'confirmIf' , function ( newVal ) {
51- if ( newVal ) {
52- element . unbind ( "click" ) . bind ( "click" , function ( ) {
53- $confirm ( { text : scope . confirm } , scope . ngClick ) ;
54- } ) ;
55- } else {
56- element . unbind ( "click" ) . bind ( "click" , function ( ) {
57- if ( scope . $$phase || scope . $root . $$phase ) {
58- scope . ngClick ( ) ;
59- } else {
60- scope . $apply ( scope . ngClick ) ;
61- }
62- } ) ;
63- }
64- } ) ;
40+ priority : 1 ,
41+ restrict : 'A' ,
42+ scope : {
43+ confirmIf : "=" ,
44+ ngClick : '&' ,
45+ confirm : '@'
46+ } ,
47+ link : function ( scope , element , attrs ) {
48+ function reBind ( func ) {
49+ element . unbind ( "click" ) . bind ( "click" , function ( ) {
50+ func ( ) ;
51+ } ) ;
52+ }
53+
54+ function bindConfirm ( ) {
55+ $confirm ( { text : scope . confirm } , scope . ngClick ) ;
56+ }
57+
58+ if ( 'confirmIf' in attrs ) {
59+ scope . $watch ( 'confirmIf' , function ( newVal ) {
60+ if ( newVal ) {
61+ reBind ( bindConfirm ) ;
62+ } else {
63+ reBind ( function ( ) {
64+ if ( scope . $$phase || scope . $root . $$phase ) {
65+ scope . ngClick ( ) ;
66+ } else {
67+ scope . $apply ( scope . ngClick ) ;
68+ }
69+ } ) ;
70+ }
71+ } ) ;
72+ } else {
73+ reBind ( bindConfirm ) ;
6574 }
75+ }
6676 }
6777} ) ;
You can’t perform that action at this time.
0 commit comments