Skip to content

Instantly share code, notes, and snippets.

@Lawondyss
Created February 6, 2014 18:30
Show Gist options
  • Save Lawondyss/8849849 to your computer and use it in GitHub Desktop.
Save Lawondyss/8849849 to your computer and use it in GitHub Desktop.
Uses CSS framework SemanticUI.
angular.module('Confirmation', [])
.directive 'ngConfirmClick', ($parse) ->
restrict: 'A'
link: (scope, element, attrs) ->
popId = Math.floor Math.random() * 10000000000
attrs.popId = popId
message = attrs.message ? 'Do you really want to delete?'
okLabel = attrs.okLabel ? 'Yes'
cancelLabel = attrs.cancelLabel ? 'No'
html = '
<div style="text-align: center;">
<p><strong>' + message + '</strong></p>
<div id="pop-' + popId + '" class="ui small buttons">
<div class="ui positive button" style="width: auto;">' + okLabel + '</div>
<div class="or"></div>
<div class="ui negative button" style="width: auto;">' + cancelLabel + '</div>
</div>
</div>
'
element.popup
position: 'left center'
inline: true
on: 'click'
html: html
element.bind 'click', () ->
pop = $ '#pop-' + popId
pop
.find('.positive')
.click () ->
func = $parse attrs.ngConfirmClick
func scope
element.popup 'hide'
return
pop
.find('.negative')
.click () ->
element.popup 'hide'
return
return
@Lawondyss
Copy link
Author

In template use attribute: ng-confirm-click="afterPositiveConfirmation()"
For change the default message use attribute: message="Are you sure?"
For change the default buttons labels use attributes: okLabel="yop" cancelLabel="nope"

@boxxxie
Copy link

boxxxie commented Feb 8, 2014

can you make a js fiddle or plunkr for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment