a29ab505bd82c158f4cd07ec04d4bbb410dc65c3.svn-base 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.CycleButton = Ext.extend(Ext.SplitButton, {
  7. getItemText : function(A) {
  8. if (A && this.showText === true) {
  9. var B = "";
  10. if (this.prependText) {
  11. B += this.prependText
  12. }
  13. B += A.text;
  14. return B
  15. }
  16. return undefined
  17. },
  18. setActiveItem : function(C, A) {
  19. if (C) {
  20. if (!this.rendered) {
  21. this.text = this.getItemText(C);
  22. this.iconCls = C.iconCls
  23. } else {
  24. var B = this.getItemText(C);
  25. if (B) {
  26. this.setText(B)
  27. }
  28. this.setIconClass(C.iconCls)
  29. }
  30. this.activeItem = C;
  31. if (!A) {
  32. this.fireEvent("change", this, C)
  33. }
  34. }
  35. },
  36. getActiveItem : function() {
  37. return this.activeItem
  38. },
  39. initComponent : function() {
  40. this.addEvents("change");
  41. if (this.changeHandler) {
  42. this.on("change", this.changeHandler, this.scope || this);
  43. delete this.changeHandler
  44. }
  45. this.itemCount = this.items.length;
  46. this.menu = {
  47. cls : "x-cycle-menu",
  48. items : []
  49. };
  50. var D;
  51. for (var B = 0, A = this.itemCount; B < A; B++) {
  52. var C = this.items[B];
  53. C.group = C.group || this.id;
  54. C.itemIndex = B;
  55. C.checkHandler = this.checkHandler;
  56. C.scope = this;
  57. C.checked = C.checked || false;
  58. this.menu.items.push(C);
  59. if (C.checked) {
  60. D = C
  61. }
  62. }
  63. this.setActiveItem(D, true);
  64. Ext.CycleButton.superclass.initComponent.call(this);
  65. this.on("click", this.toggleSelected, this)
  66. },
  67. checkHandler : function(A, B) {
  68. if (B) {
  69. this.setActiveItem(A)
  70. }
  71. },
  72. toggleSelected : function() {
  73. this.menu.render();
  74. var C, A;
  75. for (var B = 1; B < this.itemCount; B++) {
  76. C = (this.activeItem.itemIndex + B) % this.itemCount;
  77. A = this.menu.items.itemAt(C);
  78. if (!A.disabled) {
  79. A.setChecked(true);
  80. break
  81. }
  82. }
  83. }
  84. });
  85. Ext.reg("cycle", Ext.CycleButton);