tab.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. var TabOption = function () {};
  2. TabOption.prototype = {
  3. containerId: "",
  4. pageid: "",
  5. cid: "",
  6. position: top,
  7. action: function (b, a) {}
  8. };
  9. var TabItemOption = function () {};
  10. TabItemOption.prototype = {
  11. id: "tab_",
  12. title: "",
  13. url: "",
  14. isClosed: true
  15. };
  16. function TabView(f) {
  17. var a = {
  18. current: null,
  19. current_index: 0,
  20. current_page: null
  21. };
  22. var g = new TabOption();
  23. $.extend(g, f);
  24. var b = g.position == "bottom" ? "_bottom" : "";
  25. this.id = g.cid;
  26. this.pid = g.pageid;
  27. this.tabs = null;
  28. this.tabContainer = null;
  29. var c = '<table class="tab_item" id="{0}" border="0" cellpadding="0" cellspacing="0"><tr><td class="tab_item1"></td><td class="tab_item2 tab_title">{1}</td><td class="tab_item2"><div class="tab_close"></div></td><td class="tab_item3"></td></tr></table>';
  30. var h = '<div class="benma_ui_tab" id="{0}"><div class="tab_hr"></div></div>';
  31. var i;
  32. if ($("#scrollContent").attr("childScrollContent") == "true") {
  33. i = '<iframe id="{0}" scrolling="no" allowTransparency="true" frameborder="0" width="100%" height="100%" src="{1}"></iframe>'
  34. } else {
  35. i = '<iframe id="{0}" style="overflow-x:hidden;" allowTransparency="true" frameborder="0" width="100%" height="100%" src="{1}"></iframe>'
  36. }
  37. if (g.position == "bottom") {
  38. c = '<table class="tab_item_bottom" id="{0}" border="0" cellpadding="0" cellspacing="0"><tr><td class="tab_item1_bottom"></td><td class="tab_item2_bottom tab_title">{1}</td><td class="tab_item2_bottom"><div class="tab_close tab_close_bottom"></div></td><td class="tab_item3_bottom"></td></tr></table>';
  39. h = '<div class="benma_ui_tab benma_ui_tab_bottom" id="{0}"><div class="tab_hr tab_hr_bottom"></div></div>'
  40. }
  41. $("#" + g.containerId).append(h.replace("{0}", this.id));
  42. function e(n) {
  43. var p = $(n);
  44. var m = $(p).find(".tab_item1" + b);
  45. var l = $(p).find(".tab_item2" + b);
  46. var k = $(p).find(".tab_item3" + b);
  47. if (a.current == null || a.current != this) {
  48. $(p).mouseover(function () {
  49. m.addClass("tab_item1_mouseover" + b);
  50. l.addClass("tab_item2_mouseover" + b);
  51. k.addClass("tab_item3_mouseover" + b)
  52. }).mouseout(function () {
  53. m.removeClass("tab_item1_mouseover" + b);
  54. l.removeClass("tab_item2_mouseover" + b);
  55. k.removeClass("tab_item3_mouseover" + b)
  56. }).click(function () {
  57. if (a.current != null) {
  58. $(a.current).find(".tab_item1" + b).removeClass("tab_item1_selected" + b);
  59. $(a.current).find(".tab_item2" + b).removeClass("tab_item2_selected" + b);
  60. $(a.current).find(".tab_item3" + b).removeClass("tab_item3_selected" + b);
  61. $(a.current).find(".tab_close").addClass("tab_close_noselected")
  62. }
  63. m.addClass("tab_item1_selected" + b);
  64. l.addClass("tab_item2_selected" + b);
  65. k.addClass("tab_item3_selected" + b);
  66. a.current = this;
  67. $(a.current).find(".tab_close").removeClass("tab_close_noselected");
  68. d($(this).attr("id"), false)
  69. });
  70. var o = $(p).find(".tab_close").mouseover(function () {
  71. $(this).addClass("tab_close_mouseover")
  72. }).mouseout(function () {
  73. $(this).removeClass("tab_close_mouseover")
  74. }).click(function () {
  75. j(p.attr("id"))
  76. })
  77. }
  78. }
  79. function d(l, k) {
  80. if (k) {}
  81. if (a.current_page) {
  82. a.current_page.hide()
  83. }
  84. a.current_page = $("#page_" + l);
  85. a.current_page.show();
  86. g.action($("#" + l), a.current_page);
  87. if(a.current_page.contents().find('.wrapselect')){
  88. var curNodeId = a.current_page.contents().find('.wrapselect').attr('id');
  89. $("#page_" + l).attr("src", a.current_page.attr("src"));
  90. setTimeout(function(){
  91. $("#page_" + l).contents().find('#'+curNodeId).trigger('click');
  92. }, 300);
  93. }else{
  94. $("#page_" + l).attr("src", a.current_page.attr("src"));
  95. }
  96. }
  97. function j(o) {
  98. var n = $("#page_" + o);
  99. var k = $("#" + o);
  100. if ($(a.current).attr("id") == k.attr("id")) {
  101. var l = k.next();
  102. if (l.attr("id")) {
  103. $("#" + l.attr("id")).trigger("click")
  104. } else {
  105. var m = k.prev();
  106. if (m.attr("id")) {
  107. $("#" + m.attr("id")).trigger("click")
  108. }
  109. }
  110. } else {}
  111. n.remove();
  112. k.remove()
  113. }
  114. this.init = function () {
  115. this.tabContainer = $("#" + this.id);
  116. this.tabs = this.tabContainer.find(".tab_item" + b);
  117. this.tabs.each(function () {
  118. e(this)
  119. })
  120. };
  121. this.add = function (n) {
  122. var m = new TabItemOption();
  123. $.extend(m, n);
  124. if ($("#" + m.id).length > 0) {
  125. this.activate(m.id);
  126. closeProgress()
  127. } else {
  128. if (m.title.length > 10) {
  129. m.title = m.title.substring(0, 10)
  130. }
  131. if (m.title.length < 4) {
  132. m.title = "&nbsp;&nbsp;" + m.title + "&nbsp;"
  133. }
  134. var k = i.replace("{0}", "page_" + m.id).replace("{1}", m.url);
  135. $("#" + this.pid).append(k);
  136. var l = c.replace("{0}", m.id).replace("{1}", m.title);
  137. this.tabContainer.append(l);
  138. e($("#" + m.id));
  139. if (!m.isClosed) {
  140. $($("#" + m.id)).find(".tab_close").hide()
  141. }
  142. this.activate(m.id)
  143. }
  144. };
  145. this.update = function (k) {
  146. var l = k.id;
  147. $("#" + l).find(".tab_title").html(k.title);
  148. $("#" + l).trigger("click");
  149. $("#page_" + l).attr("src", k.url)
  150. };
  151. this.activate = function (k) {
  152. $("#" + k).trigger("click")
  153. };
  154. this.close = function (k) {
  155. j(k)
  156. };
  157. this.init()
  158. };