HoverButton.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Introductory boilerplate:
  3. The following example shows how to use the EventHandlerList class in context
  4. of a custom ajax_current_short control. To create a custom control and
  5. add it to your application, see Creating Custom ajax_current_short Client
  6. Controls, which includes the complete control this simplified example is based
  7. on.
  8. */
  9. // Register namespace.
  10. Type.registerNamespace("Demo");
  11. Demo.HoverButton = function(element) {
  12. Demo.HoverButton.initializeBase(this, [element]);
  13. // Create delegates in the Constructor.
  14. this._clickDelegate = null;
  15. }
  16. Demo.HoverButton.prototype = {
  17. // Bind and unbind to click event.
  18. add_click: function(handler) {
  19. this.get_events().addHandler('click', handler);
  20. },
  21. remove_click: function(handler) {
  22. this.get_events().removeHandler('click', handler);
  23. },
  24. initialize: function() {
  25. var element = this.get_element();
  26. // Bind handler to delegate.
  27. if (this._clickDelegate === null) {
  28. this._clickDelegate = Function.createDelegate(this, this._clickHandler);
  29. }
  30. Sys.UI.DomEvent.addHandler(element, 'click', this._clickDelegate);
  31. Demo.HoverButton.callBaseMethod(this, 'initialize');
  32. },
  33. _clickHandler: function(event) {
  34. var h = this.get_events().getHandler('click');
  35. if (h) h(this, Sys.EventArgs.Empty);
  36. },
  37. // Release resources before control is disposed.
  38. dispose: function() {
  39. var element = this.get_element();
  40. if (this._clickDelegate) {
  41. Sys.UI.DomEvent.removeHandler(element, 'click', this._clickDelegate);
  42. delete this._clickDelegate;
  43. }
  44. Demo.HoverButton.callBaseMethod(this, 'dispose');
  45. }
  46. }
  47. // Register the class.
  48. Demo.HoverButton.registerClass('Demo.HoverButton', Sys.UI.Control);
  49. // Notify the ScriptManager that this is the end of the script.
  50. if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();