EasyUI Forum

General Category => General Discussion => Topic started by: devnull on November 13, 2019, 11:43:47 PM



Title: extend linkbutton to prevent double click.
Post by: devnull on November 13, 2019, 11:43:47 PM
Right now, each time I use a linkbutton, or use the message dialog, I have to call a function that disables the button, sets a timeout and then enables the button again after say 1 second, and I have hundreds and hundreds of link buttons in my application.

Now I would like to extend the linkbutton onClick() event so that whenever any linkbutton is pressed, it will be disabled, but I do NOT want to break the onclick() event which is already being used hundreds of times throughout the application.

So somehow I need to extend the linkbutton, such that when it is clicked, it calls a oneclick(self) function and then calls the onClick() event.

Can this be done ??



Title: Re: extend linkbutton to prevent double click.
Post by: stworthy on November 14, 2019, 02:43:02 AM
You can redefine the behaviour of the linkbutton. Please refer to this code.
Code:
(function($){
function fix(target){
$(target).off('click.linkbutton').on('click.linkbutton', function(){
var opts = $(this).linkbutton('options');
if (!opts.disabled){
if (opts.toggle){
if (opts.selected){
$(this).linkbutton('unselect');
} else {
$(this).linkbutton('select');
}
}
// $(this).linkbutton('disable')
// setTimeout(function(){
// $(target).linkbutton('enable')
// },1000)
opts.onClick.call(this);
}
})
}
var plugin = $.fn.linkbutton;
$.fn.linkbutton = function(options, param){
if (typeof options == 'string'){
return plugin.call(this, options, param);
} else {
return this.each(function(){
plugin.call($(this), options, param);
fix(this);
});
}
}
$.fn.linkbutton.defaults = plugin.defaults;
$.fn.linkbutton.methods = plugin.methods;
$.fn.linkbutton.parseOptions = plugin.parseOptions;
})(jQuery);


Title: Re: extend linkbutton to prevent double click.
Post by: devnull on November 14, 2019, 04:15:43 PM
Thanks very much, I will try that.