0ca8c41c2f1e86b71b3c66233f1abe52c9a8aee4.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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.TabPanel = Ext.extend(Ext.Panel, {
  7. monitorResize : true,
  8. deferredRender : true,
  9. tabWidth : 120,
  10. minTabWidth : 30,
  11. resizeTabs : false,
  12. enableTabScroll : false,
  13. scrollIncrement : 0,
  14. scrollRepeatInterval : 400,
  15. scrollDuration : 0.35,
  16. animScroll : true,
  17. tabPosition : "top",
  18. baseCls : "x-tab-panel",
  19. autoTabs : false,
  20. autoTabSelector : "div.x-tab",
  21. itemCls : "x-tab-item",
  22. activeTab : null,
  23. tabMargin : 2,
  24. plain : false,
  25. wheelIncrement : 20,
  26. elements : "body",
  27. headerAsText : false,
  28. frame : false,
  29. hideBorders : true,
  30. initComponent : function() {
  31. this.frame = false;
  32. Ext.TabPanel.superclass.initComponent.call(this);
  33. this.addEvents("beforetabchange", "tabchange", "contextmenu");
  34. this.setLayout(new Ext.layout.CardLayout({
  35. deferredRender : this.deferredRender
  36. }));
  37. if (this.tabPosition == "top") {
  38. this.elements += ",header";
  39. this.stripTarget = "header"
  40. } else {
  41. this.elements += ",footer";
  42. this.stripTarget = "footer"
  43. }
  44. if (!this.stack) {
  45. this.stack = Ext.TabPanel.AccessStack()
  46. }
  47. this.initItems()
  48. },
  49. render : function() {
  50. Ext.TabPanel.superclass.render.apply(this, arguments);
  51. if (this.activeTab !== undefined) {
  52. var A = this.activeTab;
  53. delete this.activeTab;
  54. this.setActiveTab(A)
  55. }
  56. },
  57. onRender : function(C, A) {
  58. Ext.TabPanel.superclass.onRender.call(this, C, A);
  59. if (this.plain) {
  60. var E = this.tabPosition == "top" ? "header" : "footer";
  61. this[E].addClass("x-tab-panel-" + E + "-plain")
  62. }
  63. var B = this[this.stripTarget];
  64. this.stripWrap = B.createChild({
  65. cls : "x-tab-strip-wrap",
  66. cn : {
  67. tag : "ul",
  68. cls : "x-tab-strip x-tab-strip-" + this.tabPosition
  69. }
  70. });
  71. this.stripSpacer = B.createChild({
  72. cls : "x-tab-strip-spacer"
  73. });
  74. this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
  75. this.edge = this.strip.createChild({
  76. tag : "li",
  77. cls : "x-tab-edge"
  78. });
  79. this.strip.createChild({
  80. cls : "x-clear"
  81. });
  82. this.body.addClass("x-tab-panel-body-" + this.tabPosition);
  83. if (!this.itemTpl) {
  84. var D = new Ext.Template(
  85. "<li class=\"{cls}\" id=\"{id}\"><a class=\"x-tab-strip-close\" onclick=\"return false;\"></a>",
  86. "<a class=\"x-tab-right\" href=\"#\" onclick=\"return false;\"><em class=\"x-tab-left\">",
  87. "<span class=\"x-tab-strip-inner\"><span class=\"x-tab-strip-text {iconCls}\">{text}</span></span>",
  88. "</em></a></li>");
  89. D.disableFormats = true;
  90. D.compile();
  91. Ext.TabPanel.prototype.itemTpl = D
  92. }
  93. this.items.each(this.initTab, this)
  94. },
  95. afterRender : function() {
  96. Ext.TabPanel.superclass.afterRender.call(this);
  97. if (this.autoTabs) {
  98. this.readTabs(false)
  99. }
  100. },
  101. initEvents : function() {
  102. Ext.TabPanel.superclass.initEvents.call(this);
  103. this.on("add", this.onAdd, this);
  104. this.on("remove", this.onRemove, this);
  105. this.strip.on("mousedown", this.onStripMouseDown, this);
  106. this.strip.on("click", this.onStripClick, this);
  107. this.strip.on("contextmenu", this.onStripContextMenu, this);
  108. if (this.enableTabScroll) {
  109. this.strip.on("mousewheel", this.onWheel, this)
  110. }
  111. },
  112. findTargets : function(C) {
  113. var B = null;
  114. var A = C.getTarget("li", this.strip);
  115. if (A) {
  116. B = this.getComponent(A.id.split("__")[1]);
  117. if (B.disabled) {
  118. return {
  119. close : null,
  120. item : null,
  121. el : null
  122. }
  123. }
  124. }
  125. return {
  126. close : C.getTarget(".x-tab-strip-close", this.strip),
  127. item : B,
  128. el : A
  129. }
  130. },
  131. onStripMouseDown : function(B) {
  132. B.preventDefault();
  133. if (B.button != 0) {
  134. return
  135. }
  136. var A = this.findTargets(B);
  137. if (A.close) {
  138. this.remove(A.item);
  139. return
  140. }
  141. if (A.item && A.item != this.activeTab) {
  142. this.setActiveTab(A.item)
  143. }
  144. },
  145. onStripClick : function(B) {
  146. var A = this.findTargets(B);
  147. if (!A.close && A.item && A.item != this.activeTab) {
  148. this.setActiveTab(A.item)
  149. }
  150. },
  151. onStripContextMenu : function(B) {
  152. B.preventDefault();
  153. var A = this.findTargets(B);
  154. if (A.item) {
  155. this.fireEvent("contextmenu", this, A.item, B)
  156. }
  157. },
  158. readTabs : function(D) {
  159. if (D === true) {
  160. this.items.each(function(G) {
  161. this.remove(G)
  162. }, this)
  163. }
  164. var C = this.el.query(this.autoTabSelector);
  165. for (var B = 0, A = C.length; B < A; B++) {
  166. var E = C[B];
  167. var F = E.getAttribute("title");
  168. E.removeAttribute("title");
  169. this.add({
  170. title : F,
  171. el : E
  172. })
  173. }
  174. },
  175. initTab : function(D, B) {
  176. var E = this.strip.dom.childNodes[B];
  177. var A = D.closable ? "x-tab-strip-closable" : "";
  178. if (D.disabled) {
  179. A += " x-item-disabled"
  180. }
  181. if (D.iconCls) {
  182. A += " x-tab-with-icon"
  183. }
  184. var F = {
  185. id : this.id + "__" + D.getItemId(),
  186. text : D.title,
  187. cls : A,
  188. iconCls : D.iconCls || ""
  189. };
  190. var C = E ? this.itemTpl.insertBefore(E, F) : this.itemTpl.append(
  191. this.strip, F);
  192. Ext.fly(C).addClassOnOver("x-tab-strip-over");
  193. if (D.tabTip) {
  194. Ext.fly(C).child("span.x-tab-strip-text", true).qtip = D.tabTip
  195. }
  196. D.on("disable", this.onItemDisabled, this);
  197. D.on("enable", this.onItemEnabled, this);
  198. D.on("titlechange", this.onItemTitleChanged, this);
  199. D.on("beforeshow", this.onBeforeShowItem, this)
  200. },
  201. onAdd : function(C, B, A) {
  202. this.initTab(B, A);
  203. if (this.items.getCount() == 1) {
  204. this.syncSize()
  205. }
  206. this.delegateUpdates()
  207. },
  208. onBeforeAdd : function(B) {
  209. var A = B.events
  210. ? (this.items.containsKey(B.getItemId()) ? B : null)
  211. : this.items.get(B);
  212. if (A) {
  213. this.setActiveTab(B);
  214. return false
  215. }
  216. Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
  217. var C = B.elements;
  218. B.elements = C ? C.replace(",header", "") : C;
  219. B.border = (B.border === true)
  220. },
  221. onRemove : function(C, B) {
  222. Ext.removeNode(this.getTabEl(B));
  223. this.stack.remove(B);
  224. if (B == this.activeTab) {
  225. var A = this.stack.next();
  226. if (A) {
  227. this.setActiveTab(A)
  228. } else {
  229. this.setActiveTab(0)
  230. }
  231. }
  232. this.delegateUpdates()
  233. },
  234. onBeforeShowItem : function(A) {
  235. if (A != this.activeTab) {
  236. this.setActiveTab(A);
  237. return false
  238. }
  239. },
  240. onItemDisabled : function(B) {
  241. var A = this.getTabEl(B);
  242. if (A) {
  243. Ext.fly(A).addClass("x-item-disabled")
  244. }
  245. this.stack.remove(B)
  246. },
  247. onItemEnabled : function(B) {
  248. var A = this.getTabEl(B);
  249. if (A) {
  250. Ext.fly(A).removeClass("x-item-disabled")
  251. }
  252. },
  253. onItemTitleChanged : function(B) {
  254. var A = this.getTabEl(B);
  255. if (A) {
  256. Ext.fly(A).child("span.x-tab-strip-text", true).innerHTML = B.title
  257. }
  258. },
  259. getTabEl : function(A) {
  260. return document.getElementById(this.id + "__" + A.getItemId())
  261. },
  262. onResize : function() {
  263. Ext.TabPanel.superclass.onResize.apply(this, arguments);
  264. this.delegateUpdates()
  265. },
  266. beginUpdate : function() {
  267. this.suspendUpdates = true
  268. },
  269. endUpdate : function() {
  270. this.suspendUpdates = false;
  271. this.delegateUpdates()
  272. },
  273. hideTabStripItem : function(B) {
  274. B = this.getComponent(B);
  275. var A = this.getTabEl(B);
  276. if (A) {
  277. A.style.display = "none";
  278. this.delegateUpdates()
  279. }
  280. },
  281. unhideTabStripItem : function(B) {
  282. B = this.getComponent(B);
  283. var A = this.getTabEl(B);
  284. if (A) {
  285. A.style.display = "";
  286. this.delegateUpdates()
  287. }
  288. },
  289. delegateUpdates : function() {
  290. if (this.suspendUpdates) {
  291. return
  292. }
  293. if (this.resizeTabs && this.rendered) {
  294. this.autoSizeTabs()
  295. }
  296. if (this.enableTabScroll && this.rendered) {
  297. this.autoScrollTabs()
  298. }
  299. },
  300. autoSizeTabs : function() {
  301. var G = this.items.length;
  302. var B = this.tabPosition != "bottom" ? "header" : "footer";
  303. var C = this[B].dom.offsetWidth;
  304. var A = this[B].dom.clientWidth;
  305. if (!this.resizeTabs || G < 1 || !A) {
  306. return
  307. }
  308. var I = Math.max(Math.min(Math.floor((A - 4) / G) - this.tabMargin,
  309. this.tabWidth), this.minTabWidth);
  310. this.lastTabWidth = I;
  311. var K = this.stripWrap.dom.getElementsByTagName("li");
  312. for (var E = 0, H = K.length - 1; E < H; E++) {
  313. var J = K[E];
  314. var L = J.childNodes[1].firstChild.firstChild;
  315. var F = J.offsetWidth;
  316. var D = L.offsetWidth;
  317. L.style.width = (I - (F - D)) + "px"
  318. }
  319. },
  320. adjustBodyWidth : function(A) {
  321. if (this.header) {
  322. this.header.setWidth(A)
  323. }
  324. if (this.footer) {
  325. this.footer.setWidth(A)
  326. }
  327. return A
  328. },
  329. setActiveTab : function(C) {
  330. C = this.getComponent(C);
  331. if (!C
  332. || this.fireEvent("beforetabchange", this, C, this.activeTab) === false) {
  333. return
  334. }
  335. if (!this.rendered) {
  336. this.activeTab = C;
  337. return
  338. }
  339. if (this.activeTab != C) {
  340. if (this.activeTab) {
  341. var A = this.getTabEl(this.activeTab);
  342. if (A) {
  343. Ext.fly(A).removeClass("x-tab-strip-active")
  344. }
  345. this.activeTab.fireEvent("deactivate", this.activeTab)
  346. }
  347. var B = this.getTabEl(C);
  348. Ext.fly(B).addClass("x-tab-strip-active");
  349. this.activeTab = C;
  350. this.stack.add(C);
  351. this.layout.setActiveItem(C);
  352. if (this.layoutOnTabChange && C.doLayout) {
  353. C.doLayout()
  354. }
  355. if (this.scrolling) {
  356. this.scrollToTab(C, this.animScroll)
  357. }
  358. C.fireEvent("activate", C);
  359. this.fireEvent("tabchange", this, C)
  360. }
  361. },
  362. getActiveTab : function() {
  363. return this.activeTab || null
  364. },
  365. getItem : function(A) {
  366. return this.getComponent(A)
  367. },
  368. autoScrollTabs : function() {
  369. var F = this.items.length;
  370. var D = this.header.dom.offsetWidth;
  371. var C = this.header.dom.clientWidth;
  372. var E = this.stripWrap;
  373. var B = E.dom.offsetWidth;
  374. var G = this.getScrollPos();
  375. var A = this.edge.getOffsetsTo(this.stripWrap)[0] + G;
  376. if (!this.enableTabScroll || F < 1 || B < 20) {
  377. return
  378. }
  379. if (A <= C) {
  380. E.dom.scrollLeft = 0;
  381. E.setWidth(C);
  382. if (this.scrolling) {
  383. this.scrolling = false;
  384. this.header.removeClass("x-tab-scrolling");
  385. this.scrollLeft.hide();
  386. this.scrollRight.hide()
  387. }
  388. } else {
  389. if (!this.scrolling) {
  390. this.header.addClass("x-tab-scrolling")
  391. }
  392. C -= E.getMargins("lr");
  393. E.setWidth(C > 20 ? C : 20);
  394. if (!this.scrolling) {
  395. if (!this.scrollLeft) {
  396. this.createScrollers()
  397. } else {
  398. this.scrollLeft.show();
  399. this.scrollRight.show()
  400. }
  401. }
  402. this.scrolling = true;
  403. if (G > (A - C)) {
  404. E.dom.scrollLeft = A - C
  405. } else {
  406. this.scrollToTab(this.activeTab, false)
  407. }
  408. this.updateScrollButtons()
  409. }
  410. },
  411. createScrollers : function() {
  412. var C = this.stripWrap.dom.offsetHeight;
  413. var A = this.header.insertFirst({
  414. cls : "x-tab-scroller-left"
  415. });
  416. A.setHeight(C);
  417. A.addClassOnOver("x-tab-scroller-left-over");
  418. this.leftRepeater = new Ext.util.ClickRepeater(A, {
  419. interval : this.scrollRepeatInterval,
  420. handler : this.onScrollLeft,
  421. scope : this
  422. });
  423. this.scrollLeft = A;
  424. var B = this.header.insertFirst({
  425. cls : "x-tab-scroller-right"
  426. });
  427. B.setHeight(C);
  428. B.addClassOnOver("x-tab-scroller-right-over");
  429. this.rightRepeater = new Ext.util.ClickRepeater(B, {
  430. interval : this.scrollRepeatInterval,
  431. handler : this.onScrollRight,
  432. scope : this
  433. });
  434. this.scrollRight = B
  435. },
  436. getScrollWidth : function() {
  437. return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos()
  438. },
  439. getScrollPos : function() {
  440. return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0
  441. },
  442. getScrollArea : function() {
  443. return parseInt(this.stripWrap.dom.clientWidth, 10) || 0
  444. },
  445. getScrollAnim : function() {
  446. return {
  447. duration : this.scrollDuration,
  448. callback : this.updateScrollButtons,
  449. scope : this
  450. }
  451. },
  452. getScrollIncrement : function() {
  453. return this.scrollIncrement
  454. || (this.resizeTabs ? this.lastTabWidth + 2 : 100)
  455. },
  456. scrollToTab : function(E, A) {
  457. if (!E) {
  458. return
  459. }
  460. var C = this.getTabEl(E);
  461. var G = this.getScrollPos(), D = this.getScrollArea();
  462. var F = Ext.fly(C).getOffsetsTo(this.stripWrap)[0] + G;
  463. var B = F + C.offsetWidth;
  464. if (F < G) {
  465. this.scrollTo(F, A)
  466. } else {
  467. if (B > (G + D)) {
  468. this.scrollTo(B - D, A)
  469. }
  470. }
  471. },
  472. scrollTo : function(B, A) {
  473. this.stripWrap.scrollTo("left", B, A ? this.getScrollAnim() : false);
  474. if (!A) {
  475. this.updateScrollButtons()
  476. }
  477. },
  478. onWheel : function(D) {
  479. var E = D.getWheelDelta() * this.wheelIncrement * -1;
  480. D.stopEvent();
  481. var F = this.getScrollPos();
  482. var C = F + E;
  483. var A = this.getScrollWidth() - this.getScrollArea();
  484. var B = Math.max(0, Math.min(A, C));
  485. if (B != F) {
  486. this.scrollTo(B, false)
  487. }
  488. },
  489. onScrollRight : function() {
  490. var A = this.getScrollWidth() - this.getScrollArea();
  491. var C = this.getScrollPos();
  492. var B = Math.min(A, C + this.getScrollIncrement());
  493. if (B != C) {
  494. this.scrollTo(B, this.animScroll)
  495. }
  496. },
  497. onScrollLeft : function() {
  498. var B = this.getScrollPos();
  499. var A = Math.max(0, B - this.getScrollIncrement());
  500. if (A != B) {
  501. this.scrollTo(A, this.animScroll)
  502. }
  503. },
  504. updateScrollButtons : function() {
  505. var A = this.getScrollPos();
  506. this.scrollLeft[A == 0 ? "addClass" : "removeClass"]("x-tab-scroller-left-disabled");
  507. this.scrollRight[A >= (this.getScrollWidth() - this.getScrollArea())
  508. ? "addClass"
  509. : "removeClass"]("x-tab-scroller-right-disabled")
  510. }
  511. });
  512. Ext.reg("tabpanel", Ext.TabPanel);
  513. Ext.TabPanel.prototype.activate = Ext.TabPanel.prototype.setActiveTab;
  514. Ext.TabPanel.AccessStack = function() {
  515. var A = [];
  516. return {
  517. add : function(B) {
  518. A.push(B);
  519. if (A.length > 10) {
  520. A.shift()
  521. }
  522. },
  523. remove : function(E) {
  524. var D = [];
  525. for (var C = 0, B = A.length; C < B; C++) {
  526. if (A[C] != E) {
  527. D.push(A[C])
  528. }
  529. }
  530. A = D
  531. },
  532. next : function() {
  533. return A.pop()
  534. }
  535. }
  536. };