Question.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. Type.registerNamespace("Demo");
  2. // Constructor
  3. Demo.Question = function(element) {
  4. Demo.Question.initializeBase(this, [element]);
  5. // Create a delegate for the select event.
  6. this._selectDelegate = null;
  7. }
  8. Demo.Question.prototype = {
  9. // correct property accessors
  10. get_correct: function() {
  11. return this.get_element().name - 1;
  12. },
  13. set_correct: function(value) {
  14. this.get_element().name = value;
  15. },
  16. // Bind and unbind to select event.
  17. add_select: function(handler) {
  18. this.get_events().addHandler('select', handler);
  19. },
  20. remove_select: function(handler) {
  21. this.get_events().removeHandler('select', handler);
  22. },
  23. // Release resources before control is disposed.
  24. dispose: function() {
  25. var element = this.get_element();
  26. if (this._selectDelegate) {
  27. $clearHandlers(element);
  28. delete this._selectDelegate;
  29. }
  30. Demo.Question.callBaseMethod(this, 'dispose');
  31. },
  32. initialize: function() {
  33. var element = this.get_element();
  34. // Make sure no option is selected.
  35. element.value = "";
  36. // Attach delegate to select event.
  37. if (this._selectDelegate === null) {
  38. this._selectDelegate = Function.createDelegate(this, this._selectHandler);
  39. }
  40. Sys.UI.DomEvent.addHandler(element, 'change', this._selectDelegate);
  41. Demo.Question.callBaseMethod(this, 'initialize');
  42. },
  43. _selectHandler: function(event) {
  44. var h = this.get_events().getHandler('select');
  45. if (h) h(this, Sys.EventArgs.Empty);
  46. }
  47. }
  48. Demo.Question.registerClass('Demo.Question', Sys.UI.Control);
  49. // Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
  50. // invoke Sys.Application.notifyScriptLoaded to notify ScriptManager
  51. // that this is the end of the script.
  52. if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();