-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.onetime.min.js
1 lines (1 loc) · 1.22 KB
/
jquery.onetime.min.js
1
(function(a){a.extend(a.fn,{onetime:function(c,d){var b=this.filter("form");b.each(function(e,g){var f=new a.onetime(g,c,d);a(this).submit(function(h){if(!h.isDefaultPrevented()){f.disableButtons();f.triggerButtonEvent()}})});return this}});a.onetime=function(c,b,d){this.form=c;this.formSettings=a.extend(true,{},b);this.buttonSettings=a.extend(true,{},d);this.init()};a.extend(a.onetime,{prototype:{init:function(){var c=this;var b=this.buttons();jQuery.each(this.buttonSettings,function(d,e){var f=c.buttons(d);e=a.extend(true,{},c.formSettings,e);c.setupCallbacks(f,e);b=b.not(f)});this.setupCallbacks(b,this.formSettings)},buttons:function(b){var c=a(this.form).find("input:submit, input[type=image]");if(b!==undefined){c=c.filter(b)}return c},setupCallbacks:function(d,b){if(b.hasOwnProperty("disable")){d.bind("onetime-submit",b.disable)}if(b.hasOwnProperty("text")){d.bind("onetime-submit",function(){a(this).val(b.text)})}if(b.hasOwnProperty("loader")){d.bind("onetime-submit",function(){a(c.form).find(b.loader).show()})}var c=this;d.click(function(){c.submitButton=this})},disableButtons:function(){this.buttons().attr("disabled","disabled")},triggerButtonEvent:function(){a(this.submitButton).triggerHandler("onetime-submit")}}})})(jQuery);