contabs.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. $(function () {
  2. function f(l) {
  3. var k = 0;
  4. $(l).each(function () {
  5. k += $(this).outerWidth(true)
  6. });
  7. return k
  8. }
  9. function g(n) {
  10. var o = f($(n).prevAll()), q = f($(n).nextAll());
  11. var l = f($(".content-tabs").children().not(".J_menuTabs"));
  12. var k = $(".content-tabs").outerWidth(true) - l;
  13. var p = 0;
  14. if ($(".page-tabs-content").outerWidth() < k) {
  15. p = 0
  16. } else {
  17. if (q <= (k - $(n).outerWidth(true) - $(n).next().outerWidth(true))) {
  18. if ((k - $(n).next().outerWidth(true)) > q) {
  19. p = o;
  20. var m = n;
  21. while ((p - $(m).outerWidth()) > ($(".page-tabs-content").outerWidth() - k)) {
  22. p -= $(m).prev().outerWidth();
  23. m = $(m).prev()
  24. }
  25. }
  26. } else {
  27. if (o > (k - $(n).outerWidth(true) - $(n).prev().outerWidth(true))) {
  28. p = o - $(n).prev().outerWidth(true)
  29. }
  30. }
  31. }
  32. $(".page-tabs-content").animate({marginLeft: 0 - p + "px"}, "fast")
  33. }
  34. function a() {
  35. var o = Math.abs(parseInt($(".page-tabs-content").css("margin-left")));
  36. var l = f($(".content-tabs").children().not(".J_menuTabs"));
  37. var k = $(".content-tabs").outerWidth(true) - l;
  38. var p = 0;
  39. if ($(".page-tabs-content").width() < k) {
  40. return false
  41. } else {
  42. var m = $(".J_menuTab:first");
  43. var n = 0;
  44. while ((n + $(m).outerWidth(true)) <= o) {
  45. n += $(m).outerWidth(true);
  46. m = $(m).next()
  47. }
  48. n = 0;
  49. if (f($(m).prevAll()) > k) {
  50. while ((n + $(m).outerWidth(true)) < (k) && m.length > 0) {
  51. n += $(m).outerWidth(true);
  52. m = $(m).prev()
  53. }
  54. p = f($(m).prevAll())
  55. }
  56. }
  57. $(".page-tabs-content").animate({marginLeft: 0 - p + "px"}, "fast")
  58. }
  59. function b() {
  60. var o = Math.abs(parseInt($(".page-tabs-content").css("margin-left")));
  61. var l = f($(".content-tabs").children().not(".J_menuTabs"));
  62. var k = $(".content-tabs").outerWidth(true) - l;
  63. var p = 0;
  64. if ($(".page-tabs-content").width() < k) {
  65. return false
  66. } else {
  67. var m = $(".J_menuTab:first");
  68. var n = 0;
  69. while ((n + $(m).outerWidth(true)) <= o) {
  70. n += $(m).outerWidth(true);
  71. m = $(m).next()
  72. }
  73. n = 0;
  74. while ((n + $(m).outerWidth(true)) < (k) && m.length > 0) {
  75. n += $(m).outerWidth(true);
  76. m = $(m).next()
  77. }
  78. p = f($(m).prevAll());
  79. if (p > 0) {
  80. $(".page-tabs-content").animate({marginLeft: 0 - p + "px"}, "fast")
  81. }
  82. }
  83. }
  84. $(".J_menuItem").each(function (k) {
  85. if (!$(this).attr("data-index")) {
  86. $(this).attr("data-index", k)
  87. }
  88. });
  89. function c() {
  90. var o = $(this).attr("href"), m = $(this).data("index"), l = $.trim($(this).text()), k = true;
  91. if (o == undefined || $.trim(o).length == 0) {
  92. return false
  93. }
  94. $(".J_menuTab").each(function () {
  95. if ($(this).data("id") == o) {
  96. if (!$(this).hasClass("active")) {
  97. $(this).addClass("active").siblings(".J_menuTab").removeClass("active");
  98. g(this);
  99. $(".J_mainContent .J_iframe").each(function () {
  100. if ($(this).data("id") == o) {
  101. $(this).show().siblings(".J_iframe").hide();
  102. return false
  103. }
  104. })
  105. }
  106. k = false;
  107. return false
  108. }
  109. });
  110. if (k) {
  111. var p = '<a href="javascript:;" class="active J_menuTab" data-id="' + o + '">' + l + ' <i class="fa fa-times-circle"></i></a>';
  112. $(".J_menuTab").removeClass("active");
  113. var n = '<iframe class="J_iframe" name="iframe' + m + '" width="100%" height="100%" src="' + o + '" frameborder="0" data-id="' + o + '" seamless></iframe>';
  114. $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(n);
  115. $(".J_menuTabs .page-tabs-content").append(p);
  116. g($(".J_menuTab.active"))
  117. }
  118. return false
  119. }
  120. $(".J_menuItem").on("click", c);
  121. function h() {
  122. var m = $(this).parents(".J_menuTab").data("id");
  123. var l = $(this).parents(".J_menuTab").width();
  124. if ($(this).parents(".J_menuTab").hasClass("active")) {
  125. if ($(this).parents(".J_menuTab").next(".J_menuTab").size()) {
  126. var k = $(this).parents(".J_menuTab").next(".J_menuTab:eq(0)").data("id");
  127. $(this).parents(".J_menuTab").next(".J_menuTab:eq(0)").addClass("active");
  128. $(".J_mainContent .J_iframe").each(function () {
  129. if ($(this).data("id") == k) {
  130. $(this).show().siblings(".J_iframe").hide();
  131. return false
  132. }
  133. });
  134. var n = parseInt($(".page-tabs-content").css("margin-left"));
  135. if (n < 0) {
  136. $(".page-tabs-content").animate({marginLeft: (n + l) + "px"}, "fast")
  137. }
  138. $(this).parents(".J_menuTab").remove();
  139. $(".J_mainContent .J_iframe").each(function () {
  140. if ($(this).data("id") == m) {
  141. $(this).remove();
  142. return false
  143. }
  144. })
  145. }
  146. if ($(this).parents(".J_menuTab").prev(".J_menuTab").size()) {
  147. var k = $(this).parents(".J_menuTab").prev(".J_menuTab:last").data("id");
  148. $(this).parents(".J_menuTab").prev(".J_menuTab:last").addClass("active");
  149. $(".J_mainContent .J_iframe").each(function () {
  150. if ($(this).data("id") == k) {
  151. $(this).show().siblings(".J_iframe").hide();
  152. return false
  153. }
  154. });
  155. $(this).parents(".J_menuTab").remove();
  156. $(".J_mainContent .J_iframe").each(function () {
  157. if ($(this).data("id") == m) {
  158. $(this).remove();
  159. return false
  160. }
  161. })
  162. }
  163. } else {
  164. $(this).parents(".J_menuTab").remove();
  165. $(".J_mainContent .J_iframe").each(function () {
  166. if ($(this).data("id") == m) {
  167. $(this).remove();
  168. return false
  169. }
  170. });
  171. g($(".J_menuTab.active"))
  172. }
  173. return false
  174. }
  175. $(".J_menuTabs").on("click", ".J_menuTab i", h);
  176. function i() {
  177. $(".page-tabs-content").children("[data-id]").not(":first").not(".active").each(function () {
  178. $('.J_iframe[data-id="' + $(this).data("id") + '"]').remove();
  179. $(this).remove()
  180. });
  181. $(".page-tabs-content").css("margin-left", "0")
  182. }
  183. $(".J_tabCloseOther").on("click", i);
  184. function j() {
  185. g($(".J_menuTab.active"))
  186. }
  187. $(".J_tabShowActive").on("click", j);
  188. function e() {
  189. if (!$(this).hasClass("active")) {
  190. var k = $(this).data("id");
  191. $(".J_mainContent .J_iframe").each(function () {
  192. if ($(this).data("id") == k) {
  193. $(this).show().siblings(".J_iframe").hide();
  194. return false
  195. }
  196. });
  197. $(this).addClass("active").siblings(".J_menuTab").removeClass("active");
  198. g(this)
  199. }
  200. }
  201. $(".J_menuTabs").on("click", ".J_menuTab", e);
  202. function d() {
  203. var l = $('.J_iframe[data-id="' + $(this).data("id") + '"]');
  204. var k = l.attr("src")
  205. }
  206. $(".J_menuTabs").on("dblclick", ".J_menuTab", d);
  207. $(".J_tabLeft").on("click", a);
  208. $(".J_tabRight").on("click", b);
  209. $(".J_tabCloseAll").on("click", function () {
  210. $(".page-tabs-content").children("[data-id]").not(":first").each(function () {
  211. $('.J_iframe[data-id="' + $(this).data("id") + '"]').remove();
  212. $(this).remove()
  213. });
  214. $(".page-tabs-content").children("[data-id]:first").each(function () {
  215. $('.J_iframe[data-id="' + $(this).data("id") + '"]').show();
  216. $(this).addClass("active")
  217. });
  218. $(".page-tabs-content").css("margin-left", "0")
  219. })
  220. });