53e77aa8398f7a462783fd7d7fe466e3f1eaac48.svn-base 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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.Toolbar = function(A) {
  7. if (A instanceof Array) {
  8. A = {
  9. buttons : A
  10. }
  11. }
  12. Ext.Toolbar.superclass.constructor.call(this, A)
  13. };
  14. (function() {
  15. var A = Ext.Toolbar;
  16. Ext.extend(A, Ext.BoxComponent, {
  17. trackMenus : true,
  18. initComponent : function() {
  19. A.superclass.initComponent.call(this);
  20. if (this.items) {
  21. this.buttons = this.items
  22. }
  23. this.items = new Ext.util.MixedCollection(false,
  24. function(B) {
  25. return B.itemId || B.id || Ext.id()
  26. })
  27. },
  28. autoCreate : {
  29. cls : "x-toolbar x-small-editor",
  30. html : "<table cellspacing=\"0\"><tr></tr></table>"
  31. },
  32. onRender : function(C, B) {
  33. this.el = C.createChild(this.autoCreate, B);
  34. this.tr = this.el.child("tr", true)
  35. },
  36. afterRender : function() {
  37. A.superclass.afterRender.call(this);
  38. if (this.buttons) {
  39. this.add.apply(this, this.buttons);
  40. delete this.buttons
  41. }
  42. },
  43. add : function() {
  44. var C = arguments, B = C.length;
  45. for (var D = 0; D < B; D++) {
  46. var E = C[D];
  47. if (E.isFormField) {
  48. this.addField(E)
  49. } else {
  50. if (E.render) {
  51. this.addItem(E)
  52. } else {
  53. if (typeof E == "string") {
  54. if (E == "separator" || E == "-") {
  55. this.addSeparator()
  56. } else {
  57. if (E == " ") {
  58. this.addSpacer()
  59. } else {
  60. if (E == "->") {
  61. this.addFill()
  62. } else {
  63. this.addText(E)
  64. }
  65. }
  66. }
  67. } else {
  68. if (E.tagName) {
  69. this.addElement(E)
  70. } else {
  71. if (typeof E == "object") {
  72. if (E.xtype) {
  73. this.addField(Ext.ComponentMgr
  74. .create(E, "button"))
  75. } else {
  76. this.addButton(E)
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. },
  85. addSeparator : function() {
  86. return this.addItem(new A.Separator())
  87. },
  88. addSpacer : function() {
  89. return this.addItem(new A.Spacer())
  90. },
  91. addFill : function() {
  92. return this.addItem(new A.Fill())
  93. },
  94. addElement : function(B) {
  95. return this.addItem(new A.Item(B))
  96. },
  97. addItem : function(B) {
  98. var C = this.nextBlock();
  99. this.initMenuTracking(B);
  100. B.render(C);
  101. this.items.add(B);
  102. return B
  103. },
  104. addButton : function(D) {
  105. if (D instanceof Array) {
  106. var F = [];
  107. for (var E = 0, C = D.length; E < C; E++) {
  108. F.push(this.addButton(D[E]))
  109. }
  110. return F
  111. }
  112. var B = D;
  113. if (!(D instanceof A.Button)) {
  114. B = D.split ? new A.SplitButton(D) : new A.Button(D)
  115. }
  116. var G = this.nextBlock();
  117. this.initMenuTracking(B);
  118. B.render(G);
  119. this.items.add(B);
  120. return B
  121. },
  122. initMenuTracking : function(B) {
  123. if (this.trackMenus && B.menu) {
  124. B.on({
  125. "menutriggerover" : this.onButtonTriggerOver,
  126. "menushow" : this.onButtonMenuShow,
  127. "menuhide" : this.onButtonMenuHide,
  128. scope : this
  129. })
  130. }
  131. },
  132. addText : function(B) {
  133. return this.addItem(new A.TextItem(B))
  134. },
  135. insertButton : function(C, F) {
  136. if (F instanceof Array) {
  137. var E = [];
  138. for (var D = 0, B = F.length; D < B; D++) {
  139. E.push(this.insertButton(C + D, F[D]))
  140. }
  141. return E
  142. }
  143. if (!(F instanceof A.Button)) {
  144. F = new A.Button(F)
  145. }
  146. var G = document.createElement("td");
  147. this.tr.insertBefore(G, this.tr.childNodes[C]);
  148. this.initMenuTracking(F);
  149. F.render(G);
  150. this.items.insert(C, F);
  151. return F
  152. },
  153. addDom : function(C, B) {
  154. var E = this.nextBlock();
  155. Ext.DomHelper.overwrite(E, C);
  156. var D = new A.Item(E.firstChild);
  157. D.render(E);
  158. this.items.add(D);
  159. return D
  160. },
  161. addField : function(C) {
  162. var D = this.nextBlock();
  163. C.render(D);
  164. var B = new A.Item(D.firstChild);
  165. B.render(D);
  166. this.items.add(B);
  167. return B
  168. },
  169. nextBlock : function() {
  170. var B = document.createElement("td");
  171. this.tr.appendChild(B);
  172. return B
  173. },
  174. onDestroy : function() {
  175. Ext.Toolbar.superclass.onDestroy.call(this);
  176. if (this.rendered) {
  177. if (this.items) {
  178. Ext.destroy.apply(Ext, this.items.items)
  179. }
  180. Ext.Element.uncache(this.tr)
  181. }
  182. },
  183. onDisable : function() {
  184. this.items.each(function(B) {
  185. if (B.disable) {
  186. B.disable()
  187. }
  188. })
  189. },
  190. onEnable : function() {
  191. this.items.each(function(B) {
  192. if (B.enable) {
  193. B.enable()
  194. }
  195. })
  196. },
  197. onButtonTriggerOver : function(B) {
  198. if (this.activeMenuBtn && this.activeMenuBtn != B) {
  199. this.activeMenuBtn.hideMenu();
  200. B.showMenu();
  201. this.activeMenuBtn = B
  202. }
  203. },
  204. onButtonMenuShow : function(B) {
  205. this.activeMenuBtn = B
  206. },
  207. onButtonMenuHide : function(B) {
  208. delete this.activeMenuBtn
  209. }
  210. });
  211. Ext.reg("toolbar", Ext.Toolbar);
  212. A.Item = function(B) {
  213. this.el = Ext.getDom(B);
  214. this.id = Ext.id(this.el);
  215. this.hidden = false
  216. };
  217. A.Item.prototype = {
  218. getEl : function() {
  219. return this.el
  220. },
  221. render : function(B) {
  222. this.td = B;
  223. B.appendChild(this.el)
  224. },
  225. destroy : function() {
  226. if (this.td && this.td.parentNode) {
  227. this.td.parentNode.removeChild(this.td)
  228. }
  229. },
  230. show : function() {
  231. this.hidden = false;
  232. this.td.style.display = ""
  233. },
  234. hide : function() {
  235. this.hidden = true;
  236. this.td.style.display = "none"
  237. },
  238. setVisible : function(B) {
  239. if (B) {
  240. this.show()
  241. } else {
  242. this.hide()
  243. }
  244. },
  245. focus : function() {
  246. Ext.fly(this.el).focus()
  247. },
  248. disable : function() {
  249. Ext.fly(this.td).addClass("x-item-disabled");
  250. this.disabled = true;
  251. this.el.disabled = true
  252. },
  253. enable : function() {
  254. Ext.fly(this.td).removeClass("x-item-disabled");
  255. this.disabled = false;
  256. this.el.disabled = false
  257. }
  258. };
  259. Ext.reg("tbitem", A.Item);
  260. A.Separator = function() {
  261. var B = document.createElement("span");
  262. B.className = "ytb-sep";
  263. A.Separator.superclass.constructor.call(this, B)
  264. };
  265. Ext.extend(A.Separator, A.Item, {
  266. enable : Ext.emptyFn,
  267. disable : Ext.emptyFn,
  268. focus : Ext.emptyFn
  269. });
  270. Ext.reg("tbseparator", A.Separator);
  271. A.Spacer = function() {
  272. var B = document.createElement("div");
  273. B.className = "ytb-spacer";
  274. A.Spacer.superclass.constructor.call(this, B)
  275. };
  276. Ext.extend(A.Spacer, A.Item, {
  277. enable : Ext.emptyFn,
  278. disable : Ext.emptyFn,
  279. focus : Ext.emptyFn
  280. });
  281. Ext.reg("tbspacer", A.Spacer);
  282. A.Fill = Ext.extend(A.Spacer, {
  283. render : function(B) {
  284. B.style.width = "100%";
  285. A.Fill.superclass.render.call(this, B)
  286. }
  287. });
  288. Ext.reg("tbfill", A.Fill);
  289. A.TextItem = function(C) {
  290. var B = document.createElement("span");
  291. B.className = "ytb-text";
  292. B.innerHTML = C;
  293. A.TextItem.superclass.constructor.call(this, B)
  294. };
  295. Ext.extend(A.TextItem, A.Item, {
  296. enable : Ext.emptyFn,
  297. disable : Ext.emptyFn,
  298. focus : Ext.emptyFn
  299. });
  300. Ext.reg("tbtext", A.TextItem);
  301. A.Button = Ext.extend(Ext.Button, {
  302. hideParent : true,
  303. onDestroy : function() {
  304. A.Button.superclass.onDestroy.call(this);
  305. if (this.container) {
  306. this.container.remove()
  307. }
  308. }
  309. });
  310. Ext.reg("tbbutton", A.Button);
  311. A.SplitButton = Ext.extend(Ext.SplitButton, {
  312. hideParent : true,
  313. onDestroy : function() {
  314. A.SplitButton.superclass.onDestroy.call(this);
  315. if (this.container) {
  316. this.container.remove()
  317. }
  318. }
  319. });
  320. Ext.reg("tbsplit", A.SplitButton);
  321. A.MenuButton = A.SplitButton
  322. })();