jconfirmaction.jquery.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * jQuery Plugin : jConfirmAction
  3. *
  4. * by Hidayat Sagita
  5. * http://www.webstuffshare.com
  6. * Licensed Under GPL version 2 license.
  7. *
  8. */
  9. (function($){
  10. jQuery.fn.jConfirmAction = function (options) {
  11. // Some jConfirmAction options (limited to customize language) :
  12. // question : a text for your question.
  13. // yesAnswer : a text for Yes answer.
  14. // cancelAnswer : a text for Cancel/No answer.
  15. var theOptions = jQuery.extend ({
  16. question: "Are You Sure ?",
  17. yesAnswer: "Yes",
  18. cancelAnswer: "Cancel",
  19. onYes: function(){alert('No Callback used ! (jConfirmAction)')},
  20. onOpen: function(){},
  21. onClose: function(){}
  22. }, options);
  23. //return this.each (function () {
  24. $(this).live('click', function(e) {
  25. $('div.question').remove();
  26. link = $(this);
  27. options.onOpen(link);
  28. e.preventDefault();
  29. thisHref = $(this).attr('href');
  30. if($(this).next('.question').length <= 0)
  31. $(this).after('<div class="question">'+theOptions.question+'<br/> <span class="yes">'+theOptions.yesAnswer+'</span><span class="cancel">'+theOptions.cancelAnswer+'</span></div>');
  32. $(this).next('.question').animate({opacity: 1}, 300);
  33. $('.yes').bind('click', function(){
  34. options.onYes(link);
  35. });
  36. $('.cancel').bind('click', function(){
  37. $(this).parents('.question').fadeOut(300, function() {
  38. options.onClose(link);
  39. $(this).remove();
  40. });
  41. });
  42. });
  43. //});
  44. }
  45. })(jQuery);