-
Notifications
You must be signed in to change notification settings - Fork 4
/
tabs-swipable.min.js
1 lines (1 loc) · 2.64 KB
/
tabs-swipable.min.js
1
angular.module("ionic").directive("tabsSwipable",["$ionicGesture",function(e){return{restrict:"A",require:"ionTabs",link:function(t,n,a,i){var r={},s=!1;void 0!=a.tabsSwipableLoop&&(-1==["true","false"].indexOf(a.tabsSwipableLoop)?console.error("tabsSwipable: tabsSwipableLoop value should be true or false, '"+a.tabsSwipableLoop+"' is given."):s="true"==a.tabsSwipableLoop);var o=function(e){document.contains(document.getElementById("ionTabsAnimatedStyle"))&&document.getElementById("ionTabsAnimatedStyle").remove();for(var n=0;n<i.tabs.length;n++)ionView=angular.element(document.querySelector("ion-nav-view[name='"+i.tabs[n].navViewName+"']")),ionView.css({left:"initial"}),n!=i.selectedIndex()&&ionView.attr("nav-view","cached");if(e.gesture.distance>window.screen.width/1.6||e.gesture.distance/(e.gesture.timeStamp-e.gesture.startEvent.timeStamp)>.1){var a=i.selectedIndex();"right"==e.gesture.direction&&a--,"left"==e.gesture.direction&&a++,a>=0&&a<i.tabs.length?a!=i.selectedIndex()&&t.$apply(i.select(a)):s&&(-1==a?a!=i.selectedIndex()&&t.$apply(i.select(i.tabs.length-1)):a==i.tabs.length&&a!=i.selectedIndex()&&t.$apply(i.select(0)))}},l=function(e){var t=nextTarget=i.selectedIndex(),n=angular.element(document.querySelector("ion-nav-view[name='"+i.tabs[t].navViewName+"']")),a=null,r=document.querySelector("[tabs-swipable] .tabs .tab-item.tab-item-active").offsetWidth,o=document.getElementById("ionTabsAnimatedStyle")||document.createElement("style");if(o.setAttribute("id","ionTabsAnimatedStyle"),o.innerHTML=".tab-item-active::after{position: absolute;width: "+r+"px;}",o.innerHTML+=".tab-item-active::after{transform: translateX( "+-e.gesture.deltaX/5+"px);}",!(t<0)&&("right"==e.gesture.direction&&nextTarget--,"left"==e.gesture.direction&&nextTarget++,nextTarget>=0&&nextTarget<i.tabs.length?a=angular.element(document.querySelector("ion-nav-view[name='"+i.tabs[nextTarget].navViewName+"']")):s&&(-1==nextTarget?a=angular.element(document.querySelector("ion-nav-view[name='"+i.tabs[i.tabs.length-1].navViewName+"']")):nextTarget==i.tabs.length&&(a=angular.element(document.querySelector("ion-nav-view[name='"+i.tabs[0].navViewName+"']")))),s||"right"==e.gesture.direction&&nextTarget>=0||"left"==e.gesture.direction&&nextTarget<i.tabs.length)){var l={};l.left=e.gesture.deltaX+"px",n.css(l),"left"==e.gesture.direction&&(l.left=window.screen.width+e.gesture.deltaX+"px"),"right"==e.gesture.direction&&(l.left=e.gesture.deltaX-window.screen.width+"px"),a.attr("nav-view","active"),a.css(l),document.getElementsByTagName("head")[0].append(o)}};r.drag=e.on("drag",l,n),r.dragend=e.on("dragend",o,n),t.$on("$destroy",function(){e.off(r.drag,"drag",l),e.off(r.dragend,"dragend",o)})}}}]);