| 139 | } |
| 140 | |
| 141 | function omtouchend() { |
| 142 | document.removeEventListener("touchmove", omtouchmove); |
| 143 | document.removeEventListener("touchend", omtouchend); |
| 144 | document.removeEventListener("touchcancel", omtouchend); |
| 145 | |
| 146 | // Only change tabs when a significant horizontal swipe is detected and not scrolling vertically |
| 147 | if (!isScrolling && Math.abs(moveX) > 100) { |
| 148 | const tabs = Array.from(el.get(".options").children).filter((child) => |
| 149 | child.matches("span"), |
| 150 | ); |
| 151 | const currentTab = el.get(".options>span.active"); |
| 152 | const direction = moveX > 0 ? 1 : -1; |
| 153 | const currentTabIndex = tabs.indexOf(currentTab); |
| 154 | const nextTabIndex = |
| 155 | (currentTabIndex + direction + tabs.length) % tabs.length; |
| 156 | const nextTab = tabs[nextTabIndex]; |
| 157 | nextTab.click(); |
| 158 | if (currentTab) currentTab.classList.remove("active"); |
| 159 | nextTab.classList.add("active"); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | function changeTab(e) { |
| 164 | const { target } = e; |