-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.togglebutton.js
44 lines (37 loc) · 1.08 KB
/
jquery.togglebutton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* jQuery Toggle Button
* by Chris Korhonen (sourcebottle.net)
* http://github.com/ckorhonen/jQuery-Toggle-Button
*
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
jQuery.fn.toggleButton = function(settings) {
settings = jQuery.extend({
text: "Please Wait...",
className: "disabled",
preventClick: true
}, settings);
var originalText = $(this).text();
if(!originalText){
originalText = $(this).attr('value');
}
var isDisabled = $(this).hasClass(settings.className);
$(this).toggleClass(settings.className).text(settings.text).attr('value', settings.text);
try{
if(!$(this).data('events').change){
$(this).bind('change',function(e){
if(!$(e.target).hasClass(settings.className)){
$(e.target).text(originalText).attr('value',originalText);
}
});
}
} catch(e){ //if no object data exists
}
if(!isDisabled && settings.preventClick){
$(this).attr('disabled', 'disabled');
} else {
$(this).removeAttr('disabled');
}
$(this).trigger('change');
};