jconfirmaction.jquery.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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(){},
  20. onOpen: function(){},
  21. onClose: function(){}
  22. }, options);
  23. $(this).live('click', function(e) {
  24. $('div.question').remove();
  25. link = $(this);
  26. options.onOpen(link);
  27. e.preventDefault();
  28. thisHref = $(this).attr('href');
  29. if($(this).next('.question').length <= 0)
  30. $(this).after('<div class="question">'+theOptions.question
  31. +'<br/> <span class="yes">'+theOptions.yesAnswer
  32. +'</span><span class="cancel">'+theOptions.cancelAnswer
  33. +'</span></div>');
  34. $(this).next('.question').animate({opacity: 1}, 300);
  35. $('.yes').bind('click', function(){
  36. options.onYes(link);
  37. });
  38. $('.cancel').bind('click', function(){
  39. $(this).parents('.question').fadeOut(300, function() {
  40. options.onClose(link);
  41. $(this).remove();
  42. });
  43. });
  44. });
  45. }
  46. })(jQuery);