A Cool jQuery Plugin - FastConfirm
Posted At : December 2, 2010 3:44 PM | Posted By : Bob Silverberg
Related Categories: jQuery
I was working on the Engage app for cf.Objective() and I wanted to quickly add a confirmation dialog to the delete link for proposals. Now I'm not a particularly advanced jQuery developer, but I do know that there are a lot of people out there who are, and many of them have written plugins to help us lazier folks get things done. Through the power of Google I found a jQuery Plugins Page that lists all plugins that have been tagged with the term confirm. Wanting something quick and easy, I was drawn to one called Fast Confirm.
I checked out the demo and read through the docs, then saw some comments on the bottom of the docs page that suggested precisely how to implement the plugin for my exact use case. Within 10 minutes I had my confirmation dialog up and running! Here's the code:
2<script type="text/javascript" src="/js/jquery.fastconfirm.js"></script>
3<script type="text/javascript">
4 $(function(){
5 $(".confirm").click(function() {
6 $(this).fastConfirm({
7 position: "right",
8 onProceed: function(trigger) {
9 window.location.href=$(trigger).attr("href");
10 },
11 onCancel: function(trigger) {
12 }
13 });
14 return false;
15 });
16 });
17</script>
With the above script on my page, all I have to do is add a class of confirm to any anchor tag and I'll get a confirmation dialog whenever the anchor is clicked.
The plugin does allow you to change the question asked in the dialog, as well as a number of other options, but I was happy to accept the default of "Are you sure?". I think this is a great, simple plugin. Kudos to Pierre-Jean Parra for writing it and contributing it to the community.