| Sys.UI.ExtendedClickBehavior = function() { Sys.UI.ExtendedClickBehavior.initializeBase(this); var _clickHandler; // step 2 this.click = this.createEvent(); this.leftClick = this.createEvent(); this.rightClick = this.createEvent(); this.dispose = function() { // step 3 this.control.element.detachEvent('onmousedown', _clickHandler); Sys.UI.ExtendedClickBehavior.callBaseMethod(this, 'dispose'); } this.initialize = function() { Sys.UI.ExtendedClickBehavior.callBaseMethod(this, 'initialize'); // step 3 _clickHandler = Function.createDelegate(this, clickHandler); this.control.element.attachEvent('onmousedown', _clickHandler); } this.getDescriptor = function() { var td = Sys.UI.ExtendedClickBehavior.callBaseMethod(this, 'getDescriptor'); // step 5 td.addEvent('click', true); td.addEvent('leftClick', true); td.addEvent('rightClick', true); return td; } // step 4 function clickHandler() { this.click.invoke(this, Sys.EventArgs.Empty); if (window.event.button == 1) { this.leftClick.invoke(this, Sys.EventArgs.Empty); } else if (window.event.button == 2) { this.rightClick.invoke(this, Sys.EventArgs.Empty); } } } // step 1 Sys.UI.ExtendedClickBehavior.registerSealedClass('Sys.UI.ExtendedClickBehavior', Sys.UI.Behavior); Sys.TypeDescriptor.addType('script', 'extendedClickBehavior', Sys.UI.ExtendedClickBehavior); |
最新相关文章
发表评论