diff --git a/src/index.js b/src/index.js index 12b379d..9f82adf 100644 --- a/src/index.js +++ b/src/index.js @@ -34,7 +34,8 @@ function ngDialog ($document, $compile, $rootScope, $controller, $timeout, $q) { cancel: cancel, submit: submit, confirm: confirm, - reason: reason + reason: reason, + alert: alert } function submit (data) { @@ -57,6 +58,48 @@ function ngDialog ($document, $compile, $rootScope, $controller, $timeout, $q) { return deferred.reject('Canceled') } + function alert (text, title) { + deferred = $q.defer() + title = title || 'this can not be undone'; + + var alertModal = angular.element( + '
' + + '
' + + '
' + + '

' + title + '

' + + '
' + + '
' + + '
' + text + '
' + + '
' + + '' + + '
' + + '
' + ) + + var scope = $rootScope.$new() + + scope.accept = function () { + alertModal.remove() + return deferred.resolve() + } + + $compile(alertModal)(scope) + + // Attach compiled modal to DOM + body.append(alertModal) + + $timeout(function () { + $timeout(function () { + document.querySelector('#dialog-alert').classList.add('show-dialog') + }, 200) + alertModal.addClass('fadeIn') + }, 0) + + return deferred.promise + } + function confirm (text) { deferred = $q.defer()