-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathui-listView.min.js
1 lines (1 loc) · 5.93 KB
/
ui-listView.min.js
1
!function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e){e.$root.$$phase||e.$digest()}var i=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),n=angular.module("ui-listView",["ui-listView.templates"]),l=/^\s*([a-zA-Z0-9]+)\s+(?:in)\s+([a-zA-Z0-9.]+(\s*[|].*$)?)/,r={preferredHeight:48},s=function(){function t(){e(this,t),this.cells=[],this.setOptions({})}return i(t,[{key:"setOptions",value:function(e){this._addDefaultOptions(e),e.listView=this,this.options=e,this.reload([])}},{key:"reload",value:function(e){e&&e!==this.originalItems||!this.originalItems?(this._clear(),this.originalItems=e):e=this.originalItems,this.rows.length>e.length&&(this.rows.length=e.length),this._rebuildRows(e)}},{key:"requestOffsetUpdate",value:function(e){var t=this,i=this._request;i||(this._request=i={startIndex:e},this._callDelegate("throttle",function(){t.updateRowOffsets(i.startIndex),t._request=null})),i.startIndex=Math.min(i.startIndex,e)}},{key:"updateRowOffsets",value:function(e){e=e||0;var t,i,n=this.rows,l=n[e].offset;for(i=e;i<n.length;i++)t=n[i],t.offset=l,t.cell&&this._callCellDelegate(t.cell,"offsetDidChange",t.offset),l+=t.height;this.layout()}},{key:"updateCells",value:function(){var e,t,i,n=this.visibleRange,l=n.index,r=l+n.length,s=this.rows,o=this.cells;l>1&&l%2&&l--,o.length=n.length;for(var a=l;r>a;a++)e=o[a-l],t=s[a],e||(e=o[a-l]={}),e.row&&(e.row.cell=null),t.cell=e,e.row=t,e.item=s[a].item,e.index=a,e.itemIdentifier=this._callDelegate("getItemIdentifier",e.item),i&&(t.offset=i.offset+i.height),this._callCellDelegate(e,"rowDidChange",t),i=t}},{key:"updateAnchor",value:function(){var e=this.getScrollHeight(),t=this._lastScrollHeight;return this.anchor&&(this.anchor.updateAnchor(e),this._lastScrollHeight=e),e!==t}},{key:"updateRange",value:function(){for(var e,t,i,n=this.viewport,l=n.offset,r=l+n.height,s=this.rows,o=this._findVisibleRowIndex(l,r),a=0,u=0,h=0,c=this.visibleRange;!t||!i;)t||(e=s[o-h],(!e||e.offset+e.height<l)&&(t=!0,a=Math.max(o-h,0))),i||(e=s[o+h],(!e||e.offset>r)&&(i=!0,u=Math.min(o+h,s.length))),h++;return this.options.range=this.visibleRange={index:a,length:u-a,total:s.length},c.index!==this.visibleRange.index||c.length!==this.visibleRange.length}},{key:"setViewport",value:function(e,t){return this.viewport={offset:e,height:t},this.layout()}},{key:"layout",value:function(){return this.updateAnchor(),this.updateRange()?(this.updateCells(),!0):!1}},{key:"getScrollHeight",value:function(){var e=this.rows.length,t=this.rows[e-1];return e?t.offset+t.height:0}},{key:"getCellStyle",value:function(e){return{top:e.row.offset+"px"}}},{key:"_addDefaultOptions",value:function(e){for(var t in r)!e.hasOwnProperty(t)&&r.hasOwnProperty(t)&&(e[t]=r[t])}},{key:"_clear",value:function(e){this.originalItems=[],(!this.rows||e)&&(this.rows=[]),this.cells=[],this.options.range=this.visibleRange={index:0,length:0}}},{key:"_rebuildRows",value:function(e){for(var t,i=0,n=this.rows,l=0;l<e.length;l++)t=n[l],t||(t=n[l]={height:this.options.preferredHeight,offset:i}),t.index=l,t.item=e[l],t.cell=null,i+=t.height}},{key:"_findVisibleRowIndex",value:function(e,t){var i,n=this.visibleRange,l=this.rows,r=Math.floor(n.index+n.length/2),s=0,o=l.length;for(r>l.length-1&&(r=Math.max(l.length-1,0));o>=s&&l[r];){if(i=l[r],i.offset+i.height<e)s=r+1;else{if(!(i.offset>t))break;o=r-1}r=s+Math.round((o-s)/2)}return r}},{key:"_callDelegate",value:function(e,t,i,n){var l=this.delegate;return l?l[e](t,i,n):void 0}},{key:"_callCellDelegate",value:function(e,t,i,n,l){var r=e.delegate;return r?r[t](i,n,l):void 0}}]),t}();n.controller("UIListView",s),n.directive("uiListView",["$rootScope","$parse",function(e,i){return{templateUrl:"ui-listView.tpl.html",replace:!0,transclude:!0,scope:{options:"="},controller:"UIListView",controllerAs:"listView",require:"uiListView",compile:function(e,n){var r=l.exec(n.uiListView);if(!r)throw Error('Invalid expression. It must be in the form "item in Array" ');var s=r[1],o=i(r[2]);return function(e,i,n,l){function r(){return l.setViewport(h.scrollTop,h.clientHeight)}function a(){r()&&(c=!0,t(e),c=!1),clearTimeout(f),f=setTimeout(function(){r(),t(e)})}function u(){t(e)}var h=i[0];l.delegate={getItemIdentifier:function(){return s},throttle:function(i){e.$$postDigest(i),t(e)}},e.$watch("options",function(e){l.setOptions(e||{})});var c,f;e.$watchCollection(function(){return c?l.originalItems:o(e.$parent)},function(e){l.reload(e),r()}),e.$watch(function(){return h.clientHeight+"-"+h.clientWidth},function(){r()}),h.addEventListener("scroll",a,!1),window.addEventListener("resize",u),e.$on("$destroy",function(){window.removeEventListener("resize",u)})}}}}]),angular.module("ui-listView.templates",[]).run(["$templateCache",function(e){e.put("ui-listView.tpl.html",'<div class="ui-list-view">\n <div class="ui-list-view-cell" ui-list-view-cell ng-repeat="cell in listView.cells">\n <div class="ui-list-view-cell-content"></div>\n </div>\n <div class="ui-list-view-anchor" ui-list-view-anchor></div>\n</div>')}]),angular.module("ui-listView").directive("uiListViewAnchor",function(){return{require:"^uiListView",link:function(e,t,i,n){var l=t[0];n.anchor={updateAnchor:function(e){l.style.top=e+"px"}}}}}),angular.module("ui-listView").directive("uiListViewCell",function(){return{require:"^uiListView",link:function(e,t,i,n,l){function r(e){u.style.top=e+"px"}function s(){var e=u.clientHeight,t=h.row;e!==t.height&&(t.height=e,n.requestOffsetUpdate(t.index))}function o(e){a[h.itemIdentifier]=e.item,a.$index=e.index,a.$first=0===e.index,a.$last=e.index===n.rows.length-1,r(e.offset)}var a,u=t[0],h=e.cell;l(function(e,i){var n=t.children();a=i,o(h.row),n.empty(),n.append(e)}),e.$watch(function(){return h.row.index+"-"+u.clientHeight},function(){s()}),h.delegate={rowDidChange:o,offsetDidChange:r},o(h.row)}}})}();