3 * https://github.com/Schlogen/angular-confirm
4 * @version v1.2.3 - 2016-01-26
7 (function (root, factory) {
9 if (typeof define === 'function' && define.amd) {
10 define(['angular'], factory);
11 } else if (typeof module !== 'undefined' && typeof module.exports === 'object') {
12 module.exports = factory(require('angular'));
14 return factory(root.angular);
16 }(this, function (angular) {
17 angular.module('angular-confirm', ['ui.bootstrap.modal'])
18 .controller('ConfirmModalController', function ($scope, $uibModalInstance, data) {
19 $scope.data = angular.copy(data);
21 $scope.ok = function (closeMessage) {
22 $uibModalInstance.close(closeMessage);
25 $scope.cancel = function (dismissMessage) {
26 if (angular.isUndefined(dismissMessage)) {
27 dismissMessage = 'cancel';
29 $uibModalInstance.dismiss(dismissMessage);
33 .value('$confirmModalDefaults', {
34 template: '<div class="modal-header"><h3 class="modal-title">{{data.title}}</h3></div>' +
35 '<div class="modal-body">{{data.text}}</div>' +
36 '<div class="modal-footer">' +
37 '<button class="btn btn-primary" ng-click="ok()">{{data.ok}}</button>' +
38 '<button class="btn btn-default" ng-click="cancel()">{{data.cancel}}</button>' +
40 controller: 'ConfirmModalController',
47 .factory('$confirm', function ($uibModal, $confirmModalDefaults) {
48 return function (data, settings) {
49 var defaults = angular.copy($confirmModalDefaults);
50 settings = angular.extend(defaults, (settings || {}));
52 data = angular.extend({}, settings.defaultLabels, data || {});
54 if ('templateUrl' in settings && 'template' in settings) {
55 delete settings.template;
64 return $uibModal.open(settings).result;
67 .directive('confirm', function ($confirm) {
80 link: function (scope, element, attrs) {
82 element.unbind("click").bind("click", function ($event) {
84 $event.preventDefault();
86 if (angular.isUndefined(scope.confirmIf) || scope.confirmIf) {
88 var data = {text: scope.confirm};
89 if (scope.confirmTitle) {
90 data.title = scope.confirmTitle;
92 if (scope.confirmOk) {
93 data.ok = scope.confirmOk;
95 if (scope.confirmCancel) {
96 data.cancel = scope.confirmCancel;
98 $confirm(data, scope.confirmSettings || {}).then(scope.ngClick);
101 scope.$apply(scope.ngClick);