7 lines
No EOL
7.9 KiB
JavaScript
7 lines
No EOL
7.9 KiB
JavaScript
/*!
|
|
* Angular Material Design
|
|
* https://github.com/angular/material
|
|
* @license MIT
|
|
* v0.10.1
|
|
*/
|
|
!function(t,e,i){"use strict";function s(){return{controller:n,template:r,compile:function(t,e){t.addClass("md-virtual-repeat-container").addClass(e.hasOwnProperty("mdOrientHorizontal")?"md-orient-horizontal":"md-orient-vertical")}}}function r(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 n(t,i,s,r){this.$scope=i,this.$element=s,this.$attrs=r,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.scroller=s[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],t(e.bind(this,this.updateSize)),r.ngHide&&i.$watch(r.ngHide,e.bind(this,function(i){i||t(e.bind(this,this.updateSize))}))}function o(t){return{controller:h,priority:1e3,require:["mdVirtualRepeat","^^mdVirtualRepeatContainer"],restrict:"A",terminal:!0,transclude:"element",compile:function(e,i){var s=i.mdVirtualRepeat,r=s.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)\s*$/),n=r[1],o=t(r[2]),h=i.mdExtraName&&t(i.mdExtraName);return function(t,e,i,s,r){s[0].link_(s[1],r,n,o,h)}}}}function h(t,e,i,s,r,n){this.$scope=t,this.$element=e,this.$attrs=i,this.$browser=s,this.$document=r,this.$$rAF=n,this.browserCheckUrlChange=s.$$checkUrlChange,this.newStartIndex=0,this.newEndIndex=0,this.startIndex=0,this.endIndex=0,this.itemSize=t.$eval(i.mdItemSize)||null,this.isFirstRender=!0,this.itemsLength=0,this.blocks={},this.pooledBlocks=[]}e.module("material.components.virtualRepeat",["material.core"]).directive("mdVirtualRepeatContainer",s).directive("mdVirtualRepeat",o);var l=1533917,a=3;n.$inject=["$$rAF","$scope","$element","$attrs"],n.prototype.register=function(t){this.repeater=t,e.element(this.scroller).on("scroll wheel touchmove touchend",e.bind(this,this.handleScroll_))},n.prototype.isHorizontal=function(){return this.horizontal},n.prototype.getSize=function(){return this.size},n.prototype.setSize_=function(t){this.size=t,this.$element[0].style[this.isHorizontal()?"width":"height"]=t+"px"},n.prototype.updateSize=function(){this.originalSize||(this.size=this.isHorizontal()?this.$element[0].clientWidth:this.$element[0].clientHeight,this.repeater&&this.repeater.containerUpdated())},n.prototype.getScrollSize=function(){return this.scrollSize},n.prototype.sizeScroller_=function(t){var e=this.isHorizontal()?"width":"height",i=this.isHorizontal()?"height":"width";if(l>t)this.sizer.style[e]=t+"px";else{this.sizer.innerHTML="",this.sizer.style[e]="auto",this.sizer.style[i]="auto";var s=Math.floor(t/l),r=document.createElement("div");r.style[e]=l+"px",r.style[i]="1px";for(var n=0;s>n;n++)this.sizer.appendChild(r.cloneNode(!1));r.style[e]=t-s*l+"px",this.sizer.appendChild(r)}},n.prototype.autoShrink_=function(t){var e=Math.max(t,this.autoShrinkMin*this.repeater.getItemSize());this.autoShrink&&e!==this.size&&(e<(this.originalSize||this.size)?(this.originalSize||(this.originalSize=this.size),this.setSize_(e)):this.originalSize&&(this.setSize_(this.originalSize),this.originalSize=null))},n.prototype.setScrollSize=function(t){this.scrollSize!==t&&(this.sizeScroller_(t),this.autoShrink_(t),this.scrollSize=t)},n.prototype.getScrollOffset=function(){return this.scrollOffset},n.prototype.scrollTo=function(t){this.scroller[this.isHorizontal()?"scrollLeft":"scrollTop"]=t,this.handleScroll_()},n.prototype.resetScroll=function(){this.scrollTo(0)},n.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)-a),s=this.isHorizontal()?"translateX(":"translateY(";s+=i*e+"px)",this.scrollOffset=t,this.offsetter.style.webkitTransform=s,this.offsetter.style.transform=s,this.repeater.containerUpdated()}}},o.$inject=["$parse"],h.$inject=["$scope","$element","$attrs","$browser","$document","$$rAF"],h.Block,h.prototype.link_=function(t,e,i,s,r){this.container=t,this.transclude=e,this.repeatName=i,this.repeatListExpression=s,this.extraName=r,this.sized=!1,this.container.register(this)},h.prototype.readItemSize_=function(){this.items=this.repeatListExpression(this.$scope),this.parentNode=this.$element[0].parentNode;var t=this.getBlock_(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.containerUpdated=function(){return this.itemSize?(this.sized||(this.items=this.repeatListExpression(this.$scope)),this.sized||(this.sized=!0,this.$scope.$watchCollection(this.repeatListExpression,e.bind(this,this.virtualRepeatUpdate_))),this.updateIndexes_(),void((this.newStartIndex!==this.startIndex||this.newEndIndex!==this.endIndex||this.container.getScrollOffset()>this.container.getScrollSize())&&this.virtualRepeatUpdate_(this.items,this.items))):void this.$$rAF(e.bind(this,this.readItemSize_))},h.prototype.getItemSize=function(){return this.itemSize},h.prototype.virtualRepeatUpdate_=function(t,i){var s=t?t.length:0,r=!1;if(s!==this.itemsLength&&(r=!0,this.itemsLength=s),this.items&&s<this.items.length&&0!==this.container.getScrollOffset())return this.items=t,void this.container.resetScroll();if(this.items=t,t!==i&&this.updateIndexes_(),this.parentNode=this.$element[0].parentNode,r&&this.container.setScrollSize(s*this.itemSize),this.isFirstRender){this.isFirstRender=!1;var n=this.$attrs.mdStartIndex?this.$scope.$eval(this.$attrs.mdStartIndex):0;this.container.scrollTo(n*this.itemSize)}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 o,h,l=[],a=[];for(o=this.newStartIndex;o<this.newEndIndex&&null==this.blocks[o];o++)h=this.getBlock_(o),this.updateBlock_(h,o),l.push(h);for(;null!=this.blocks[o];o++)this.updateBlock_(this.blocks[o],o);for(var c=o-1;o<this.newEndIndex;o++)h=this.getBlock_(o),this.updateBlock_(h,o),a.push(h);l.length&&this.parentNode.insertBefore(this.domFragmentFromBlocks_(l),this.$element[0].nextSibling),a.length&&this.parentNode.insertBefore(this.domFragmentFromBlocks_(a),this.blocks[c]&&this.blocks[c].element[0].nextSibling),this.$browser.$$checkUrlChange=this.browserCheckUrlChange,this.startIndex=this.newStartIndex,this.endIndex=this.newEndIndex},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.$scope.$root.$$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.newEndIndex=Math.min(t,this.newStartIndex+e+a),this.newStartIndex=Math.max(0,this.newStartIndex-a)}}(window,window.angular); |