bongzilla

Untitled

Mar 22nd, 2021
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $( document ).ready(function() {
  2. var currentTabIndex = 1;
  3.  
  4. $(".b-tabs__link").on("click", function() {
  5. currentTabIndex = $(this).data("w-tab").slice(-1);
  6. });
  7.  
  8. $(".b-sider__arrow-left").on("click", function(e) {
  9. const tabsDiv = $(this).parent().parent().parent().siblings(".b-tabs__menu");
  10.  
  11. const tabIndex = Number($(this).parent().parent().data("w-tab").slice(-1));
  12. const tabsLength = $(this).closest(".b-tabs__content").find(".b-tabs__pane").length;
  13.  
  14. let prevTabIndex = tabIndex - 1;
  15. console.log("prevTabIndex", prevTabIndex);
  16.  
  17. if(prevTabIndex < 1) prevTabIndex = 5
  18.  
  19. console.log("prevTabIndex after", prevTabIndex);
  20.  
  21. changeTabPrev($(this), prevTabIndex, tabsLength)
  22. })
  23.  
  24. $(".b-arrow-coral").on("click", function(e) {
  25. const tabsDiv = $(this).parent().parent().parent().siblings(".b-tabs__menu");
  26.  
  27. const tabIndex = Number($(this).parent().parent().data("w-tab").slice(-1));
  28. const tabsLength = $(this).closest(".b-tabs__content").find(".b-tabs__pane").length;
  29.  
  30. let nextTabIndex = tabIndex + 1;
  31.  
  32. if(nextTabIndex > tabsLength) nextTabIndex = 1
  33.  
  34. changeTab($(this), nextTabIndex, tabsLength)
  35. })
  36.  
  37. function changeTab(ctx, currentTabIndex, tabsLength) {
  38. changeSelectedTab(currentTabIndex);
  39. const tabsDiv = ctx.parent().parent().parent().siblings(".b-tabs__menu");
  40.  
  41. const currentTabPane = ctx.parent().parent();
  42. const firstPane = ctx.parent().parent().parent().find(".b-tabs__pane").eq(0);
  43. const nextPane = ctx.parent().parent().next();
  44.  
  45. const nextTabPane = currentTabIndex !== 1
  46. ? changeToAnother()
  47. : changeToFirst()
  48.  
  49. function changeToFirst() {
  50. firstPane.css({"opacity": 1, "transition": "opacity 0.3s ease 0s, opacity 300ms ease 0s"}).addClass("w--tab-active");
  51. }
  52.  
  53. function changeToAnother() {
  54. nextPane.css({"opacity": 1, "transition": "opacity 0.3s ease 0s, opacity 300ms ease 0s"}).addClass("w--tab-active")
  55. currentTabPane.removeClass("w--tab-active").removeAttr("style");
  56. }
  57.  
  58. }
  59.  
  60. function changeTabPrev(ctx, currentTabIndex, tabsLength) {
  61. changeSelectedTab(currentTabIndex);
  62. const tabsDiv = ctx.parent().parent().parent().siblings(".b-tabs__menu");
  63. // currentTabIndex = currentTabIndex + 1
  64.  
  65. console.log("currentTabIndex", currentTabIndex);
  66. console.log("===", currentTabIndex === tabsLength);
  67.  
  68. const currentTabPane = ctx.parent().parent();
  69. const lastPane = ctx.parent().parent().parent().find(".b-tabs__pane").eq(tabsLength - 1);
  70. const nextPane = ctx.parent().parent().prev();
  71.  
  72. console.log("lastPane", lastPane);
  73.  
  74. const nextTabPane = currentTabIndex !== tabsLength
  75. ? changeToAnother()
  76. : changeToLast()
  77.  
  78. function changeToLast() {
  79. currentTabPane.removeClass("w--tab-active").removeAttr("style");
  80. lastPane.css({"opacity": 1, "transition": "opacity 0.3s ease 0s, opacity 300ms ease 0s"}).addClass("w--tab-active");
  81. }
  82.  
  83. function changeToAnother() {
  84. nextPane.css({"opacity": 1, "transition": "opacity 0.3s ease 0s, opacity 300ms ease 0s"}).addClass("w--tab-active")
  85. currentTabPane.removeClass("w--tab-active").removeAttr("style");
  86. }
  87. }
  88.  
  89. function changeSelectedTab(idx) {
  90. // console.log("currentTabIndex from changeSelectedTab", currentTabIndex);
  91. $(".b-tabs__menu .w--current").removeClass("w--current");
  92. $(".b-tabs__menu").find(".b-tabs__link").eq(idx - 1).addClass("w--current");
  93. }
  94. })
RAW Paste Data