/*!
* UI development toolkit for HTML5 (OpenUI5)
* (c) Copyright 2009-2018 SAP SE or an SAP affiliate company.
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
*/
sap.ui.define(['jquery.sap.global','./library','sap/ui/core/Control','sap/ui/core/delegate/ItemNavigation','sap/ui/core/Icon','sap/ui/core/delegate/ScrollEnablement','sap/ui/Device',"./TabStripRenderer"],function(q,l,C,I,a,S,D,T){"use strict";var b=C.extend("sap.ui.commons.TabStrip",{metadata:{library:"sap.ui.commons",properties:{height:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:null},width:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:null},selectedIndex:{type:"int",group:"Misc",defaultValue:0},enableTabReordering:{type:"boolean",group:"Behavior",defaultValue:false}},defaultAggregation:"tabs",aggregations:{tabs:{type:"sap.ui.commons.Tab",multiple:true,singularName:"tab"},_leftArrowControl:{type:"sap.ui.core.Icon",multiple:false,visibility:"hidden"},_rightArrowControl:{type:"sap.ui.core.Icon",multiple:false,visibility:"hidden"}},events:{select:{parameters:{index:{type:"int"}}},close:{parameters:{index:{type:"int"}}}}}});b.SCROLL_SIZE=320;b.ANIMATION_DURATION=sap.ui.getCore().getConfiguration().getAnimation()?200:0;b.SCROLL_ANIMATION_DURATION=sap.ui.getCore().getConfiguration().getAnimation()?500:0;b.prototype.init=function(){this._bInitialized=true;this._bRtl=sap.ui.getCore().getConfiguration().getRTL();this._iCurrentScrollLeft=0;this._iMaxOffsetLeft=null;this._scrollable=null;this._oScroller=new S(this,this.getId()+"-tablist",{horizontal:!this.getEnableTabReordering(),vertical:false,nonTouchScrolling:true});this.data("sap-ui-fastnavgroup","true",true);};b.prototype.setEnableTabReordering=function(v){this.setProperty("enableTabReordering",v,true);if(this._oScroller){this._oScroller.setHorizontal(!v);}return this;};b.prototype.onBeforeRendering=function(){if(this._sResizeListenerId){sap.ui.core.ResizeHandler.deregister(this._sResizeListenerId);this._sResizeListenerId=null;}};b.prototype.onAfterRendering=function(){if(this._oScroller){this._oScroller.setIconTabBar(this,q.proxy(this._updateScrollingAppearance,this),null);}this._initItemNavigation();this._updateScrollingAppearance();this._sResizeListenerId=sap.ui.core.ResizeHandler.register(this.getDomRef(),q.proxy(this._updateScrollingAppearance,this));var t=this.getTabs();var s=this.getSelectedIndex();var o=t[s];if(this._oScroller&&o&&o.$().length>0){if(!this._oScroller._$Container){this._oScroller.onAfterRendering();}this._scrollIntoView(o.$(),b.SCROLL_ANIMATION_DURATION);}for(var i=0;i-1){if((i!=this.getSelectedIndex())&&(this.getTabs()[i].getEnabled())){var o=this.getSelectedIndex();this.setProperty('selectedIndex',i,true);this.rerenderPanel(o,true);this.oItemNavigation.setSelectedIndex(this.oItemNavigation.getFocusedIndex());}}};b.prototype.onsapspace=function(e){var s=e.target;this.selectTabByDomRef(s);};b.prototype.onsapspacemodifiers=b.prototype.onsapspace;b.prototype.onsapenter=b.prototype.onsapspace;b.prototype.onsapentermodifiers=b.prototype.onsapspace;b.prototype.onsapdelete=function(e){var s=e.target;var i=this.getItemIndex(s);if(i>-1&&this.getTabs()[i].getClosable()){this.fireClose({index:i});}};b.prototype.getFocusDomRef=function(){return this.getDomRef().firstChild;};b.prototype.exit=function(){this._bInitialized=false;this._iCurrentScrollLeft=null;this._iMaxOffsetLeft=null;this._scrollable=null;if(this._oScroller){this._oScroller.destroy();this._oScroller=null;}if(this._sResizeListenerId){sap.ui.core.ResizeHandler.deregister(this._sResizeListenerId);this._sResizeListenerId=null;}if(this.oItemNavigation){this.removeDelegate(this.oItemNavigation);this.oItemNavigation.destroy();delete this.oItemNavigation;}};b.prototype.getItemIndex=function(d){var i;if(!d.id||d.id.search("-close")!=-1){var o=q(d).parentByAttribute("id");i=o.id;}else{i=d.id;}for(var c=0,t=this.getTabs();ci){this.setProperty('selectedIndex',this.getSelectedIndex()-1,true);}return this.removeAggregation("tabs",i,true);};b.prototype.setSelectedIndex=function(s){var o=this.getSelectedIndex();if(s==o){return this;}var t=this.getTabs();var c=t[s];if(this._oScroller&&c&&c.$().length>0){this._scrollIntoView(c.$(),b.SCROLL_ANIMATION_DURATION);}if(!c&&!this.getDomRef()){this.setProperty('selectedIndex',s,false);}else if(c&&c.getEnabled()&&c.getVisible()){this.setProperty('selectedIndex',s,true);if(this.getDomRef()&&!this.invalidated){this.rerenderPanel(o);if(this.oItemNavigation){var v=0;var d=-1;for(var i=0;i=0&&(!this.getTabs()[n].getEnabled()||!this.getTabs()[n].getVisible())){n--;}}this.setProperty('selectedIndex',n,true);this.rerenderPanel(c);}else{this.toggleTabClasses(this.getSelectedIndex(),this.getSelectedIndex());}this.iVisibleTabs--;var v=0;var d=[];var s=-1;var e=false;for(var i=0;i0){var r=sap.ui.getCore().createRenderManager();this.getRenderer().renderTabContents(r,c);r.flush($[0]);r.destroy();}var N=c.getId();$.attr("id",N+"-panel").attr("aria-labelledby",N);}else{$.empty();}O.setProperty("scrollTop",$.scrollTop(),true);O.setProperty("scrollLeft",$.scrollLeft(),true);if(c){c.onAfterRendering();}if(f){this.fireSelect({index:n});}});if(c){this.toggleTabClasses(o,n);}};b.prototype.toggleTabClasses=function(o,n){var t=this.getTabs();var c=t[o];if(c){c.$().toggleClass("sapUiTabSel sapUiTab").attr("aria-selected",false);}var B=o-1;while(B>=0&&!t[B].getVisible()){B--;}if(B>=0){t[B].$().removeClass("sapUiTabBeforeSel");}var A=o+1;while(A=0&&!t[B].getVisible()){B--;}if(B>=0){t[B].$().addClass("sapUiTabBeforeSel");}A=n+1;while(A-1){this.fireClose({index:i});}}};b.prototype.onmousedown=function(e){var L=!e.button;var i=this._isTouchMode(e);if(!i&&!L){return;}var s=e.target;var $=q(s);if(s.className=="sapUiTabClose"){e.preventDefault();e.stopPropagation();e.target=null;return;}this.selectTabByDomRef(s);if(!this.getEnableTabReordering()){return;}var c=$.closest(".sapUiTab, .sapUiTabSel, .sapUiTabDsbl");if(c.length===1){this._onTabMoveStart(c,e,i);}};b.prototype._onTabMoveStart=function($,e,i){this._disableTextSelection();e.preventDefault();$.zIndex(this.$().zIndex()+10);var c=this.getItemIndex(e.target);var t=this.getTabs()[c];var d=this.$().find('.sapUiTabBarCnt').children();var f=q.inArray($[0],d);var w=$.outerWidth();this._dragContext={index:f,tabIndex:c,isTouchMode:i,startX:i?e.originalEvent.targetTouches[0].pageX:e.pageX,tab:t,tabWidth:w,tabCenter:$.position().left+w/2};this._aMovedTabIndexes=[];var g=q(document);if(i){g.bind("touchmove",q.proxy(this._onTabMove,this));g.bind("touchend",q.proxy(this._onTabMoved,this));}else{g.mousemove(q.proxy(this._onTabMove,this));g.mouseup(q.proxy(this._onTabMoved,this));}};b.prototype._onTabMove=function(e){var d=this._dragContext;if(!d){return;}var c=this._isTouchMode(e);if(c){e.preventDefault();}var p=c?e.targetTouches[0].pageX:e.pageX;var f=p-d.startX;d.tab.$().css({left:f});var $,x,o,r,g=this.$().find('.sapUiTabBarCnt').children(),m=this._aMovedTabIndexes,R=sap.ui.getCore().getConfiguration().getRTL();for(var i=0;id.tabCenter+f;this._onAnimateTab($,d.tabWidth,r,m,i);}else{r=xd.index){$.insertAfter(q(f[n]));}else{$.insertBefore(q(f[n]));}f=this.$().find('.sapUiTabBarCnt').children();if(!d.tab.getEnabled()){for(var i=0;i0){c=0;}}else{c=s+d;if(c<0){c=0;}if(c>this._iMaxOffsetLeft){c=this._iMaxOffsetLeft;}}if(this._oScroller){this._oScroller.scrollTo(c,0,i);}this._iCurrentScrollLeft=c;};b.prototype._scrollIntoView=function($,d){var c=this.$("tablist"),t=c.innerWidth()-c.width(),i=$.outerWidth(true),e=$.position().left-t/2,s=this.getDomRef("scrollCont"),f=s.scrollLeft,g=this.$("scrollCont").width(),n=f;if(e<0||e>g-i){if(this._bRtl&&D.browser.firefox){if(e<0){n+=e+i-g;}else{n+=e;}}else{if(e<0){n+=e;}else{n+=e+i-g;}}this._iCurrentScrollLeft=n;if(this._oScroller){this._oScroller.scrollTo(n,0,d);}}};b.prototype._hasScrolling=function(){var t=this.getDomRef("tablist"),s=this.getDomRef("scrollCont"),c=t&&(t.scrollWidth>s.clientWidth);this.$().toggleClass("sapUiTabStripScrollable",c);return c;};b.prototype._updateScrollingAppearance=function(){var t=this.getDomRef("tablist"),s=this.getDomRef("scrollCont"),i,r,c,d=false,e=false;if(this._hasScrolling()&&t&&s){if(this._bRtl&&D.browser.firefox){i=-s.scrollLeft;}else{i=s.scrollLeft;}r=t.scrollWidth;c=s.clientWidth;if(Math.abs(r-c)===1){r=c;}if(i>0){d=true;}if((r>c)&&(i+c