SampleTextBox.js 2.6 KB

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