EasyUI Forum
April 23, 2024, 02:01:52 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: extend linkbutton to prevent double click.  (Read 5790 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« 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 ??

Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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);
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #2 on: November 14, 2019, 04:15:43 PM »

Thanks very much, I will try that.
Logged

-- Licensed User --
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!