Created
February 6, 2014 18:30
-
-
Save Lawondyss/8849849 to your computer and use it in GitHub Desktop.
Uses CSS framework SemanticUI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
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"