blob: 67e43a72fa91779978a75de1708886e0cef919f0 [file] [log] [blame]
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v1.0.0-master-19c11fd
*/
!function(t,e,i){"use strict";function s(){return{controller:o,template:n,compile:function(t,e){t.addClass("md-virtual-repeat-container").addClass(e.hasOwnProperty("mdOrientHorizontal")?"md-orient-horizontal":"md-orient-vertical")}}}function n(t){return'<div class="md-virtual-repeat-scroller"><div class="md-virtual-repeat-sizer"></div><div class="md-virtual-repeat-offsetter">'+t[0].innerHTML+"</div></div>"}function o(t,i,s,n,o,r,h,a){this.$rootScope=n,this.$scope=r,this.$element=h,this.$attrs=a,this.size=0,this.scrollSize=0,this.scrollOffset=0,this.horizontal=this.$attrs.hasOwnProperty("mdOrientHorizontal"),this.repeater=null,this.autoShrink=this.$attrs.hasOwnProperty("mdAutoShrink"),this.autoShrinkMin=parseInt(this.$attrs.mdAutoShrinkMin,10)||0,this.originalSize=null,this.offsetSize=parseInt(this.$attrs.mdOffsetSize,10)||0,this.$attrs.mdTopIndex?(this.bindTopIndex=s(this.$attrs.mdTopIndex),this.topIndex=this.bindTopIndex(this.$scope),e.isDefined(this.topIndex)||(this.topIndex=0,this.bindTopIndex.assign(this.$scope,0)),this.$scope.$watch(this.bindTopIndex,e.bind(this,function(t){t!==this.topIndex&&this.scrollToIndex(t)}))):this.topIndex=0,this.scroller=h[0].getElementsByClassName("md-virtual-repeat-scroller")[0],this.sizer=this.scroller.getElementsByClassName("md-virtual-repeat-sizer")[0],this.offsetter=this.scroller.getElementsByClassName("md-virtual-repeat-offsetter")[0];var l=e.bind(this,this.updateSize);t(e.bind(this,function(){l();var t=i.debounce(l,10,null,!1),s=e.element(o);this.size||t(),s.on("resize",t),r.$on("$destroy",function(){s.off("resize",t)}),r.$emit("$md-resize-enable"),r.$on("$md-resize",l)}))}function r(t){return{controller:h,priority:1e3,require:["mdVirtualRepeat","^^mdVirtualRepeatContainer"],restrict:"A",terminal:!0,transclude:"element",compile:function(e,i){var s=i.mdVirtualRepeat,n=s.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)\s*$/),o=n[1],r=t(n[2]),h=i.mdExtraName&&t(i.mdExtraName);return function(t,e,i,s,n){s[0].link_(s[1],n,o,r,h)}}}}function h(t,i,s,n,o,r,h){this.$scope=t,this.$element=i,this.$attrs=s,this.$browser=n,this.$document=o,this.$rootScope=r,this.$$rAF=h,this.onDemand=s.hasOwnProperty("mdOnDemand"),this.browserCheckUrlChange=n.$$checkUrlChange,this.newStartIndex=0,this.newEndIndex=0,this.newVisibleEnd=0,this.startIndex=0,this.endIndex=0,this.itemSize=t.$eval(s.mdItemSize)||null,this.isFirstRender=!0,this.isVirtualRepeatUpdating_=!1,this.itemsLength=0,this.unwatchItemSize_=e.noop,this.blocks={},this.pooledBlocks=[]}function a(t){if(!e.isFunction(t.getItemAtIndex)||!e.isFunction(t.getLength))throw Error("When md-on-demand is enabled, the Object passed to md-virtual-repeat must implement functions getItemAtIndex() and getLength() ");this.model=t}e.module("material.components.virtualRepeat",["material.core","material.components.showHide"]).directive("mdVirtualRepeatContainer",s).directive("mdVirtualRepeat",r);var l=1533917,d=3;o.$inject=["$$rAF","$mdUtil","$parse","$rootScope","$window","$scope","$element","$attrs"],o.prototype.register=function(t){this.repeater=t,e.element(this.scroller).on("scroll wheel touchmove touchend",e.bind(this,this.handleScroll_))},o.prototype.isHorizontal=function(){return this.horizontal},o.prototype.getSize=function(){return this.size},o.prototype.setSize_=function(t){this.size=t,this.$element[0].style[this.isHorizontal()?"width":"height"]=t+"px"},o.prototype.updateSize=function(){this.originalSize||(this.size=this.isHorizontal()?this.$element[0].clientWidth:this.$element[0].clientHeight,this.repeater&&this.repeater.containerUpdated())},o.prototype.getScrollSize=function(){return this.scrollSize},o.prototype.sizeScroller_=function(t){var e=this.isHorizontal()?"width":"height",i=this.isHorizontal()?"height":"width";if(this.sizer.innerHTML="",l>t)this.sizer.style[e]=t+"px";else{this.sizer.style[e]="auto",this.sizer.style[i]="auto";var s=Math.floor(t/l),n=document.createElement("div");n.style[e]=l+"px",n.style[i]="1px";for(var o=0;s>o;o++)this.sizer.appendChild(n.cloneNode(!1));n.style[e]=t-s*l+"px",this.sizer.appendChild(n)}},o.prototype.autoShrink_=function(t){var e=Math.max(t,this.autoShrinkMin*this.repeater.getItemSize());if(this.autoShrink&&e!==this.size){var i=this.originalSize||this.size;!i||i>e?(this.originalSize||(this.originalSize=this.size),this.setSize_(e)):this.originalSize&&(this.setSize_(this.originalSize),this.originalSize=null),this.repeater.containerUpdated()}},o.prototype.setScrollSize=function(t){var e=t+this.offsetSize;this.scrollSize!==e&&(this.sizeScroller_(e),this.autoShrink_(e),this.scrollSize=e)},o.prototype.getScrollOffset=function(){return this.scrollOffset},o.prototype.scrollTo=function(t){this.scroller[this.isHorizontal()?"scrollLeft":"scrollTop"]=t,this.handleScroll_()},o.prototype.scrollToIndex=function(t){var e=this.repeater.getItemSize(),i=this.repeater.itemsLength;t>i&&(t=i-1),this.scrollTo(e*t)},o.prototype.resetScroll=function(){this.scrollTo(0)},o.prototype.handleScroll_=function(){var t=this.isHorizontal()?this.scroller.scrollLeft:this.scroller.scrollTop;if(t!==this.scrollOffset){var e=this.repeater.getItemSize();if(e){var i=Math.max(0,Math.floor(t/e)-d),s=this.isHorizontal()?"translateX(":"translateY(";if(s+=i*e+"px)",this.scrollOffset=t,this.offsetter.style.webkitTransform=s,this.offsetter.style.transform=s,this.bindTopIndex){var n=Math.floor(t/e);n!==this.topIndex&&n<this.repeater.itemsLength&&(this.topIndex=n,this.bindTopIndex.assign(this.$scope,n),this.$rootScope.$$phase||this.$scope.$digest())}this.repeater.containerUpdated()}}},r.$inject=["$parse"],h.$inject=["$scope","$element","$attrs","$browser","$document","$rootScope","$$rAF"],h.Block,h.prototype.link_=function(t,i,s,n,o){this.container=t,this.transclude=i,this.repeatName=s,this.rawRepeatListExpression=n,this.extraName=o,this.sized=!1,this.repeatListExpression=e.bind(this,this.repeatListExpression_),this.container.register(this)},h.prototype.readItemSize_=function(){if(!this.itemSize){this.items=this.repeatListExpression(this.$scope),this.parentNode=this.$element[0].parentNode;var t=this.getBlock_(0);t.element[0].parentNode||this.parentNode.appendChild(t.element[0]),this.itemSize=t.element[0][this.container.isHorizontal()?"offsetWidth":"offsetHeight"]||null,this.blocks[0]=t,this.poolBlock_(0),this.itemSize&&this.containerUpdated()}},h.prototype.repeatListExpression_=function(t){var e=this.rawRepeatListExpression(t);if(this.onDemand&&e){var i=new a(e);return i.$$includeIndexes(this.newStartIndex,this.newVisibleEnd),i}return e},h.prototype.containerUpdated=function(){return this.itemSize?(this.sized||(this.items=this.repeatListExpression(this.$scope)),this.sized||(this.unwatchItemSize_(),this.sized=!0,this.$scope.$watchCollection(this.repeatListExpression,e.bind(this,function(t,e){this.isVirtualRepeatUpdating_||this.virtualRepeatUpdate_(t,e)}))),this.updateIndexes_(),void((this.newStartIndex!==this.startIndex||this.newEndIndex!==this.endIndex||this.container.getScrollOffset()>this.container.getScrollSize())&&(this.items instanceof a&&this.items.$$includeIndexes(this.newStartIndex,this.newEndIndex),this.virtualRepeatUpdate_(this.items,this.items)))):(this.unwatchItemSize_=this.$scope.$watchCollection(this.repeatListExpression,e.bind(this,function(t){t&&t.length&&this.$$rAF(e.bind(this,this.readItemSize_))})),void(this.$rootScope.$$phase||this.$scope.$digest()))},h.prototype.getItemSize=function(){return this.itemSize},h.prototype.virtualRepeatUpdate_=function(t,i){this.isVirtualRepeatUpdating_=!0;var s=t&&t.length||0,n=!1;if(this.items&&s<this.items.length&&0!==this.container.getScrollOffset())return this.items=t,void this.container.resetScroll();if(s!==this.itemsLength&&(n=!0,this.itemsLength=s),this.items=t,(t!==i||n)&&this.updateIndexes_(),this.parentNode=this.$element[0].parentNode,n&&this.container.setScrollSize(s*this.itemSize),this.isFirstRender){this.isFirstRender=!1;var o=this.$attrs.mdStartIndex?this.$scope.$eval(this.$attrs.mdStartIndex):this.container.topIndex;this.container.scrollToIndex(o)}Object.keys(this.blocks).forEach(function(t){var e=parseInt(t,10);(e<this.newStartIndex||e>=this.newEndIndex)&&this.poolBlock_(e)},this),this.$browser.$$checkUrlChange=e.noop;var r,h,a=[],l=[];for(r=this.newStartIndex;r<this.newEndIndex&&null==this.blocks[r];r++)h=this.getBlock_(r),this.updateBlock_(h,r),a.push(h);for(;null!=this.blocks[r];r++)this.updateBlock_(this.blocks[r],r);for(var d=r-1;r<this.newEndIndex;r++)h=this.getBlock_(r),this.updateBlock_(h,r),l.push(h);a.length&&this.parentNode.insertBefore(this.domFragmentFromBlocks_(a),this.$element[0].nextSibling),l.length&&this.parentNode.insertBefore(this.domFragmentFromBlocks_(l),this.blocks[d]&&this.blocks[d].element[0].nextSibling),this.$browser.$$checkUrlChange=this.browserCheckUrlChange,this.startIndex=this.newStartIndex,this.endIndex=this.newEndIndex,this.isVirtualRepeatUpdating_=!1},h.prototype.getBlock_=function(t){if(this.pooledBlocks.length)return this.pooledBlocks.pop();var i;return this.transclude(e.bind(this,function(e,s){i={element:e,"new":!0,scope:s},this.updateScope_(s,t),this.parentNode.appendChild(e[0])})),i},h.prototype.updateBlock_=function(t,e){this.blocks[e]=t,(t["new"]||t.scope.$index!==e||t.scope[this.repeatName]!==this.items[e])&&(t["new"]=!1,this.updateScope_(t.scope,e),this.$rootScope.$$phase||t.scope.$digest())},h.prototype.updateScope_=function(t,e){t.$index=e,t[this.repeatName]=this.items&&this.items[e],this.extraName&&(t[this.extraName(this.$scope)]=this.items[e])},h.prototype.poolBlock_=function(t){this.pooledBlocks.push(this.blocks[t]),this.parentNode.removeChild(this.blocks[t].element[0]),delete this.blocks[t]},h.prototype.domFragmentFromBlocks_=function(t){var e=this.$document[0].createDocumentFragment();return t.forEach(function(t){e.appendChild(t.element[0])}),e},h.prototype.updateIndexes_=function(){var t=this.items?this.items.length:0,e=Math.ceil(this.container.getSize()/this.itemSize);this.newStartIndex=Math.max(0,Math.min(t-e,Math.floor(this.container.getScrollOffset()/this.itemSize))),this.newVisibleEnd=this.newStartIndex+e+d,this.newEndIndex=Math.min(t,this.newVisibleEnd),this.newStartIndex=Math.max(0,this.newStartIndex-d)},a.prototype.$$includeIndexes=function(t,e){for(var i=t;e>i;i++)this.hasOwnProperty(i)||(this[i]=this.model.getItemAtIndex(i));this.length=this.model.getLength()}}(window,window.angular);