react fake double , bind click and dblclick on the same element

zyip發表於2016-05-23

 

 

smartClick:function(id,name,waiter,e){
                var desk = $$(e.currentTarget).data('raw');
                if(this.lastClickTime[id] && ((new Date())-this.lastClickTime[id])>70)
                {//quick click twice , it seems a dblclick
                    console.log('dblclick');
                    this.lastClickTime[id]=undefined;
                    this.clickHandler && clearTimeout(this.clickHandler);
                    this.clickHandler = 0;
                    return;
                }

                if(!this.clickHandler)
                {
                    this.clickHandler=setTimeout(function(){
                        console.log('click');
                        this.lastClickTime[id]=undefined;
                        clearTimeout(this.clickHandler);
                        this.clickHandler = 0;
                    }.bind(this),300);
                    this.lastClickTime[id]=new Date();    
                }                
                return;
                
            },

 

相關文章