Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 418c955

Browse files
author
James Kleeh
committed
Merge pull request #12 from Schlogen/almeidap-angular-1.4-fix
Changes merged
2 parents e9788f8 + 6edad75 commit 418c955

File tree

3 files changed

+75
-80
lines changed

3 files changed

+75
-80
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.idea
22
/node_modules
3+
/npm-debug.log

angular-confirm.js

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,94 @@
11
/*
22
* angular-confirm
33
* http://schlogen.github.io/angular-confirm/
4-
* Version: 1.0.4 - 2015-28-04
4+
* Version: 1.1.0 - 2015-14-07
55
* License: Apache
66
*/
77
angular.module('angular-confirm', ['ui.bootstrap'])
8-
.controller('ConfirmModalController', ['$scope', '$modalInstance', 'data', function ($scope, $modalInstance, data) {
9-
$scope.data = angular.copy(data);
8+
.controller('ConfirmModalController', ['$scope', '$modalInstance', 'data', function ($scope, $modalInstance, data) {
9+
$scope.data = angular.copy(data);
1010

11-
$scope.ok = function () {
12-
$modalInstance.close();
13-
};
11+
$scope.ok = function () {
12+
$modalInstance.close();
13+
};
1414

15-
$scope.cancel = function () {
16-
$modalInstance.dismiss('cancel');
17-
};
15+
$scope.cancel = function () {
16+
$modalInstance.dismiss('cancel');
17+
};
1818

19-
}])
20-
.value('$confirmModalDefaults', {
21-
template: '<div class="modal-header"><h3 class="modal-title">{{data.title}}</h3></div>' +
22-
'<div class="modal-body">{{data.text}}</div>' +
23-
'<div class="modal-footer">' +
24-
'<button class="btn btn-primary" ng-click="ok()">{{data.ok}}</button>' +
25-
'<button class="btn btn-default" ng-click="cancel()">{{data.cancel}}</button>' +
26-
'</div>',
27-
controller: 'ConfirmModalController',
28-
defaultLabels: {
29-
title :'Confirm',
30-
ok: 'OK',
31-
cancel: 'Cancel'
32-
}
33-
})
34-
.factory('$confirm', ['$modal', '$confirmModalDefaults', function($modal, $confirmModalDefaults) {
35-
return function(data, settings) {
36-
settings = angular.extend($confirmModalDefaults, (settings || {}));
37-
38-
data = angular.extend({}, settings.defaultLabels, data || {});
39-
40-
if ('templateUrl' in settings && 'template' in settings) {
41-
delete settings.template;
19+
}])
20+
.value('$confirmModalDefaults', {
21+
template: '<div class="modal-header"><h3 class="modal-title">{{data.title}}</h3></div>' +
22+
'<div class="modal-body">{{data.text}}</div>' +
23+
'<div class="modal-footer">' +
24+
'<button class="btn btn-primary" ng-click="ok()">{{data.ok}}</button>' +
25+
'<button class="btn btn-default" ng-click="cancel()">{{data.cancel}}</button>' +
26+
'</div>',
27+
controller: 'ConfirmModalController',
28+
defaultLabels: {
29+
title: 'Confirm',
30+
ok: 'OK',
31+
cancel: 'Cancel'
4232
}
33+
})
34+
.factory('$confirm', ['$modal', '$confirmModalDefaults', function ($modal, $confirmModalDefaults) {
35+
return function (data, settings) {
36+
settings = angular.extend($confirmModalDefaults, (settings || {}));
37+
38+
data = angular.extend({}, settings.defaultLabels, data || {});
39+
40+
if ('templateUrl' in settings && 'template' in settings) {
41+
delete settings.template;
42+
}
43+
44+
settings.resolve = {
45+
data: function () {
46+
return data;
47+
}
48+
};
49+
50+
return $modal.open(settings).result;
51+
};
52+
}])
53+
.directive('confirm', ['$confirm', function ($confirm) {
54+
return {
55+
priority: 1,
56+
restrict: 'A',
57+
scope: {
58+
confirmIf: "=",
59+
ngClick: '&',
60+
confirm: '@',
61+
confirmSettings: "=",
62+
confirmTitle: '@',
63+
confirmOk: '@',
64+
confirmCancel: '@'
65+
},
66+
link: function (scope, element, attrs) {
4367

44-
settings.resolve = {data: function() { return data; }};
4568

46-
return $modal.open(settings).result;
47-
};
48-
}])
49-
.directive('confirm', ['$confirm', function($confirm) {
50-
return {
51-
priority: 1,
52-
restrict: 'A',
53-
scope: {
54-
confirmIf: "=",
55-
ngClick: '&',
56-
confirm: '@',
57-
confirmSettings: "=",
58-
confirmTitle: '@',
59-
confirmOk: '@',
60-
confirmCancel: '@'
61-
},
62-
link: function(scope, element, attrs) {
69+
element.unbind("click").bind("click", function ($event) {
6370

64-
function reBind(func) {
65-
element.unbind("click").bind("click", function($event) {
6671
$event.preventDefault();
67-
func();
68-
});
69-
}
7072

71-
function bindConfirm() {
72-
var data = { text: scope.confirm };
73-
if (scope.confirmTitle) {
74-
data.title = scope.confirmTitle;
75-
}
76-
if (scope.confirmOk) {
77-
data.ok = scope.confirmOk;
78-
}
79-
if (scope.confirmCancel) {
80-
data.cancel = scope.confirmCancel;
81-
}
82-
$confirm(data, scope.confirmSettings || {}).then(scope.ngClick);
83-
}
73+
if (angular.isUndefined(scope.confirmIf) || scope.confirmIf) {
8474

85-
if (attrs.confirmIf && attrs.confirmIf != "") {
86-
scope.$watch('confirmIf', function(newVal) {
87-
if (newVal) {
88-
reBind(bindConfirm);
75+
var data = {text: scope.confirm};
76+
if (scope.confirmTitle) {
77+
data.title = scope.confirmTitle;
78+
}
79+
if (scope.confirmOk) {
80+
data.ok = scope.confirmOk;
81+
}
82+
if (scope.confirmCancel) {
83+
data.cancel = scope.confirmCancel;
84+
}
85+
$confirm(data, scope.confirmSettings || {}).then(scope.ngClick);
8986
} else {
90-
reBind(function() {
91-
scope.$apply(scope.ngClick);
92-
});
87+
88+
scope.$apply(scope.ngClick);
9389
}
9490
});
95-
} else {
96-
reBind(bindConfirm);
91+
9792
}
9893
}
99-
}
100-
}]);
94+
}]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-confirm",
3-
"version": "1.0.5",
3+
"version": "1.1.0",
44
"description": "Angular Confirm Modal",
55
"main": "angular-confirm.js",
66
"scripts": {

0 commit comments

Comments
 (0)