Skip to content

Instantly share code, notes, and snippets.

@mwagena
Forked from asafge/ng-really.js
Last active November 22, 2017 16:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mwagena/dd30c7803a65f6ae23ec to your computer and use it in GitHub Desktop.
Save mwagena/dd30c7803a65f6ae23ec to your computer and use it in GitHub Desktop.
Updatet script to use Bootstrap Modals
/**
* A generic confirmation for risky actions.
* Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" ng-really-title="Delete this?" function
*/
angular.module('app').directive('ngReallyClick', ["$modal", "$timeout", function($modal, $timeout) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
return element.bind('click', function() {
var message, title;
message = attrs.ngReallyMessage;
title = attrs.ngReallyTitle || 'Are you sure?';
return $modal.open({
template: '<div class="modal-header">' +
'<button type="button" class="close" ng-click="cancel()" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<h4 class="modal-title">' + title + '</h4>' +
'</div>' +
'<div class="modal-body">' + message + '</div>' +
'<div class="modal-footer">' +
'<button class="btn btn-default" ng-click="cancel()">Cancel</button>' +
'<button class="btn btn-primary" ng-click="confirm()">Confirm</button>' +
'</div>',
size: 'sm',
controller: ["$scope", "$modalInstance", function($scope, $modalInstance) {
$scope.cancel = function() {
return $modalInstance.dismiss('cancel');
};
return $scope.confirm = function() {
return $timeout(function() {
scope.$apply(attrs.ngReallyClick);
return $modalInstance.dismiss();
}, 0);
};
}]
});
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment