-
-
Save kwmiebach/16bdaa04611e1a3bbf478be07cde607f to your computer and use it in GitHub Desktop.
ng-confirm - An AngularJS directive that creates a confirmation dialog for an action. Forked from https://gist.github.com/asafge/7430497 and https://gist.github.com/brunovianarezende/8437155
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app') | |
.directive('ngReallyClick', [ function() { | |
/** | |
* A generic confirmation for risky actions. | |
* https://gist.github.com/kwmiebach/16bdaa04611e1a3bbf478be07cde607f | |
* Originally https://gist.github.com/asafge/7430497 | |
* replaces: confirm - ng-confirm | |
* Usage: Add attributes: | |
* * ng-really-click="takeAction()" function | |
* * ng-really-message="Are you sure?" | |
* There is also another fork with bootstrap added: | |
* https://gist.github.com/mwagena/dd30c7803a65f6ae23ec | |
*/ | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
element.bind('click', function() { | |
var message = attrs.ngReallyMessage; | |
if (message && confirm(message)) { | |
scope.$apply(attrs.ngReallyClick); | |
} | |
}); | |
} | |
}; | |
}]) | |
.directive('ngReallyClickIf', [function() { | |
/** | |
* Alternative version thanks to https://gist.github.com/brunovianarezende/8437155 | |
* Adds a condition. Confirmation dialog is suppressed | |
* and action taken anyway if condition does not evaluate true. | |
* Usage: Add attributes: | |
* * ng-really-click-if="takeAction()" function | |
* * ng-really-message="Are you sure?" | |
* * ng-really-cond="mustBeEvaluatedToTrueForTheConfirmBoxBeShown" expression | |
*/ | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
element.bind('click', function() { | |
var condition = scope.$eval(attrs.ngReallyCond); | |
if(condition){ | |
var message = attrs.ngReallyMessage; | |
if (message && confirm(message)) { | |
scope.$apply(attrs.ngReallyClickIf); | |
} | |
} | |
else{ | |
scope.$apply(attrs.ngReallyClickIf); | |
} | |
}); | |
} | |
}; | |
}]) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment