16 lines
12 KiB
JavaScript
16 lines
12 KiB
JavaScript
/**
|
|
* Copyright 2014 Telerik AD
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
!function(e,define){define(["./kendo.fx.min","./kendo.data.min","./kendo.draganddrop.min"],e)}(function(){return function(e,t){var n,i,r,o,a,s,l,d,c=window.kendo,u=c.mobile,h=u.ui,p=e.proxy,f=c.effects.Transition,g=c.ui.Pane,m=c.ui.PaneDimensions,v=h.DataBoundWidget,_=c.data.DataSource,w=c.data.Buffer,y=c.data.BatchBuffer,b=Math,k=b.abs,x=b.ceil,C=b.round,T=b.max,S=b.min,D=b.floor,A="change",E="changing",I="refresh",P="km-current-page",M="km-virtual-page",z="function",F="itemChange",R="cleanup",L=3,H=-1,B=0,N=1,O=-1,V=0,U=1,W=c.Class.extend({init:function(t){var n=this,i=e("<ol class='km-pages'/>");t.element.append(i),this._changeProxy=p(n,"_change"),this._refreshProxy=p(n,"_refresh"),t.bind(A,this._changeProxy),t.bind(I,this._refreshProxy),e.extend(n,{element:i,scrollView:t})},items:function(){return this.element.children()},_refresh:function(e){var t,n="";for(t=0;e.pageCount>t;t++)n+="<li/>";this.element.html(n),this.items().eq(e.page).addClass(P)},_change:function(e){this.items().removeClass(P).eq(e.page).addClass(P)},destroy:function(){this.scrollView.unbind(A,this._changeProxy),this.scrollView.unbind(I,this._refreshProxy),this.element.remove()}});c.mobile.ui.ScrollViewPager=W,n="transitionEnd",i="dragStart",r="dragEnd",o=c.Observable.extend({init:function(t,o){var a,s,l,d,u,h,p=this;c.Observable.fn.init.call(this),this.element=t,this.container=t.parent(),a=new c.ui.Movable(p.element),s=new f({axis:"x",movable:a,onEnd:function(){p.trigger(n)}}),l=new c.UserEvents(t,{start:function(e){2*k(e.x.velocity)>=k(e.y.velocity)?l.capture():l.cancel(),p.trigger(i,e),s.cancel()},allowSelection:!0,end:function(e){p.trigger(r,e)}}),d=new m({element:p.element,container:p.container}),u=d.x,u.bind(A,function(){p.trigger(A)}),h=new g({dimensions:d,userEvents:l,movable:a,elastic:!0}),e.extend(p,{duration:o&&o.duration||1,movable:a,transition:s,userEvents:l,dimensions:d,dimension:u,pane:h}),this.bind([n,i,r,A],o)},size:function(){return{width:this.dimensions.x.getSize(),height:this.dimensions.y.getSize()}},total:function(){return this.dimension.getTotal()},offset:function(){return-this.movable.x},updateDimension:function(){this.dimension.update(!0)},refresh:function(){this.dimensions.refresh()},moveTo:function(e){this.movable.moveAxis("x",-e)},transitionTo:function(e,t,n){n?this.moveTo(-e):this.transition.moveTo({location:e,duration:this.duration,ease:t})}}),c.mobile.ui.ScrollViewElasticPane=o,a=c.Observable.extend({init:function(e,t,n){var i=this;c.Observable.fn.init.call(this),i.element=e,i.pane=t,i._getPages(),this.page=0,this.pageSize=n.pageSize||1,this.contentHeight=n.contentHeight,this.enablePager=n.enablePager},scrollTo:function(e,t){this.page=e,this.pane.transitionTo(-e*this.pane.size().width,f.easeOutExpo,t)},paneMoved:function(e,t,n,i){var r,o,a=this,s=a.pane,l=s.size().width*a.pageSize,d=C,c=t?f.easeOutBack:f.easeOutExpo;e===O?d=x:e===U&&(d=D),o=d(s.offset()/l),r=T(a.minSnap,S(-o*l,a.maxSnap)),o!=a.page&&n&&n({currentPage:a.page,nextPage:o})&&(r=-a.page*s.size().width),s.transitionTo(r,c,i)},updatePage:function(){var e=this.pane,t=C(e.offset()/e.size().width);return t!=this.page?(this.page=t,!0):!1},forcePageUpdate:function(){return this.updatePage()},resizeTo:function(e){var t,n,i=this.pane,r=e.width;this.pageElements.width(r),"100%"===this.contentHeight&&(t=this.element.parent().height(),this.enablePager===!0&&(n=this.element.parent().find("ol.km-pages"),n.length&&(t-=n.outerHeight(!0))),this.element.css("height",t),this.pageElements.css("height",t)),i.updateDimension(),this._paged||(this.page=D(i.offset()/r)),this.scrollTo(this.page,!0),this.pageCount=x(i.total()/r),this.minSnap=-(this.pageCount-1)*r,this.maxSnap=0},_getPages:function(){this.pageElements=this.element.find("[data-role=page]"),this._paged=this.pageElements.length>0}}),c.mobile.ui.ScrollViewContent=a,s=c.Observable.extend({init:function(e,t,n){var i=this;c.Observable.fn.init.call(this),i.element=e,i.pane=t,i.options=n,i._templates(),i.page=n.page||0,i.pages=[],i._initPages(),i.resizeTo(i.pane.size()),i.pane.dimension.forceEnabled()},setDataSource:function(e){this.dataSource=_.create(e),this._buffer(),this._pendingPageRefresh=!1,this._pendingWidgetRefresh=!1},_viewShow:function(){var e=this;e._pendingWidgetRefresh&&(setTimeout(function(){e._resetPages()},0),e._pendingWidgetRefresh=!1)},_buffer:function(){var e=this.options.itemsPerPage;this.buffer&&this.buffer.destroy(),this.buffer=e>1?new y(this.dataSource,e):new w(this.dataSource,3*e),this._resizeProxy=p(this,"_onResize"),this._resetProxy=p(this,"_onReset"),this._endReachedProxy=p(this,"_onEndReached"),this.buffer.bind({resize:this._resizeProxy,reset:this._resetProxy,endreached:this._endReachedProxy})},_templates:function(){var e=this.options.template,t=this.options.emptyTemplate,n={},i={};typeof e===z&&(n.template=e,e="#=this.template(data)#"),this.template=p(c.template(e),n),typeof t===z&&(i.emptyTemplate=t,t="#=this.emptyTemplate(data)#"),this.emptyTemplate=p(c.template(t),i)},_initPages:function(){var e,t,n=this.pages,i=this.element;for(t=0;L>t;t++)e=new l(i),n.push(e);this.pane.updateDimension()},resizeTo:function(e){var t,n,i,r=this.pages,o=this.pane;for(t=0;r.length>t;t++)r[t].setWidth(e.width);"auto"===this.options.contentHeight?this.element.css("height",this.pages[1].element.height()):"100%"===this.options.contentHeight&&(n=this.element.parent().height(),this.options.enablePager===!0&&(i=this.element.parent().find("ol.km-pages"),i.length&&(n-=i.outerHeight(!0))),this.element.css("height",n),r[0].element.css("height",n),r[1].element.css("height",n),r[2].element.css("height",n)),o.updateDimension(),this._repositionPages(),this.width=e.width},scrollTo:function(e){var t,n=this.buffer;n.syncDataSource(),t=n.at(e),t&&(this._updatePagesContent(e),this.page=e)},paneMoved:function(e,t,n,i){var r,o=this,a=o.pane,s=a.size().width,l=a.offset(),d=Math.abs(l)>=s/3,u=t?c.effects.Transition.easeOutBack:c.effects.Transition.easeOutExpo,h=o.page+2>o.buffer.total(),p=0;e===U?0!==o.page&&(p=-1):e!==O||h?l>0&&d&&!h?p=1:0>l&&d&&0!==o.page&&(p=-1):p=1,r=o.page,p&&(r=p>0?r+1:r-1),n&&n({currentPage:o.page,nextPage:r})&&(p=0),0===p?o._cancelMove(u,i):-1===p?o._moveBackward(i):1===p&&o._moveForward(i)},updatePage:function(){var e=this.pages;return 0===this.pane.offset()?!1:(this.pane.offset()>0?(e.push(this.pages.shift()),this.page++,this.setPageContent(e[2],this.page+1)):(e.unshift(this.pages.pop()),this.page--,this.setPageContent(e[0],this.page-1)),this._repositionPages(),this._resetMovable(),!0)},forcePageUpdate:function(){var e=this.pane.offset(),t=3*this.pane.size().width/4;return k(e)>t?this.updatePage():!1},_resetMovable:function(){this.pane.moveTo(0)},_moveForward:function(e){this.pane.transitionTo(-this.width,c.effects.Transition.easeOutExpo,e)},_moveBackward:function(e){this.pane.transitionTo(this.width,c.effects.Transition.easeOutExpo,e)},_cancelMove:function(e,t){this.pane.transitionTo(0,e,t)},_resetPages:function(){this.page=this.options.page||0,this._updatePagesContent(this.page),this._repositionPages(),this.trigger("reset")},_onResize:function(){var e=this.pages[2],t=this.page+1;this._pendingPageRefresh&&(this.setPageContent(e,t),this._pendingPageRefresh=!1)},_onReset:function(){this.pageCount=x(this.dataSource.total()/this.options.itemsPerPage),this.element.is(":visible")?this._resetPages():this._widgetNeedsRefresh=!0},_onEndReached:function(){this._pendingPageRefresh=!0},_repositionPages:function(){var e=this.pages;e[0].position(H),e[1].position(B),e[2].position(N)},_updatePagesContent:function(e){var t=this.pages,n=e||0;this.setPageContent(t[0],n-1),this.setPageContent(t[1],n),this.setPageContent(t[2],n+1)},setPageContent:function(t,n){var i=this.buffer,r=this.template,o=this.emptyTemplate,a=null;n>=0&&(a=i.at(n),e.isArray(a)&&!a.length&&(a=null)),this.trigger(R,{item:t.element}),t.content(a?r(a):o({})),c.mobile.init(t.element),this.trigger(F,{item:t.element,data:a,ns:c.mobile.ui})}}),c.mobile.ui.VirtualScrollViewContent=s,l=c.Class.extend({init:function(t){this.element=e("<div class='"+M+"'></div>"),this.width=t.width(),this.element.width(this.width),t.append(this.element)},content:function(e){this.element.html(e)},position:function(e){this.element.css("transform","translate3d("+this.width*e+"px, 0, 0)")},setWidth:function(e){this.width=e,this.element.width(e)}}),c.mobile.ui.VirtualPage=l,d=v.extend({init:function(e,t){var n,i,r=this;v.fn.init.call(r,e,t),t=r.options,e=r.element,c.stripWhitespace(e[0]),e.wrapInner("<div/>").addClass("km-scrollview"),this.options.enablePager&&(this.pager=new W(this)),r.inner=e.children().first(),r.page=0,r.inner.css("height",t.contentHeight),r.pane=new o(r.inner,{duration:this.options.duration,transitionEnd:p(this,"_transitionEnd"),dragStart:p(this,"_dragStart"),dragEnd:p(this,"_dragEnd"),change:p(this,I)}),r.bind("resize",function(){r.pane.refresh()}),r.page=t.page,n=0===this.inner.children().length,r._content=n?new s(r.inner,r.pane,t):new a(r.inner,r.pane,t),r._content.page=r.page,r._content.bind("reset",function(){var e=r._content;r._syncWithContent(),r.trigger(I,{pageCount:e.pageCount,page:e.page})}),r._content.bind(F,function(e){r.trigger(F,e),r.angular("compile",function(){return{elements:e.item,data:[{dataItem:e.data}]}})}),r._content.bind(R,function(e){r.angular("cleanup",function(){return{elements:e.item}})}),r.setDataSource(t.dataSource),i=r.container(),i.nullObject?(r.viewInit(),r.viewShow()):i.bind("show",p(this,"viewShow")).bind("init",p(this,"viewInit"))},options:{name:"ScrollView",page:0,duration:400,velocityThreshold:.8,contentHeight:"auto",pageSize:1,itemsPerPage:1,bounceVelocityThreshold:1.6,enablePager:!0,autoBind:!0,template:"",emptyTemplate:""},events:[E,A,I],destroy:function(){v.fn.destroy.call(this),c.destroy(this.element)},viewInit:function(){this.options.autoBind&&this._content.scrollTo(this._content.page,!0)},viewShow:function(){this.pane.refresh()},refresh:function(){var e=this._content;e.resizeTo(this.pane.size()),this.page=e.page,this.trigger(I,{pageCount:e.pageCount,page:e.page})},content:function(e){this.element.children().first().html(e),this._content._getPages(),this.pane.refresh()},value:function(e){var n=this.dataSource;return e?(this.scrollTo(n.indexOf(e),!0),t):n.at(this.page)},scrollTo:function(e,t){this._content.scrollTo(e,t),this._syncWithContent()},prev:function(){var e=this;e._content.paneMoved(U,t,function(t){return e.trigger(E,t)})},next:function(){var e=this;e._content.paneMoved(O,t,function(t){return e.trigger(E,t)})},setDataSource:function(e){if(this._content instanceof s){var t=!e;this.dataSource=_.create(e),this._content.setDataSource(this.dataSource),this.options.autoBind&&!t&&this.dataSource.fetch()}},items:function(){return this.element.find("."+M)},_syncWithContent:function(){var e,n,i=this._content.pages,r=this._content.buffer;this.page=this._content.page,e=r?r.at(this.page):t,e instanceof Array||(e=[e]),n=i?i[1].element:t,this.trigger(A,{page:this.page,element:n,data:e})},_dragStart:function(){this._content.forcePageUpdate()&&this._syncWithContent()},_dragEnd:function(e){var t=this,n=e.x.velocity,i=this.options.velocityThreshold,r=V,o=k(n)>this.options.bounceVelocityThreshold;n>i?r=U:-i>n&&(r=O),this._content.paneMoved(r,o,function(e){return t.trigger(E,e)})},_transitionEnd:function(){this._content.updatePage()&&this._syncWithContent()}}),h.plugin(d)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |