Created
January 18, 2012 22:53
-
-
Save jimmysawczuk/1636333 to your computer and use it in GitHub Desktop.
make confirm javascript
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
function makeConfirm(orig, confirm_callback, prompt, confirm_text, cancel_text) | |
{ | |
if (typeof prompt == "undefined") | |
{ | |
prompt = "Are you sure?"; | |
} | |
if (typeof confirm_text == "undefined") | |
{ | |
confirm_text = "Yes"; | |
} | |
if (typeof confirm_text == "undefined"); | |
{ | |
cancel_text = "No"; | |
} | |
$(orig).click(function() | |
{ | |
var clicked = $(this); | |
($('<span />') | |
.append(prompt) | |
.append($('<input />') | |
.attr({'type': 'button', 'value': confirm_text}) | |
.click(function() | |
{ | |
confirm_callback(); | |
}) | |
).append($('<input />') | |
.attr({'type': 'button', 'value': cancel_text}) | |
.click(function() | |
{ | |
$(this).parent().hide(); | |
clicked.show(); | |
}) | |
) | |
).insertBefore(clicked); | |
clicked.hide(); | |
}); | |
} |
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
makeConfirm(delete_btn, function() | |
{ | |
alert('deleted!'); | |
}, 'Are you sure you want to delete this question?'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment