Skip to content

Instantly share code, notes, and snippets.

@eibrahim
Created May 23, 2013 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eibrahim/5637279 to your computer and use it in GitHub Desktop.
Save eibrahim/5637279 to your computer and use it in GitHub Desktop.
'use strict';
angular.module('frontendApp')
.directive('confirmButton', function (Data) {
return {
restrict: "E",
replace: true,
template: "<a id=\"{{my_id}}\" class=\"btn btn-danger confirmation-popover-button\" ng-click=\"show()\" >\n <i class=\"halflings-icon {{icon || 'trash'}}\"></i>\n</a>",
scope: {
confirm: '&',
icon: '@'
},
link: function (scope, elm, attrs) {
scope.my_id = "my-confirm-button-" + (Data.getNewCount());
scope.click = function () {
scope.confirm();
return elm.popover('hide');
};
scope.cancel = function () {
return elm.popover('hide');
};
scope.show = function () {
$(".confirmation-popover-button").each(function (i, e) {
if ($(e).attr("id") !== scope.my_id) {
return $(e).popover("hide");
}
});
return elm.popover("show");
};
return elm.popover({
title: "Are you sure?",
html: true,
trigger: "manual",
content: "<div class='my-confirmation-popover' class='btn-toolbar'>\n <button ng-click='cancel()' class='btn btn-link'>No</button>\n <button class='btn btn-danger' ng-click='click()'>Yes</button>\n</div>"
}).on("shown", function () {
var h;
h = $(".my-confirmation-popover").contents();
return $compile(h)(scope);
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment