open-consul/ui/javascripts/libs/list-view.min.js

5 lines
16 KiB
JavaScript

// Last commit: 0bff5bc (2014-04-26 12:06:07 -0500)
// Copyright: ©2012-2013 Erik Bryn, Yapp Inc., and contributors.
!function(){function e(e,t){return e&&t&&e.x===t.x&&e.y===t.y}function t(){var t,n,r;Ember.instrument("view.updateContext.positionElement",this,function(){t=i(this,"element"),n=this.position,r=this._position,n&&t&&(e(n,r)||(Ember.run.schedule("render",this,this._parentView.applyTransform,t,n.x,n.y),this._position=n))},this)}var i=Ember.get;Ember.set,Ember.ListItemViewMixin=Ember.Mixin.create({init:function(){this._super(),this.one("didInsertElement",t)},classNames:["ember-list-item-view"],_position:null,updatePosition:function(e){this.position=e,this._positionElement()},_positionElement:t})}(),function(){function e(e){e.willInsertElement&&e.willInsertElement()}function t(e){e.didInsertElement&&e.didInsertElement()}function i(){var i,o,l,h;i=n(this,"element"),i&&(l=n(this,"context"),this.triggerRecursively("willClearRender"),this.lengthAfterRender>this.lengthBeforeRender&&(this.clearRenderedChildren(),this._childViews.length=this.lengthBeforeRender),l?(o=Ember.RenderBuffer(),o=this.renderToBuffer(o),h=this._childViews.length>0,h&&this.invokeRecursively(e,!1),i.innerHTML=o.innerString?o.innerString():s(o),r(this,"element",i),this.transitionTo("inDOM"),h&&this.invokeRecursively(t,!1)):i.innerHTML="")}var n=Ember.get,r=Ember.set,s=function(e){var t=[],i=e.childBuffers;return Ember.ArrayPolyfills.forEach.call(i,function(e){var i="string"==typeof e;i?t.push(e):e.array(t)}),t.join("")};Ember.ListItemView=Ember.View.extend(Ember.ListItemViewMixin,{updateContext:function(e){var t=n(this,"context");Ember.instrument("view.updateContext.render",this,function(){t!==e&&(r(this,"context",e),e&&e.isController&&r(this,"controller",e))},this)},rerender:function(){Ember.run.scheduleOnce("render",this,i)},_contextDidChange:Ember.observer(i,"context","controller")})}(),function(){var e=Ember.get,t=Ember.set;Ember.ReusableListItemView=Ember.View.extend(Ember.ListItemViewMixin,{init:function(){this._super();var e=Ember.ObjectProxy.create();this.set("context",e),this._proxyContext=e},isVisible:Ember.computed("context.content",function(){return!!this.get("context.content")}),updateContext:function(i){var n=e(this._proxyContext,"content");n!==i&&("inDOM"===this.state&&this.prepareForReuse(i),t(this._proxyContext,"content",i),i&&i.isController&&t(this,"controller",i))},prepareForReuse:Ember.K})}(),function(){function e(e){if(e in i)return e;for(var t=e.charAt(0).toUpperCase()+e.slice(1),r=0;r<n.length;r++){var s=n[r]+t;if(s in i)return s}return null}var t=document.createElement("div"),i=t.style,n=["Webkit","Moz","O","ms"],r=e("transform"),s=e("perspective"),o=null!==r,l=null!==s;Ember.ListViewHelper={transformProp:r,applyTransform:function(){return o?function(e,t,i){e.style[r]="translate("+t+"px, "+i+"px)"}:function(e,t,i){e.style.top=i+"px",e.style.left=t+"px"}}(),apply3DTransform:function(){return l?function(e,t,i){e.style[r]="translate3d("+t+"px, "+i+"px, 0)"}:o?function(e,t,i){e.style[r]="translate("+t+"px, "+i+"px)"}:function(e,t,i){e.style.top=i+"px",e.style.left=t+"px"}}()}}(),function(){function e(){var e=l(this,"content");e&&e.addArrayObserver(this)}function t(e){this.removeObject(e),e.destroy()}function i(){Ember.run.once(this,"_syncChildViews")}function n(e,t){return l(e,"contentIndex")-l(t,"contentIndex")}function r(){Ember.View.notifyMutationListeners&&Ember.run.once(Ember.View,"notifyMutationListeners")}function s(){var e=l(this,"emptyView");e&&e instanceof Ember.View&&e.removeFromParent()}function o(){var e=l(this,"emptyView");e&&("string"==typeof e&&(e=l(e)||e),e=this.createChildView(e),h(this,"emptyView",e),Ember.CoreView.detect(e)&&(this._createdEmptyView=e),this.unshiftObject(e))}var l=Ember.get,h=Ember.set,c=Math.min,a=Math.max,u=Math.floor,d=Math.ceil,m=Ember.ArrayPolyfills.forEach,f=Ember.create(Ember.ContainerView.proto().domManager);f.prepend=function(e,t){e.$(".ember-list-container").prepend(t),r()},Ember.ListViewMixin=Ember.Mixin.create({itemViewClass:Ember.ReusableListItemView,emptyViewClass:Ember.View,classNames:["ember-list-view"],attributeBindings:["style"],domManager:f,scrollTop:0,bottomPadding:0,_lastEndingIndex:0,paddingCount:1,init:function(){this._super(),this.on("didInsertElement",this._syncListContainerWidth),this.columnCountDidChange(),this._syncChildViews(),this._addContentArrayObserver()},_addContentArrayObserver:Ember.beforeObserver(function(){e.call(this)},"content"),render:function(e){e.push('<div class="ember-list-container">'),this._super(e),e.push("</div>")},willInsertElement:function(){if(!this.get("height")||!this.get("rowHeight"))throw new Error("A ListView must be created with a height and a rowHeight.");this._super()},style:Ember.computed("height","width",function(){var e,t,i,n;e=l(this,"height"),t=l(this,"width"),n=l(this,"css"),i="",e&&(i+="height:"+e+"px;"),t&&(i+="width:"+t+"px;");for(var r in n)n.hasOwnProperty(r)&&(i+=r+":"+n[r]+";");return i}),scrollTo:function(){throw new Error("must override to perform the visual scroll and effectively delegate to _scrollContentTo")},_scrollTo:Ember.K,_scrollContentTo:function(e){var t,i,n,r,s,o,h;if(o=a(0,e),this.scrollTop!==o){var u=a(0,l(this,"totalHeight")-l(this,"height"));o=c(o,u),h=l(this,"content"),s=l(h,"length"),t=this._startingIndex(s),Ember.instrument("view._scrollContentTo",{scrollTop:o,content:h,startingIndex:t,endingIndex:c(a(s-1,0),t+this._numChildViewsForViewport())},function(){return this.scrollTop=o,r=a(s-1,0),t=this._startingIndex(),n=t+this._numChildViewsForViewport(),i=c(r,n),t===this._lastStartingIndex&&i===this._lastEndingIndex?(this.trigger("scrollYChanged",e),void 0):(Ember.run(this,function(){this._reuseChildren(),this._lastStartingIndex=t,this._lastEndingIndex=i,this.trigger("scrollYChanged",e)}),void 0)},this)}},totalHeight:Ember.computed("content.length","rowHeight","columnCount","bottomPadding",function(){var e,t,i,n;return e=l(this,"content.length"),t=l(this,"rowHeight"),i=l(this,"columnCount"),n=l(this,"bottomPadding"),d(e/i)*t+n}),_prepareChildForReuse:function(e){e.prepareForReuse()},_reuseChildForContentIndex:function(e,t){var i,n,r,s;i=l(this,"content"),s=l(this,"enableProfiling"),r=this.positionForIndex(t),e.updatePosition(r),h(e,"contentIndex",t),s&&Ember.instrument("view._reuseChildForContentIndex",r,function(){},this),n=i.objectAt(t),e.updateContext(n)},positionForIndex:function(e){var t,i,n,r,s,o;return t=l(this,"elementWidth")||1,i=l(this,"width")||1,n=l(this,"columnCount"),r=l(this,"rowHeight"),s=r*u(e/n),o=e%n*t,{y:s,x:o}},_childViewCount:function(){var e,t;return e=l(this,"content.length"),t=this._numChildViewsForViewport(),c(e,t)},columnCount:Ember.computed("width","elementWidth",function(){var e,t,i;return e=l(this,"elementWidth"),t=l(this,"width"),i=e&&t>e?u(t/e):1}),columnCountDidChange:Ember.observer(function(){var e,t,i,n,r,s,o,h;s=this._lastColumnCount,t=this.scrollTop,o=l(this,"columnCount"),n=l(this,"maxScrollTop"),h=l(this,"element"),this._lastColumnCount=o,s&&(e=s/o,i=t*e,r=c(n,i),this._scrollTo(r),this.scrollTop=r),arguments.length>0&&Ember.run.schedule("afterRender",this,this._syncListContainerWidth)},"columnCount"),maxScrollTop:Ember.computed("height","totalHeight",function(){var e,t;return e=l(this,"totalHeight"),t=l(this,"height"),a(0,e-t)}),_isChildEmptyView:function(){var e=l(this,"emptyView");return e&&e instanceof Ember.View&&1===this._childViews.length&&0===this._childViews.indexOf(e)},_numChildViewsForViewport:function(){var e,t,i,n;return e=l(this,"height"),t=l(this,"rowHeight"),i=l(this,"paddingCount"),n=l(this,"columnCount"),d(e/t)*n+i*n},_startingIndex:function(e){var t,i,n,r,s,o;return s=void 0===e?l(this,"content.length"):e,t=this.scrollTop,i=l(this,"rowHeight"),n=l(this,"columnCount"),r=u(t/i)*n,o=a(s-1,0),c(r,o)},contentWillChange:Ember.beforeObserver(function(){var e;e=l(this,"content"),e&&e.removeArrayObserver(this)},"content"),contentDidChange:Ember.observer(function(){e.call(this),i.call(this)},"content"),needsSyncChildViews:Ember.observer(i,"height","width","columnCount"),_addItemView:function(){var e,t;e=l(this,"itemViewClass"),t=this.createChildView(e),this.pushObject(t)},_syncChildViews:function(){var e,i,n,r,h,c,a,u,d,f,p;if(!l(this,"isDestroyed")&&!l(this,"isDestroying")){if(u=l(this,"content.length"),d=l(this,"emptyView"),i=this._childViewCount(),e=this.positionOrderedChildViews(),this._isChildEmptyView()&&s.call(this),c=this._startingIndex(),a=c+i,r=i,n=e.length,p=r-n,0===p);else if(p>0)for(h=this._lastEndingIndex,f=0;p>f;f++,h++)this._addItemView(h);else m.call(e.splice(r,n),t,this);this._reuseChildren(),this._lastStartingIndex=c,this._lastEndingIndex=this._lastEndingIndex+p,(0===u||void 0===u)&&o.call(this)}},_syncListContainerWidth:function(){var e,t,i,n;e=l(this,"elementWidth"),t=l(this,"columnCount"),i=e*t,n=this.$(".ember-list-container"),i&&n&&n.css("width",i)},_reuseChildren:function(){var e,t,i,n,r,s,o,h,u,d,m;for(m=this.scrollTop,e=l(this,"content.length"),u=a(e-1,0),t=this.getReusableChildViews(),i=t.length,n=this._startingIndex(),h=n+this._numChildViewsForViewport(),r=c(u,h),d=c(h,n+i),o=n;d>o;o++)s=t[o%i],this._reuseChildForContentIndex(s,o)},getReusableChildViews:function(){return this._childViews},positionOrderedChildViews:function(){return this.getReusableChildViews().sort(n)},arrayWillChange:Ember.K,arrayDidChange:function(e,t){var n,r;s.call(this),"inDOM"===this.state&&((t>=this._lastStartingIndex||t<this._lastEndingIndex)&&(n=0,m.call(this.positionOrderedChildViews(),function(e){r=this._lastStartingIndex+n,this._reuseChildForContentIndex(e,r),n++},this)),i.call(this))},destroy:function(){return this._super()?(this._createdEmptyView&&this._createdEmptyView.destroy(),this):void 0}})}(),function(){var e=Ember.get;Ember.set,Ember.ListView=Ember.ContainerView.extend(Ember.ListViewMixin,{css:{position:"relative",overflow:"auto","-webkit-overflow-scrolling":"touch","overflow-scrolling":"touch"},applyTransform:Ember.ListViewHelper.applyTransform,_scrollTo:function(t){var i=e(this,"element");i&&(i.scrollTop=t)},didInsertElement:function(){var t=this,i=e(this,"element");this._updateScrollableHeight(),this._scroll=function(e){t.scroll(e)},Ember.$(i).on("scroll",this._scroll)},willDestroyElement:function(){var t;t=e(this,"element"),Ember.$(t).off("scroll",this._scroll)},scroll:function(e){this.scrollTo(e.target.scrollTop)},scrollTo:function(t){e(this,"element"),this._scrollTo(t),this._scrollContentTo(t)},totalHeightDidChange:Ember.observer(function(){Ember.run.scheduleOnce("afterRender",this,this._updateScrollableHeight)},"totalHeight"),_updateScrollableHeight:function(){var t;"inDOM"===this.state&&(t=this._isChildEmptyView()?"":e(this,"totalHeight"),this.$(".ember-list-container").css({height:t}))}})}(),function(){function e(e){this.mouseWheel(e),e.preventDefault()}function t(e,t){e.addEventListener(u,t.start,!1),e.addEventListener("mousewheel",t.wheel,!1)}function i(e,t){e.removeEventListener(u,t.start,!1),e.removeEventListener("mousewheel",t.wheel,!1)}function n(e){window.addEventListener(d,e.move,!0),window.addEventListener(m,e.end,!0),window.addEventListener(f,e.cancel,!0)}function r(e){window.removeEventListener(d,e.move,!0),window.removeEventListener(m,e.end,!0),window.removeEventListener(f,e.cancel,!0)}function s(e,t){return function(i){t.call(e,i)}}function o(e){var t,i=e.changedTouches[0],n=i.target;return n&&p.test(n.tagName)?(t=document.createEvent("MouseEvents"),t.initMouseEvent("click",!0,!0,e.view,1,i.screenX,i.screenY,i.clientX,i.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,null),n.dispatchEvent(t)):void 0}var l,h,c,a,u,d,m,f,p=/input|textarea|select/i,g="ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch;g?(u="touchstart",l=function(e){var t=e.touches[0],i=t&&t.target;i&&p.test(i.tagName)||(n(this.scrollerEventHandlers),this.willBeginScroll(e.touches,e.timeStamp),e.preventDefault())},d="touchmove",h=function(e){this.continueScroll(e.touches,e.timeStamp)},m="touchend",c=function(e){this._isScrolling||o(e),r(this.scrollerEventHandlers),this.endScroll(e.timeStamp)},f="touchcancel",a=function(e){r(this.scrollerEventHandlers),this.endScroll(e.timeStamp)}):(u="mousedown",l=function(e){if(1===e.which){var t=e.target;t&&p.test(t.tagName)||(n(this.scrollerEventHandlers),this.willBeginScroll([e],e.timeStamp),e.preventDefault())}},d="mousemove",h=function(e){this.continueScroll([e],e.timeStamp)},m="mouseup",c=function(e){r(this.scrollerEventHandlers),this.endScroll(e.timeStamp)},f="mouseout",a=function(e){e.relatedTarget||(r(this.scrollerEventHandlers),this.endScroll(e.timeStamp))}),Ember.VirtualListScrollerEvents=Ember.Mixin.create({init:function(){return this.on("didInsertElement",this,"bindScrollerEvents"),this.on("willDestroyElement",this,"unbindScrollerEvents"),this.scrollerEventHandlers={start:s(this,l),move:s(this,h),end:s(this,c),cancel:s(this,a),wheel:s(this,e)},this._super()},scrollElement:Ember.computed.oneWay("element").readOnly(),bindScrollerEvents:function(){var e=this.get("scrollElement"),i=this.scrollerEventHandlers;t(e,i)},unbindScrollerEvents:function(){var e=this.get("scrollElement"),t=this.scrollerEventHandlers;i(e,t),r(t)}})}(),function(){function e(e){var i,n,r;e=e||this,i=t(e,"width"),n=t(e,"height"),r=t(e,"totalHeight"),e.scroller.setDimensions(i,n,i,r),e.trigger("scrollerDimensionsDidChange")}var t=(Math.max,Ember.get);Ember.set,Ember.VirtualListView=Ember.ContainerView.extend(Ember.ListViewMixin,Ember.VirtualListScrollerEvents,{_isScrolling:!1,_mouseWheel:null,css:{position:"relative",overflow:"hidden"},init:function(){this._super(),this.setupScroller(),this.setupPullToRefresh()},_scrollerTop:0,applyTransform:Ember.ListViewHelper.apply3DTransform,setupScroller:function(){var t;t=this,t.scroller=new Scroller(function(e,i){"inDOM"===t.state&&t.listContainerElement&&(t._scrollerTop=i,t._scrollContentTo(i),t.applyTransform(t.listContainerElement,0,-i))},{scrollingX:!1,scrollingComplete:function(){t.trigger("scrollingDidComplete")}}),t.trigger("didInitializeScroller"),e(t)},setupPullToRefresh:function(){this.pullToRefreshViewClass&&(this._insertPullToRefreshView(),this._activateScrollerPullToRefresh())},_insertPullToRefreshView:function(){this.pullToRefreshView=this.createChildView(this.pullToRefreshViewClass),this.insertAt(0,this.pullToRefreshView);var e=this;this.pullToRefreshView.on("didInsertElement",function(){Ember.run.schedule("afterRender",this,function(){e.applyTransform(this.get("element"),0,-1*e.pullToRefreshViewHeight)})})},_activateScrollerPullToRefresh:function(){function e(){n.pullToRefreshView.set("active",!0),n.trigger("activatePullToRefresh")}function t(){n.pullToRefreshView.set("active",!1),n.trigger("deactivatePullToRefresh")}function i(){Ember.run(function(){function e(){!n||n.get("isDestroyed")||n.get("isDestroying")||(n.scroller.finishPullToRefresh(),n.pullToRefreshView.set("refreshing",!1))}n.pullToRefreshView.set("refreshing",!0),n.startRefresh(e)})}var n=this;this.scroller.activatePullToRefresh(this.pullToRefreshViewHeight,e,t,i)},getReusableChildViews:function(){var e=this._childViews[0];return e&&e===this.pullToRefreshView?this._childViews.slice(1):this._childViews},scrollerDimensionsNeedToChange:Ember.observer(function(){Ember.run.once(this,e)},"width","height","totalHeight"),didInsertElement:function(){this.listContainerElement=this.$("> .ember-list-container")[0]},willBeginScroll:function(e,t){this._isScrolling=!1,this.trigger("scrollingDidStart"),this.scroller.doTouchStart(e,t)},continueScroll:function(e,t){var i,n,r;this._isScrolling?this.scroller.doTouchMove(e,t):(i=this._scrollerTop,this.scroller.doTouchMove(e,t),n=this._scrollerTop,i!==n&&(r=Ember.$.Event("scrollerstart"),Ember.$(e[0].target).trigger(r),this._isScrolling=!0))},endScroll:function(e){this.scroller.doTouchEnd(e)},scrollTo:function(e,t){void 0===t&&(t=!0),this.scroller.scrollTo(0,e,t,1)},mouseWheel:function(e){var t,i,n;return t=e.webkitDirectionInvertedFromDevice,i=e.wheelDeltaY*(t?.8:-.8),n=this.scroller.__scrollTop+i,n>=0&&n<=this.scroller.__maxScrollTop&&(this.scroller.scrollBy(0,i,!0),e.stopPropagation()),!1}})}(),function(){Ember.Handlebars.registerHelper("ember-list",function(e){var t=e.hash,i=e.hashTypes;t.content=t.items,delete t.items,i.content=i.items,delete i.items,t.content||(t.content="this",i.content="ID");for(var n in t)if(/-/.test(n)){var r=Ember.String.camelize(n);t[r]=t[n],i[r]=i[n],delete t[n],delete i[n]}return Ember.Handlebars.helpers.collection.call(this,"Ember.ListView",e)})}(),"undefined"==typeof location||"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname||Ember.Logger.warn("You are running a production build of Ember on localhost and won't receive detailed error messages. If you want full error messages please use the non-minified build provided on the Ember website.");