FocusBehavior.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Register the namespace for the control.
  2. Type.registerNamespace('Samples');
  3. //
  4. // Define the behavior properties.
  5. //
  6. Samples.FocusBehavior = function(element) {
  7. Samples.FocusBehavior.initializeBase(this, [element]);
  8. this._highlightCssClass = null;
  9. this._nohighlightCssClass = null;
  10. }
  11. //
  12. // Create the prototype for the behavior.
  13. //
  14. Samples.FocusBehavior.prototype = {
  15. initialize : function() {
  16. Samples.FocusBehavior.callBaseMethod(this, 'initialize');
  17. $addHandlers(this.get_element(),
  18. { 'focus' : this._onFocus,
  19. 'blur' : this._onBlur },
  20. this);
  21. this.get_element().className = this._nohighlightCssClass;
  22. },
  23. dispose : function() {
  24. $clearHandlers(this.get_element());
  25. Samples.FocusBehavior.callBaseMethod(this, 'dispose');
  26. },
  27. //
  28. // Event delegates
  29. //
  30. _onFocus : function(e) {
  31. if (this.get_element() && !this.get_element().disabled) {
  32. this.get_element().className = this._highlightCssClass;
  33. }
  34. },
  35. _onBlur : function(e) {
  36. if (this.get_element() && !this.get_element().disabled) {
  37. this.get_element().className = this._nohighlightCssClass;
  38. }
  39. },
  40. //
  41. // Behavior properties
  42. //
  43. get_highlightCssClass : function() {
  44. return this._highlightCssClass;
  45. },
  46. set_highlightCssClass : function(value) {
  47. if (this._highlightCssClass !== value) {
  48. this._highlightCssClass = value;
  49. this.raisePropertyChanged('highlightCssClass');
  50. }
  51. },
  52. get_nohighlightCssClass : function() {
  53. return this._nohighlightCssClass;
  54. },
  55. set_nohighlightCssClass : function(value) {
  56. if (this._nohighlightCssClass !== value) {
  57. this._nohighlightCssClass = value;
  58. this.raisePropertyChanged('nohighlightCssClass');
  59. }
  60. }
  61. }
  62. // Optional descriptor for JSON serialization.
  63. Samples.FocusBehavior.descriptor = {
  64. properties: [ {name: 'highlightCssClass', type: String},
  65. {name: 'nohighlightCssClass', type: String} ]
  66. }
  67. // Register the class as a type that inherits from Sys.UI.Control.
  68. Samples.FocusBehavior.registerClass('Samples.FocusBehavior', Sys.UI.Behavior);
  69. if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();