You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
13 KiB

  1. (function ($) {
  2. $.nfinetab = {
  3. requestFullScreen: function () {
  4. var de = document.documentElement;
  5. if (de.requestFullscreen) {
  6. de.requestFullscreen();
  7. } else if (de.mozRequestFullScreen) {
  8. de.mozRequestFullScreen();
  9. } else if (de.webkitRequestFullScreen) {
  10. de.webkitRequestFullScreen();
  11. }
  12. },
  13. exitFullscreen: function () {
  14. var de = document;
  15. if (de.exitFullscreen) {
  16. de.exitFullscreen();
  17. } else if (de.mozCancelFullScreen) {
  18. de.mozCancelFullScreen();
  19. } else if (de.webkitCancelFullScreen) {
  20. de.webkitCancelFullScreen();
  21. }
  22. },
  23. refreshTab: function () {
  24. var currentId = $('.page-tabs-content').find('.active').attr('data-id');
  25. var target = $('.NFine_iframe[data-id="' + currentId + '"]');
  26. var url = target.attr('src');
  27. $.loading(true);
  28. target.attr('src', url).load(function () {
  29. $.loading(false);
  30. });
  31. },
  32. activeTab: function () {
  33. var currentId = $(this).data('id');
  34. if (!$(this).hasClass('active')) {
  35. $('.mainContent .NFine_iframe').each(function () {
  36. if ($(this).data('id') == currentId) {
  37. $(this).show().siblings('.NFine_iframe').hide();
  38. return false;
  39. }
  40. });
  41. $(this).addClass('active').siblings('.menuTab').removeClass('active');
  42. $.nfinetab.scrollToTab(this);
  43. }
  44. },
  45. closeOtherTabs: function () {
  46. $('.page-tabs-content').children("[data-id]").find('.fa-remove').parents('a').not(".active").each(function () {
  47. $('.NFine_iframe[data-id="' + $(this).data('id') + '"]').remove();
  48. $(this).remove();
  49. });
  50. $('.page-tabs-content').css("margin-left", "0");
  51. },
  52. closeTab: function () {
  53. var closeTabId = $(this).parents('.menuTab').data('id');
  54. var currentWidth = $(this).parents('.menuTab').width();
  55. if ($(this).parents('.menuTab').hasClass('active')) {
  56. if ($(this).parents('.menuTab').next('.menuTab').size()) {
  57. var activeId = $(this).parents('.menuTab').next('.menuTab:eq(0)').data('id');
  58. $(this).parents('.menuTab').next('.menuTab:eq(0)').addClass('active');
  59. $('.mainContent .NFine_iframe').each(function () {
  60. if ($(this).data('id') == activeId) {
  61. $(this).show().siblings('.NFine_iframe').hide();
  62. return false;
  63. }
  64. });
  65. var marginLeftVal = parseInt($('.page-tabs-content').css('margin-left'));
  66. if (marginLeftVal < 0) {
  67. $('.page-tabs-content').animate({
  68. marginLeft: (marginLeftVal + currentWidth) + 'px'
  69. }, "fast");
  70. }
  71. $(this).parents('.menuTab').remove();
  72. $('.mainContent .NFine_iframe').each(function () {
  73. if ($(this).data('id') == closeTabId) {
  74. $(this).remove();
  75. return false;
  76. }
  77. });
  78. }
  79. if ($(this).parents('.menuTab').prev('.menuTab').size()) {
  80. var activeId = $(this).parents('.menuTab').prev('.menuTab:last').data('id');
  81. $(this).parents('.menuTab').prev('.menuTab:last').addClass('active');
  82. $('.mainContent .NFine_iframe').each(function () {
  83. if ($(this).data('id') == activeId) {
  84. $(this).show().siblings('.NFine_iframe').hide();
  85. return false;
  86. }
  87. });
  88. $(this).parents('.menuTab').remove();
  89. $('.mainContent .NFine_iframe').each(function () {
  90. if ($(this).data('id') == closeTabId) {
  91. $(this).remove();
  92. return false;
  93. }
  94. });
  95. }
  96. }
  97. else {
  98. $(this).parents('.menuTab').remove();
  99. $('.mainContent .NFine_iframe').each(function () {
  100. if ($(this).data('id') == closeTabId) {
  101. $(this).remove();
  102. return false;
  103. }
  104. });
  105. $.nfinetab.scrollToTab($('.menuTab.active'));
  106. }
  107. return false;
  108. },
  109. addTab: function () {
  110. $("#header-nav>ul>li.open").removeClass("open");
  111. var dataId = $(this).attr('data-id');
  112. if (dataId != "") {
  113. top.$.cookie('nfine_currentmoduleid', dataId, { path: "/" });
  114. }
  115. var dataUrl = $(this).attr('href');
  116. var menuName = $.trim($(this).text());
  117. var flag = true;
  118. if (dataUrl == undefined || $.trim(dataUrl).length == 0) {
  119. return false;
  120. }
  121. $('.menuTab').each(function () {
  122. if ($(this).data('id') == dataUrl) {
  123. if (!$(this).hasClass('active')) {
  124. $(this).addClass('active').siblings('.menuTab').removeClass('active');
  125. $.nfinetab.scrollToTab(this);
  126. $('.mainContent .NFine_iframe').each(function () {
  127. if ($(this).data('id') == dataUrl) {
  128. $(this).show().siblings('.NFine_iframe').hide();
  129. return false;
  130. }
  131. });
  132. }
  133. flag = false;
  134. return false;
  135. }
  136. });
  137. if (flag) {
  138. var str = '<a href="javascript:;" class="active menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-remove"></i></a>';
  139. $('.menuTab').removeClass('active');
  140. var str1 = '<iframe class="NFine_iframe" id="iframe' + dataId + '" name="iframe' + dataId + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
  141. $('.mainContent').find('iframe.NFine_iframe').hide();
  142. $('.mainContent').append(str1);
  143. $.loading(true);
  144. $('.mainContent iframe:visible').load(function () {
  145. $.loading(false);
  146. });
  147. $('.menuTabs .page-tabs-content').append(str);
  148. $.nfinetab.scrollToTab($('.menuTab.active'));
  149. }
  150. return false;
  151. },
  152. scrollTabRight: function () {
  153. var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
  154. var tabOuterWidth = $.nfinetab.calSumWidth($(".content-tabs").children().not(".menuTabs"));
  155. var visibleWidth = $(".content-tabs").outerWidth(true) - tabOuterWidth;
  156. var scrollVal = 0;
  157. if ($(".page-tabs-content").width() < visibleWidth) {
  158. return false;
  159. } else {
  160. var tabElement = $(".menuTab:first");
  161. var offsetVal = 0;
  162. while ((offsetVal + $(tabElement).outerWidth(true)) <= marginLeftVal) {
  163. offsetVal += $(tabElement).outerWidth(true);
  164. tabElement = $(tabElement).next();
  165. }
  166. offsetVal = 0;
  167. while ((offsetVal + $(tabElement).outerWidth(true)) < (visibleWidth) && tabElement.length > 0) {
  168. offsetVal += $(tabElement).outerWidth(true);
  169. tabElement = $(tabElement).next();
  170. }
  171. scrollVal = $.nfinetab.calSumWidth($(tabElement).prevAll());
  172. if (scrollVal > 0) {
  173. $('.page-tabs-content').animate({
  174. marginLeft: 0 - scrollVal + 'px'
  175. }, "fast");
  176. }
  177. }
  178. },
  179. scrollTabLeft: function () {
  180. var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
  181. var tabOuterWidth = $.nfinetab.calSumWidth($(".content-tabs").children().not(".menuTabs"));
  182. var visibleWidth = $(".content-tabs").outerWidth(true) - tabOuterWidth;
  183. var scrollVal = 0;
  184. if ($(".page-tabs-content").width() < visibleWidth) {
  185. return false;
  186. } else {
  187. var tabElement = $(".menuTab:first");
  188. var offsetVal = 0;
  189. while ((offsetVal + $(tabElement).outerWidth(true)) <= marginLeftVal) {
  190. offsetVal += $(tabElement).outerWidth(true);
  191. tabElement = $(tabElement).next();
  192. }
  193. offsetVal = 0;
  194. if ($.nfinetab.calSumWidth($(tabElement).prevAll()) > visibleWidth) {
  195. while ((offsetVal + $(tabElement).outerWidth(true)) < (visibleWidth) && tabElement.length > 0) {
  196. offsetVal += $(tabElement).outerWidth(true);
  197. tabElement = $(tabElement).prev();
  198. }
  199. scrollVal = $.nfinetab.calSumWidth($(tabElement).prevAll());
  200. }
  201. }
  202. $('.page-tabs-content').animate({
  203. marginLeft: 0 - scrollVal + 'px'
  204. }, "fast");
  205. },
  206. scrollToTab: function (element) {
  207. var marginLeftVal = $.nfinetab.calSumWidth($(element).prevAll()), marginRightVal = $.nfinetab.calSumWidth($(element).nextAll());
  208. var tabOuterWidth = $.nfinetab.calSumWidth($(".content-tabs").children().not(".menuTabs"));
  209. var visibleWidth = $(".content-tabs").outerWidth(true) - tabOuterWidth;
  210. var scrollVal = 0;
  211. if ($(".page-tabs-content").outerWidth() < visibleWidth) {
  212. scrollVal = 0;
  213. } else if (marginRightVal <= (visibleWidth - $(element).outerWidth(true) - $(element).next().outerWidth(true))) {
  214. if ((visibleWidth - $(element).next().outerWidth(true)) > marginRightVal) {
  215. scrollVal = marginLeftVal;
  216. var tabElement = element;
  217. while ((scrollVal - $(tabElement).outerWidth()) > ($(".page-tabs-content").outerWidth() - visibleWidth)) {
  218. scrollVal -= $(tabElement).prev().outerWidth();
  219. tabElement = $(tabElement).prev();
  220. }
  221. }
  222. } else if (marginLeftVal > (visibleWidth - $(element).outerWidth(true) - $(element).prev().outerWidth(true))) {
  223. scrollVal = marginLeftVal - $(element).prev().outerWidth(true);
  224. }
  225. $('.page-tabs-content').animate({
  226. marginLeft: 0 - scrollVal + 'px'
  227. }, "fast");
  228. },
  229. calSumWidth: function (element) {
  230. var width = 0;
  231. $(element).each(function () {
  232. width += $(this).outerWidth(true);
  233. });
  234. return width;
  235. },
  236. init: function () {
  237. $('.menuItem').on('click', $.nfinetab.addTab);
  238. $('.menuTabs').on('click', '.menuTab i', $.nfinetab.closeTab);
  239. $('.menuTabs').on('click', '.menuTab', $.nfinetab.activeTab);
  240. $('.tabLeft').on('click', $.nfinetab.scrollTabLeft);
  241. $('.tabRight').on('click', $.nfinetab.scrollTabRight);
  242. $('.tabReload').on('click', $.nfinetab.refreshTab);
  243. $('.tabCloseCurrent').on('click', function () {
  244. $('.page-tabs-content').find('.active i').trigger("click");
  245. });
  246. $('.tabCloseAll').on('click', function () {
  247. $('.page-tabs-content').children("[data-id]").find('.fa-remove').each(function () {
  248. $('.NFine_iframe[data-id="' + $(this).data('id') + '"]').remove();
  249. $(this).parents('a').remove();
  250. });
  251. $('.page-tabs-content').children("[data-id]:first").each(function () {
  252. $('.NFine_iframe[data-id="' + $(this).data('id') + '"]').show();
  253. $(this).addClass("active");
  254. });
  255. $('.page-tabs-content').css("margin-left", "0");
  256. });
  257. $('.tabCloseOther').on('click', $.nfinetab.closeOtherTabs);
  258. $('.fullscreen').on('click', function () {
  259. if (!$(this).attr('fullscreen')) {
  260. $(this).attr('fullscreen', 'true');
  261. requestFullScreen();
  262. } else {
  263. $(this).removeAttr('fullscreen')
  264. exitFullscreen();
  265. }
  266. });
  267. }
  268. };
  269. $(function () {
  270. $.nfinetab.init();
  271. });
  272. })(jQuery);