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.

6 lines
16 KiB

7 years ago
  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v1.1.2-master-a9ba340
  6. */
  7. function MdTab(){function e(e,n,a,s){if(s){var r=s.getTabElementIndex(n),d=t(n,"md-tab-body").remove(),i=t(n,"md-tab-label").remove(),o=s.insertTab({scope:e,parent:e.$parent,index:r,element:n,template:d.html(),label:i.html()},r);e.select=e.select||angular.noop,e.deselect=e.deselect||angular.noop,e.$watch("active",function(e){e&&s.select(o.getIndex(),!0)}),e.$watch("disabled",function(){s.refreshIndex()}),e.$watch(function(){return s.getTabElementIndex(n)},function(e){o.index=e,s.updateTabOrder()}),e.$on("$destroy",function(){s.removeTab(o)})}}function t(e,t){for(var n=e[0].children,a=0,s=n.length;a<s;a++){var r=n[a];if(r.tagName===t.toUpperCase())return angular.element(r)}return angular.element()}return{require:"^?mdTabs",terminal:!0,compile:function(n,a){var s=t(n,"md-tab-label"),r=t(n,"md-tab-body");if(0===s.length&&(s=angular.element("<md-tab-label></md-tab-label>"),a.label?s.text(a.label):s.append(n.contents()),0===r.length)){var d=n.contents().detach();r=angular.element("<md-tab-body></md-tab-body>"),r.append(d)}return n.append(s),r.html()&&n.append(r),e},scope:{active:"=?mdActive",disabled:"=?ngDisabled",select:"&?mdOnSelect",deselect:"&?mdOnDeselect"}}}function MdTabItem(){return{require:"^?mdTabs",link:function(e,t,n,a){a&&a.attachRipple(e,t)}}}function MdTabLabel(){return{terminal:!0}}function MdTabScroll(e){return{restrict:"A",compile:function(t,n){var a=e(n.mdTabScroll,null,!0);return function(e,t){t.on("mousewheel",function(t){e.$apply(function(){a(e,{$event:t})})})}}}}function MdTabsController(e,t,n,a,s,r,d,i,o,c,l){function b(){g("stretchTabs",x),Y("focusIndex",y,le.selectedIndex||0),Y("offsetLeft",w,0),Y("hasContent",I,!1),Y("maxTabWidth",$,Q()),Y("shouldPaginate",C,!1),h("noInkBar",E),h("dynamicHeight",F),h("noPagination"),h("swipeContent"),h("noDisconnect"),h("autoselect"),h("noSelectClick"),h("centerTabs",v,!1),h("enableDisconnect"),le.scope=e,le.parent=e.$parent,le.tabs=[],le.lastSelectedIndex=null,le.hasFocus=!1,le.styleTabItemFocus=!1,le.shouldCenterTabs=z(),le.tabContentPrefix="tab-content-",m()}function m(){le.selectedIndex=le.selectedIndex||0,u(),p(),f(),c(t),r.nextTick(function(){me=q(),se(),ee(),re(),le.tabs[le.selectedIndex]&&le.tabs[le.selectedIndex].scope.select(),pe=!0,G()})}function u(){var e=i.$mdTabsTemplate,n=angular.element(t[0].querySelector("md-tab-data"));n.html(e),o(n.contents())(le.parent),delete i.$mdTabsTemplate}function f(){angular.element(n).on("resize",O),e.$on("$destroy",T)}function p(){e.$watch("$mdTabsCtrl.selectedIndex",k)}function g(e,t){var n=i.$normalize("md-"+e);t&&Y(e,t),i.$observe(n,function(t){le[e]=t})}function h(e,t){function n(t){le[e]="false"!==t}var a=i.$normalize("md-"+e);t&&Y(e,t),i.hasOwnProperty(a)&&n(i[a]),i.$observe(a,n)}function T(){fe=!0,angular.element(n).off("resize",O)}function x(e){var t=q();angular.element(t.wrapper).toggleClass("md-stretch-tabs",N()),re()}function v(e){le.shouldCenterTabs=z()}function $(e,t){if(e!==t){var n=q();angular.forEach(n.tabs,function(t){t.style.maxWidth=e+"px"}),r.nextTick(le.updateInkBarStyles)}}function C(e,t){e!==t&&(le.maxTabWidth=Q(),le.shouldCenterTabs=z(),r.nextTick(function(){le.maxTabWidth=Q(),ee(le.selectedIndex)}))}function I(e){t[e?"removeClass":"addClass"]("md-no-tab-content")}function w(t){var n=q(),s=le.shouldCenterTabs?"":"-"+t+"px";angular.element(n.paging).css(a.CSS.TRANSFORM,"translate3d("+s+", 0, 0)"),e.$broadcast("$mdTabsPaginationChanged")}function y(e,t){e!==t&&q().tabs[e]&&(ee(),Z())}function k(t,n){t!==n&&(le.selectedIndex=K(t),le.lastSelectedIndex=n,le.updateInkBarStyles(),se(),ee(t),e.$broadcast("$mdTabsChanged"),le.tabs[n]&&le.tabs[n].scope.deselect(),le.tabs[t]&&le.tabs[t].scope.select())}function S(e){var n=t[0].getElementsByTagName("md-tab");return Array.prototype.indexOf.call(n,e[0])}function M(){M.watcher||(M.watcher=e.$watch(function(){r.nextTick(function(){M.watcher&&t.prop("offsetParent")&&(M.watcher(),M.watcher=null,O())},!1)}))}function L(e){switch(e.keyCode){case a.KEY_CODE.LEFT_ARROW:e.preventDefault(),X(-1,!0);break;case a.KEY_CODE.RIGHT_ARROW:e.preventDefault(),X(1,!0);break;case a.KEY_CODE.SPACE:case a.KEY_CODE.ENTER:e.preventDefault(),be||P(le.focusIndex)}}function P(e,t){be||(le.focusIndex=le.selectedIndex=e),t&&le.noSelectClick||r.nextTick(function(){le.tabs[e].element.triggerHandler("click")},!1)}function W(e){le.shouldPaginate&&(e.preventDefault(),le.offsetLeft=ie(le.offsetLeft-e.wheelDelta))}function D(){var e,t,n=q(),a=n.canvas.clientWidth,s=a+le.offsetLeft;for(e=0;e<n.tabs.length&&(t=n.tabs[e],!(t.offsetLeft+t.offsetWidth>s));e++);a>t.offsetWidth?le.offsetLeft=ie(t.offsetLeft):le.offsetLeft=ie(t.offsetLeft+(t.offsetWidth-a+1))}function A(){var e,t,n=q();for(e=0;e<n.tabs.length&&(t=n.tabs[e],!(t.offsetLeft+t.offsetWidth>=le.offsetLeft));e++);n.canvas.clientWidth>t.offsetWidth?le.offsetLeft=ie(t.offsetLeft+t.offsetWidth-n.canvas.clientWidth):le.offsetLeft=ie(t.offsetLeft)}function O(){le.lastSelectedIndex=le.selectedIndex,le.offsetLeft=ie(le.offsetLeft),r.nextTick(function(){le.updateInkBarStyles(),G()})}function E(e){angular.element(q().inkBar).toggleClass("ng-hide",e)}function F(e){t.toggleClass("md-dynamic-height",e)}function B(e){if(!fe){var t=le.selectedIndex,n=le.tabs.splice(e.getIndex(),1)[0];ae(),le.selectedIndex===t&&(n.scope.deselect(),le.tabs[le.selectedIndex]&&le.tabs[le.selectedIndex].scope.select()),r.nextTick(function(){G(),le.offsetLeft=ie(le.offsetLeft)})}}function R(e,t){var n=pe,a={getIndex:function(){return le.tabs.indexOf(s)},isActive:function(){return this.getIndex()===le.selectedIndex},isLeft:function(){return this.getIndex()<le.selectedIndex},isRight:function(){return this.getIndex()>le.selectedIndex},shouldRender:function(){return!le.noDisconnect||this.isActive()},hasFocus:function(){return le.styleTabItemFocus&&le.hasFocus&&this.getIndex()===le.focusIndex},id:r.nextUid(),hasContent:!(!e.template||!e.template.trim())},s=angular.extend(a,e);return angular.isDefined(t)?le.tabs.splice(t,0,s):le.tabs.push(s),te(),ne(),r.nextTick(function(){G(),ce(s),n&&le.autoselect&&r.nextTick(function(){r.nextTick(function(){P(le.tabs.indexOf(s))})})}),s}function q(){var e={},n=t[0];return e.wrapper=n.querySelector("md-tabs-wrapper"),e.canvas=e.wrapper.querySelector("md-tabs-canvas"),e.paging=e.canvas.querySelector("md-pagination-wrapper"),e.inkBar=e.paging.querySelector("md-ink-bar"),e.contents=n.querySelectorAll("md-tabs-content-wrapper > md-tab-content"),e.tabs=e.paging.querySelectorAll("md-tab-item"),e.dummies=e.canvas.querySelectorAll("md-dummy-tab"),e}function H(){return le.offsetLeft>0}function _(){var e=q(),t=e.tabs[e.tabs.length-1];return t&&t.offsetLeft+t.offsetWidth>e.canvas.clientWidth+le.offsetLeft}function j(){var e=le.tabs[le.focusIndex];return e&&e.id?"tab-item-"+e.id:null}function N(){switch(le.stretchTabs){case"always":return!0;case"never":return!1;default:return!le.shouldPaginate&&n.matchMedia("(max-width: 600px)").matches}}function z(){return le.centerTabs&&!le.shouldPaginate}function U(){if(le.noPagination||!pe)return!1;var e=t.prop("clientWidth");return angular.forEach(q().dummies,function(t){e-=t.offsetWidth}),e<0}function K(e){if(e===-1)return-1;var t,n,a=Math.max(le.tabs.length-e,e);for(t=0;t<=a;t++){if(n=le.tabs[e+t],n&&n.scope.disabled!==!0)return n.getIndex();if(n=le.tabs[e-t],n&&n.scope.disabled!==!0)return n.getIndex()}return e}function Y(e,t,n){Object.defineProperty(le,e,{get:function(){return n},set:function(e){var a=n;n=e,t&&t(e,a)}})}function G(){le.maxTabWidth=Q(),le.shouldPaginate=U()}function J(e){var t=0;return angular.forEach(e,function(e){t+=Math.max(e.offsetWidth,e.getBoundingClientRect().width)}),Math.ceil(t)}function Q(){return t.prop("clientWidth")}function V(){var e=le.tabs[le.selectedIndex],t=le.tabs[le.focusIndex];le.tabs=le.tabs.sort(function(e,t){return e.index-t.index}),le.selectedIndex=le.tabs.indexOf(e),le.focusIndex=le.tabs.indexOf(t)}function X(e,t){var n,a=t?"focusIndex":"selectedIndex",s=le[a];for(n=s+e;le.tabs[n]&&le.tabs[n].scope.disabled;n+=e);le.tabs[n]&&(le[a]=n)}function Z(){le.styleTabItemFocus="keyboard"===l.getLastInteractionType(),q().dummies[le.focusIndex].focus()}function ee(e){var t=q();if(angular.isNumber(e)||(e=le.focusIndex),t.tabs[e]&&!le.shouldCenterTabs){var n=t.tabs[e],a=n.offsetLeft,s=n.offsetWidth+a;le.offsetLeft=Math.max(le.offsetLeft,ie(s-t.canvas.clientWidth+64)),le.offsetLeft=Math.min(le.offsetLeft,ie(a))}}function te(){ue.forEach(function(e){r.nextTick(e)}),ue=[]}function ne(){for(var e=!1,t=0;t<le.tabs.length;t++)if(le.tabs[t].hasContent){e=!0;break}le.hasContent=e}function ae(){le.selectedIndex=K(le.selectedIndex),le.focusIndex=K(le.focusIndex)}function se(){if(!le.dynamicHeight)return t.css("height","");if(!le.tabs.length)return ue.push(se);var e=q(),n=e.contents[le.selectedIndex],a=n?n.offsetHeight:0,s=e.wrapper.offsetHeight,i=a+s,o=t.prop("clientHeight");if(o!==i){"bottom"===t.attr("md-align-tabs")&&(o-=s,i-=s,void 0!==t.attr("md-border-bottom")&&++o),be=!0;var c={height:o+"px"},l={height:i+"px"};t.css(c),d(t,{from:c,to:l,easing:"cubic-bezier(0.35, 0, 0.25, 1)",duration:.5}).start().done(function(){t.css({transition:"none",height:""}),r.nextTick(function(){t.css("transition","")}),be=!1})}}function re(){var e=q();if(!e.tabs[le.selectedIndex])return void angular.element(e.inkBar).css({left:"auto",right:"auto"});if(!le.tabs.length)return ue.push(le.updateInkBarStyles);if(!t.prop("offsetParent"))return M();var n=le.selectedIndex,a=e.paging.offsetWidth,s=e.tabs[n],d=s.offsetLeft,i=a-d-s.offsetWidth;if(le.shouldCenterTabs){var o=J(e.tabs);a>o&&r.nextTick(re,!1)}de(),angular.element(e.inkBar).css({left:d+"px",right:i+"px"})}function de(){var e=q(),t=le.selectedIndex,n=le.lastSelectedIndex,a=angular.element(e.inkBar);angular.isNumber(n)&&a.toggleClass("md-left",t<n).toggleClass("md-right",t>n)}function ie(e){var t=q();if(!t.tabs.length||!le.shouldPaginate)return 0;var n=t.tabs[t.tabs.length-1],a=n.offsetLeft+n.offsetWidth;return e=Math.max(0,e),e=Math.min(a-t.canvas.clientWidth,e)}function oe(e,t){var n=q(),a={colorElement:angular.element(n.inkBar)};s.attach(e,t,a)}function ce(e){if(e.hasContent){var n=t[0].querySelectorAll('[md-tab-id="'+e.id+'"]');angular.element(n).attr("aria-controls",le.tabContentPrefix+e.id)}}var le=this,be=!1,me=q(),ue=[],fe=!1,pe=!1;le.$onInit=b,le.updatePagination=r.debounce(G,100),le.redirectFocus=Z,le.attachRipple=oe,le.insertTab=R,le.removeTab=B,le.select=P,le.scroll=W,le.nextPage=D,le.previousPage=A,le.keydown=L,le.canPageForward=_,le.canPageBack=H,le.refreshIndex=ae,le.incrementIndex=X,le.getTabElementIndex=S,le.updateInkBarStyles=r.debounce(re,100),le.updateTabOrder=r.debounce(V,100),le.getFocusedTabId=j,1===angular.version.major&&angular.version.minor<=4&&this.$onInit()}function MdTabs(e){return{scope:{selectedIndex:"=?mdSelected"},template:function(t,n){return n.$mdTabsTemplate=t.html(),'<md-tabs-wrapper> <md-tab-data></md-tab-data> <md-prev-button tabindex="-1" role="button" aria-label="Previous Page" aria-disabled="{{!$mdTabsCtrl.canPageBack()}}" ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageBack() }" ng-if="$mdTabsCtrl.shouldPaginate" ng-click="$mdTabsCtrl.previousPage()"> <md-icon md-svg-src="'+e.mdTabsArrow+'"></md-icon> </md-prev-button> <md-next-button tabindex="-1" role="button" aria-label="Next Page" aria-disabled="{{!$mdTabsCtrl.canPageForward()}}" ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageForward() }" ng-if="$mdTabsCtrl.shouldPaginate" ng-click="$mdTabsCtrl.nextPage()"> <md-icon md-svg-src="'+e.mdTabsArrow+'"></md-icon> </md-next-button> <md-tabs-canvas tabindex="{{ $mdTabsCtrl.hasFocus ? -1 : 0 }}" aria-activedescendant="{{$mdTabsCtrl.getFocusedTabId()}}" ng-focus="$mdTabsCtrl.redirectFocus()" ng-class="{ \'md-paginated\': $mdTabsCtrl.shouldPaginate, \'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs }" ng-keydown="$mdTabsCtrl.keydown($event)" role="tablist"> <md-pagination-wrapper ng-class="{ \'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs }" md-tab-scroll="$mdTabsCtrl.scroll($event)"> <md-tab-item tabindex="-1" class="md-tab" ng-repeat="tab in $mdTabsCtrl.tabs" role="tab" md-tab-id="{{::tab.id}}"aria-selected="{{tab.isActive()}}" aria-disabled="{{tab.scope.disabled || \'false\'}}" ng-click="$mdTabsCtrl.select(tab.getIndex())" ng-class="{ \'md-active\': tab.isActive(), \'md-focused\': tab.hasFocus(), \'md-disabled\': tab.scope.disabled }" ng-disabled="tab.scope.disabled" md-swipe-left="$mdTabsCtrl.nextPage()" md-swipe-right="$mdTabsCtrl.previousPage()" md-tabs-template="::tab.label" md-scope="::tab.parent"></md-tab-item> <md-ink-bar></md-ink-bar> </md-pagination-wrapper> <md-tabs-dummy-wrapper class="md-visually-hidden md-dummy-wrapper"> <md-dummy-tab class="md-tab" tabindex="-1" id="tab-item-{{::tab.id}}" md-tab-id="{{::tab.id}}"aria-selected="{{tab.isActive()}}" aria-disabled="{{tab.scope.disabled || \'false\'}}" ng-focus="$mdTabsCtrl.hasFocus = true" ng-blur="$mdTabsCtrl.hasFocus = false" ng-repeat="tab in $mdTabsCtrl.tabs" md-tabs-template="::tab.label" md-scope="::tab.parent"></md-dummy-tab> </md-tabs-dummy-wrapper> </md-tabs-canvas> </md-tabs-wrapper> <md-tabs-content-wrapper ng-show="$mdTabsCtrl.hasContent && $mdTabsCtrl.selectedIndex >= 0" class="_md"> <md-tab-content id="{{:: $mdTabsCtrl.tabContentPrefix + tab.id}}" class="_md" role="tabpanel" aria-labelledby="tab-item-{{::tab.id}}" md-swipe-left="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(1)" md-swipe-right="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(-1)" ng-if="tab.hasContent" ng-repeat="(index, tab) in $mdTabsCtrl.tabs" ng-class="{ \'md-no-transition\': $mdTabsCtrl.lastSelectedIndex == null, \'md-active\': tab.isActive(), \'md-left\': tab.isLeft(), \'md-right\': tab.isRight(), \'md-no-scroll\': $mdTabsCtrl.dynamicHeight }"> <div md-tabs-template="::tab.template" md-connected-if="tab.isActive()" md-scope="::tab.parent" ng-if="$mdTabsCtrl.enableDisconnect || tab.shouldRender()"></div> </md-tab-content> </md-tabs-content-wrapper>'},controller:"MdTabsController",controllerAs:"$mdTabsCtrl",bindToController:!0}}function MdTabsDummyWrapper(e,t){return{require:"^?mdTabs",link:function(n,a,s,r){if(r){var d,i,o=function(){r.updatePagination(),r.updateInkBarStyles()};if("MutationObserver"in t){var c={childList:!0,subtree:!0,characterData:!0};d=new MutationObserver(o),d.observe(a[0],c),i=d.disconnect.bind(d)}else{var l=e.debounce(o,15,null,!1);a.on("DOMSubtreeModified",l),i=a.off.bind(a,"DOMSubtreeModified",l)}n.$on("$destroy",function(){i()})}}}}function MdTabsTemplate(e,t){function n(n,a,s,r){function d(){n.$watch("connected",function(e){e===!1?i():o()}),n.$on("$destroy",o)}function i(){r.enableDisconnect&&t.disconnectScope(c)}function o(){r.enableDisconnect&&t.reconnectScope(c)}if(r){var c=r.enableDisconnect?n.compileScope.$new():n.compileScope;return a.html(n.template),e(a.contents())(c),t.nextTick(d)}}return{restrict:"A",link:n,scope:{template:"=mdTabsTemplate",connected:"=?mdConnectedIf",compileScope:"=mdScope"},require:"^?mdTabs"}}goog.provide("ngmaterial.components.tabs"),goog.require("ngmaterial.components.icon"),goog.require("ngmaterial.core"),angular.module("material.components.tabs",["material.core","material.components.icon"]),angular.module("material.components.tabs").directive("mdTab",MdTab),angular.module("material.components.tabs").directive("mdTabItem",MdTabItem),angular.module("material.components.tabs").directive("mdTabLabel",MdTabLabel),MdTabScroll.$inject=["$parse"],angular.module("material.components.tabs").directive("mdTabScroll",MdTabScroll),MdTabsController.$inject=["$scope","$element","$window","$mdConstant","$mdTabInkRipple","$mdUtil","$animateCss","$attrs","$compile","$mdTheming","$mdInteraction"],angular.module("material.components.tabs").controller("MdTabsController",MdTabsController),MdTabs.$inject=["$$mdSvgRegistry"],angular.module("material.components.tabs").directive("mdTabs",MdTabs),MdTabsDummyWrapper.$inject=["$mdUtil","$window"],angular.module("material.components.tabs").directive("mdTabsDummyWrapper",MdTabsDummyWrapper),MdTabsTemplate.$inject=["$compile","$mdUtil"],angular.module("material.components.tabs").directive("mdTabsTemplate",MdTabsTemplate),ngmaterial.components.tabs=angular.module("material.components.tabs");