EOS/Scripts/kendo/2015.3.1111/kendo.mobile.listview.min.js
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

9 lines
18 KiB
JavaScript

/*
* Kendo UI v2015.3.1111 (http://www.telerik.com/kendo-ui)
* Copyright 2015 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
!function(e,define){define(["./kendo.data.min","./kendo.userevents.min","./kendo.mobile.button.min"],e)}(function(){return function(e,t){function n(){return this.nodeType===v.TEXT_NODE&&this.nodeValue.match(U)}function i(e,t){t&&!e[0].querySelector(".km-icon")&&e.prepend('<span class="km-icon km-'+t+'"/>')}function o(e){i(e,T(e,"icon")),i(e,T(e.children(C),"icon"))}function r(e){var t=e.parent(),o=e.add(t.children(m.roleSelector("detailbutton"))),r=t.contents().not(o).not(n);r.length||(e.addClass("km-listview-link").attr(m.attr("role"),"listview-link"),i(e,T(t,"icon")),i(e,T(e,"icon")))}function s(e){if(e[0].querySelector("input[type=checkbox],input[type=radio]")){var t=e.parent();t.contents().not(e).not(function(){return 3==this.nodeType})[0]||(e.addClass("km-listview-label"),e.children("[type=checkbox],[type=radio]").addClass("km-widget km-icon km-check"))}}function a(t,n){e(t).css("transform","translate3d(0px, "+n+"px, 0px)")}var l,c,u,d,h,f,p,g,m=window.kendo,v=window.Node,_=m.mobile,b=_.ui,w=m.data.DataSource,y=b.DataBoundWidget,x=".km-list > li, > li:not(.km-group-container)",k=".km-listview-link, .km-listview-label",C="["+m.attr("icon")+"]",S=e.proxy,T=m.attrValue,D="km-group-title",A="km-state-active",M='<div class="'+D+'"><div class="km-text"></div></div>',E=m.template('<li><div class="'+D+'"><div class="km-text">#= this.headerTemplate(data) #</div></div><ul>#= kendo.render(this.template, data.items)#</ul></li>'),P='<div class="km-listview-wrapper" />',I=m.template('<form class="km-filter-form"><div class="km-filter-wrap"><input type="search" placeholder="#=placeholder#"/><a href="\\#" class="km-filter-reset" title="Clear"><span class="km-icon km-clear"></span><span class="km-text">Clear</span></a></div></form>'),R=".kendoMobileListView",B="styled",z="dataBound",L="dataBinding",F="itemChange",O="click",N="change",H="progress",V="function",U=/^\s+$/,W=/button/,j=m.Class.extend({init:function(e){var t,n,i=e.scroller();i&&(this.options=e.options,this.element=e.element,this.scroller=e.scroller(),this._shouldFixHeaders(),t=this,n=function(){t._cacheHeaders()},e.bind("resize",n),e.bind(B,n),e.bind(z,n),i.bind("scroll",function(e){t._fixHeader(e)}))},_fixHeader:function(t){if(this.fixedHeaders){var n,i,o,r=0,s=this.scroller,a=this.headers,l=t.scrollTop;do{if(n=a[r++],!n){o=e("<div />");break}i=n.offset,o=n.header}while(i+1>l);this.currentHeader!=r&&(s.fixedContainer.html(o.clone()),this.currentHeader=r)}},_shouldFixHeaders:function(){this.fixedHeaders="group"===this.options.type&&this.options.fixedHeaders},_cacheHeaders:function(){if(this._shouldFixHeaders(),this.fixedHeaders){var t=[],n=this.scroller.scrollTop;this.element.find("."+D).each(function(i,o){o=e(o),t.unshift({offset:o.position().top+n,header:o})}),this.headers=t,this._fixHeader({scrollTop:n})}}}),G=function(){return{page:1}},q=m.Class.extend({init:function(e){var t=this,n=e.options,i=e.scroller(),o=n.pullParameters||G;this.listView=e,this.scroller=i,e.bind("_dataSource",function(e){t.setDataSource(e.dataSource)}),i.setOptions({pullToRefresh:!0,pull:function(){t._pulled||(t._pulled=!0,t.dataSource.read(o.call(e,t._first)))},messages:{pullTemplate:n.messages.pullTemplate,releaseTemplate:n.messages.releaseTemplate,refreshTemplate:n.messages.refreshTemplate}})},setDataSource:function(e){var t=this;this._first=e.view()[0],this.dataSource=e,e.bind("change",function(){t._change()}),e.bind("error",function(){t._change()})},_change:function(){var e,t=this.scroller,n=this.dataSource;this._pulled&&t.pullHandled(),(this._pulled||!this._first)&&(e=n.view(),e[0]&&(this._first=e[0])),this._pulled=!1}}),$=m.Observable.extend({init:function(e){var t=this;m.Observable.fn.init.call(t),t.buffer=e.buffer,t.height=e.height,t.item=e.item,t.items=[],t.footer=e.footer,t.buffer.bind("reset",function(){t.refresh()})},refresh:function(){for(var e,t,n,i,o=this.buffer,r=this.items,s=!1;r.length;)r.pop().destroy();for(this.offset=o.offset,e=this.item,i=0;o.viewSize>i;i++){if(i===o.total()){s=!0;break}n=e(this.content(this.offset+r.length)),n.below(t),t=n,r.push(n)}this.itemCount=r.length,this.trigger("reset"),this._resize(),s&&this.trigger("endReached")},totalHeight:function(){if(!this.items[0])return 0;var e=this,t=e.items,n=t[0].top,i=t[t.length-1].bottom,o=(i-n)/e.itemCount,r=e.buffer.length-e.offset-e.itemCount;return(this.footer?this.footer.height:0)+i+r*o},batchUpdate:function(e){var t,n,i=this.height(),o=this.items,r=this.offset;if(o[0]){if(this.lastDirection)for(;o[o.length-1].bottom>e+2*i&&0!==this.offset;)this.offset--,t=o.pop(),t.update(this.content(this.offset)),t.above(o[0]),o.unshift(t);else for(;e-i>o[0].top;){if(n=this.offset+this.itemCount,n===this.buffer.total()){this.trigger("endReached");break}if(n===this.buffer.length)break;t=o.shift(),t.update(this.content(this.offset+this.itemCount)),t.below(o[o.length-1]),o.push(t),this.offset++}r!==this.offset&&this._resize()}},update:function(e){var t,n,i,o,r=this,s=this.items,a=this.height(),l=this.itemCount,c=a/2,u=(this.lastTop||0)>e,d=e-c,h=e+a+c;s[0]&&(this.lastTop=e,this.lastDirection=u,u?s[0].top>d&&s[s.length-1].bottom>h+c&&this.offset>0&&(this.offset--,t=s.pop(),n=s[0],t.update(this.content(this.offset)),s.unshift(t),t.above(n),r._resize()):h>s[s.length-1].bottom&&d-c>s[0].top&&(o=this.offset+l,o===this.buffer.total()?this.trigger("endReached"):o!==this.buffer.length&&(t=s.shift(),i=s[s.length-1],s.push(t),t.update(this.content(this.offset+this.itemCount)),r.offset++,t.below(i),r._resize())))},content:function(e){return this.buffer.at(e)},destroy:function(){this.unbind()},_resize:function(){var e=this.items,t=0,n=0,i=e[0],o=e[e.length-1];i&&(t=i.top,n=o.bottom),this.trigger("resize",{top:t,bottom:n}),this.footer&&this.footer.below(o)}});m.mobile.ui.VirtualList=$,l=m.Class.extend({init:function(t,n){var i=t.append([n],!0)[0],o=i.offsetHeight;e.extend(this,{top:0,element:i,listView:t,height:o,bottom:o})},update:function(e){this.element=this.listView.setDataItem(this.element,e)},above:function(e){e&&(this.height=this.element.offsetHeight,this.top=e.top-this.height,this.bottom=e.top,a(this.element,this.top))},below:function(e){e&&(this.height=this.element.offsetHeight,this.top=e.bottom,this.bottom=this.top+this.height,a(this.element,this.top))},destroy:function(){m.destroy(this.element),e(this.element).remove()}}),c='<div><span class="km-icon"></span><span class="km-loading-left"></span><span class="km-loading-right"></span></div>',u=m.Class.extend({init:function(t){this.element=e('<li class="km-load-more km-scroller-refresh" style="display: none"></li>').appendTo(t.element),this._loadIcon=e(c).appendTo(this.element)},enable:function(){this.element.show(),this.height=this.element.outerHeight(!0)},disable:function(){this.element.hide(),this.height=0},below:function(e){e&&(this.top=e.bottom,this.bottom=this.height+this.top,a(this.element,this.top))}}),d=u.extend({init:function(t,n){this._loadIcon=e(c).hide(),this._loadButton=e('<a class="km-load">'+t.options.messages.loadMoreText+"</a>").hide(),this.element=e('<li class="km-load-more" style="display: none"></li>').append(this._loadIcon).append(this._loadButton).appendTo(t.element);var i=this;this._loadButton.kendoMobileButton().data("kendoMobileButton").bind("click",function(){i._hideShowButton(),n.next()}),n.bind("resize",function(){i._showLoadButton()}),this.height=this.element.outerHeight(!0),this.disable()},_hideShowButton:function(){this._loadButton.hide(),this.element.addClass("km-scroller-refresh"),this._loadIcon.css("display","block")},_showLoadButton:function(){this._loadButton.show(),this.element.removeClass("km-scroller-refresh"),this._loadIcon.hide()}}),h=m.Class.extend({init:function(e){var t=this;this.chromeHeight=e.wrapper.children().not(e.element).outerHeight()||0,this.listView=e,this.scroller=e.scroller(),this.options=e.options,e.bind("_dataSource",function(e){t.setDataSource(e.dataSource,e.empty)}),e.bind("resize",function(){t.list.items.length&&(t.scroller.reset(),t.buffer.range(0),t.list.refresh())}),this.scroller.makeVirtual(),this.scroller.bind("scroll",function(e){t.list.update(e.scrollTop)}),this.scroller.bind("scrollEnd",function(e){t.list.batchUpdate(e.scrollTop)})},destroy:function(){this.list.unbind(),this.buffer.unbind()},setDataSource:function(t,n){var i,o,r,s,a=this,c=this.options,h=this.listView,f=h.scroller(),p=c.loadMore;if(this.dataSource=t,i=t.pageSize()||c.virtualViewSize,!i&&!n)throw Error("the DataSource does not have page size configured. Page Size setting is mandatory for the mobile listview virtual scrolling to work as expected.");this.buffer&&this.buffer.destroy(),o=new m.data.Buffer(t,Math.floor(i/2),p),r=p?new d(h,o):new u(h),this.list&&this.list.destroy(),s=new $({buffer:o,footer:r,item:function(e){return new l(h,e)},height:function(){return f.height()}}),s.bind("resize",function(){a.updateScrollerSize(),h.updateSize()}),s.bind("reset",function(){a.footer.enable()}),s.bind("endReached",function(){r.disable(),a.updateScrollerSize()}),o.bind("expand",function(){s.lastDirection=!1,s.batchUpdate(f.scrollTop)}),e.extend(this,{buffer:o,scroller:f,list:s,footer:r})},updateScrollerSize:function(){this.scroller.virtualSize(0,this.list.totalHeight()+this.chromeHeight)},refresh:function(){this.list.refresh()},reset:function(){this.buffer.range(0),this.list.refresh()}}),f=m.Class.extend({init:function(e){var t,n=this;this.listView=e,this.options=e.options,t=this,this._refreshHandler=function(e){t.refresh(e)},this._progressHandler=function(){e.showLoading()},e.bind("_dataSource",function(e){n.setDataSource(e.dataSource)})},destroy:function(){this._unbindDataSource()},reset:function(){},refresh:function(e){var n,i,o,r,s,a,l,c=e&&e.action,u=e&&e.items,d=this.listView,h=this.dataSource,f=this.options.appendOnRefresh,p=h.view(),g=h.group(),m=g&&g[0];return"itemchange"===c?(d._hasBindingTarget()||(n=d.findByDataItem(u)[0],n&&d.setDataItem(n,u[0])),t):(s="add"===c&&!m||f&&!d._filter,a="remove"===c&&!m,s?i=[]:a&&(i=d.findByDataItem(u)),d.trigger(L,{action:c||"rebind",items:u,removedItems:i,index:e&&e.index})?(this._shouldShowLoading()&&d.hideLoading(),t):("add"!==c||m?"remove"!==c||m?m?d.replaceGrouped(p):f&&!d._filter?(o=d.prepend(p),r=p):d.replace(p):(o=[],d.remove(u)):(l=p.indexOf(u[0]),l>-1&&(o=d.insertAt(u,l),r=u)),this._shouldShowLoading()&&d.hideLoading(),d.trigger(z,{ns:b,addedItems:o,addedDataItems:r}),t))},setDataSource:function(e){this.dataSource&&this._unbindDataSource(),this.dataSource=e,e.bind(N,this._refreshHandler),this._shouldShowLoading()&&this.dataSource.bind(H,this._progressHandler)},_unbindDataSource:function(){this.dataSource.unbind(N,this._refreshHandler).unbind(H,this._progressHandler)},_shouldShowLoading:function(){var e=this.options;return!e.pullToRefresh&&!e.loadMore&&!e.endlessScroll}}),p=m.Class.extend({init:function(t){var n=this,i=t.options.filterable,o="change paste",r=this;this.listView=t,this.options=i,t.element.before(I({placeholder:i.placeholder||"Search..."})),i.autoFilter!==!1&&(o+=" keyup"),this.element=t.wrapper.find(".km-search-form"),this.searchInput=t.wrapper.find("input[type=search]").closest("form").on("submit"+R,function(e){e.preventDefault()}).end().on("focus"+R,function(){n._oldFilter=n.searchInput.val()}).on(o.split(" ").join(R+" ")+R,S(this._filterChange,this)),this.clearButton=t.wrapper.find(".km-filter-reset").on(O,S(this,"_clearFilter")).hide(),this._dataSourceChange=e.proxy(this._refreshInput,this),t.bind("_dataSource",function(e){e.dataSource.bind("change",r._dataSourceChange)})},_refreshInput:function(){var e=this.listView.dataSource.filter(),t=this.listView._filter.searchInput;t.val(e&&e.filters[0].field===this.listView.options.filterable.field?e.filters[0].value:"")},_search:function(e){this._filter=!0,this.clearButton[e?"show":"hide"](),this.listView.dataSource.filter(e)},_filterChange:function(e){var t=this;"paste"==e.type&&this.options.autoFilter!==!1?setTimeout(function(){t._applyFilter()},1):this._applyFilter()},_applyFilter:function(){var e=this.options,t=this.searchInput.val(),n=t.length?{field:e.field,operator:e.operator||"startswith",ignoreCase:e.ignoreCase,value:t}:null;t!==this._oldFilter&&(this._oldFilter=t,this._search(n))},_clearFilter:function(e){this.searchInput.val(""),this._search(null),e.preventDefault()}}),g=y.extend({init:function(t,n){var i=this;y.fn.init.call(this,t,n),t=this.element,n=this.options,n.scrollTreshold&&(n.scrollThreshold=n.scrollTreshold),t.on("down",k,"_highlight").on("move up cancel",k,"_dim"),this._userEvents=new m.UserEvents(t,{filter:x,allowSelection:!0,tap:function(e){i._click(e)}}),t.css("-ms-touch-action","auto"),t.wrap(P),this.wrapper=this.element.parent(),this._headerFixer=new j(this),this._itemsCache={},this._templates(),this.virtual=n.endlessScroll||n.loadMore,this._style(),this.options.$angular&&(this.virtual||this.options.pullToRefresh)?setTimeout(e.proxy(this,"_start")):this._start()},_start:function(){var e=this.options;this.options.filterable&&(this._filter=new p(this)),this._itemBinder=this.virtual?new h(this):new f(this),this.options.pullToRefresh&&(this._pullToRefreshHandler=new q(this)),this.setDataSource(e.dataSource),this._enhanceItems(this.items()),m.notify(this,b)},events:[O,L,z,F],options:{name:"ListView",style:"",type:"flat",autoBind:!0,fixedHeaders:!1,template:"#:data#",headerTemplate:'<span class="km-text">#:value#</span>',appendOnRefresh:!1,loadMore:!1,endlessScroll:!1,scrollThreshold:30,pullToRefresh:!1,messages:{loadMoreText:"Press to load more",pullTemplate:"Pull to refresh",releaseTemplate:"Release to refresh",refreshTemplate:"Refreshing"},pullOffset:140,filterable:!1,virtualViewSize:null},refresh:function(){this._itemBinder.refresh()},reset:function(){this._itemBinder.reset()},setDataSource:function(e){var t=!e;this.dataSource=w.create(e),this.trigger("_dataSource",{dataSource:this.dataSource,empty:t}),this.options.autoBind&&!t&&(this.items().remove(),this.dataSource.fetch())},destroy:function(){y.fn.destroy.call(this),m.destroy(this.element),this._userEvents.destroy(),this._itemBinder&&this._itemBinder.destroy(),this.element.unwrap(),delete this.element,delete this.wrapper,delete this._userEvents},items:function(){return"group"===this.options.type?this.element.find(".km-list").children():this.element.children().not(".km-load-more")},scroller:function(){return this._scrollerInstance||(this._scrollerInstance=this.element.closest(".km-scroll-wrapper").data("kendoMobileScroller")),this._scrollerInstance},showLoading:function(){var e=this.view();e&&e.loader&&e.loader.show()},hideLoading:function(){var e=this.view();e&&e.loader&&e.loader.hide()},insertAt:function(e,t,n){var i=this;return i._renderItems(e,function(o){if(0===t?i.element.prepend(o):-1===t?i.element.append(o):i.items().eq(t-1).after(o),n)for(var r=0;o.length>r;r++)i.trigger(F,{item:o.eq(r),data:e[r],ns:b})})},append:function(e,t){return this.insertAt(e,-1,t)},prepend:function(e,t){return this.insertAt(e,0,t)},replace:function(e){return this.options.type="flat",this._angularItems("cleanup"),this.element.empty(),this._userEvents.cancel(),this._style(),this.insertAt(e,0)},replaceGrouped:function(t){this.options.type="group",this._angularItems("cleanup"),this.element.empty();var n=e(m.render(this.groupTemplate,t));this._enhanceItems(n.children("ul").children("li")),this.element.append(n),_.init(n),this._style(),this._angularItems("compile")},remove:function(e){var t=this.findByDataItem(e);this.angular("cleanup",function(){return{elements:t}}),m.destroy(t),t.remove()},findByDataItem:function(e){var t,n,i=[];for(t=0,n=e.length;n>t;t++)i[t]="[data-"+m.ns+"uid="+e[t].uid+"]";return this.element.find(i.join(","))},setDataItem:function(t,n){var i=this,o=function(o){var r=e(o[0]);m.destroy(t),i.angular("cleanup",function(){return{elements:[e(t)]}}),e(t).replaceWith(r),i.trigger(F,{item:r,data:n,ns:b})};return this._renderItems([n],o)[0]},updateSize:function(){this._size=this.getSize()},_renderItems:function(t,n){var i=e(m.render(this.template,t));return n(i),this.angular("compile",function(){return{elements:i,data:t.map(function(e){return{dataItem:e}})}}),_.init(i),this._enhanceItems(i),i},_dim:function(e){this._toggle(e,!1)},_highlight:function(e){this._toggle(e,!0)},_toggle:function(t,n){if(!(t.which>1)){var i=e(t.currentTarget),o=i.parent(),r=T(i,"role")||"",s=!r.match(W),a=t.isDefaultPrevented();s&&o.toggleClass(A,n&&!a)}},_templates:function(){var e=this.options.template,t=this.options.headerTemplate,n=' data-uid="#=arguments[0].uid || ""#"',i={},o={};typeof e===V&&(i.template=e,e="#=this.template(data)#"),this.template=S(m.template("<li"+n+">"+e+"</li>"),i),o.template=this.template,typeof t===V&&(o._headerTemplate=t,t="#=this._headerTemplate(data)#"),o.headerTemplate=m.template(t),this.groupTemplate=S(E,o)},_click:function(t){if(!(t.event.which>1||t.event.isDefaultPrevented())){var n,i=t.target,o=e(t.event.target),r=o.closest(m.roleSelector("button","detailbutton","backbutton")),s=m.widgetInstance(r,b),a=i.attr(m.attr("uid"));a&&(n=this.dataSource.getByUid(a)),this.trigger(O,{target:o,item:i,dataItem:n,button:s})&&t.preventDefault()}},_styleGroups:function(){var t=this.element.children();t.children("ul").addClass("km-list"),t.each(function(){var t=e(this),n=t.contents().first();t.addClass("km-group-container"),n.is("ul")||n.is("div."+D)||n.wrap(M)})},_style:function(){var e=this.options,t="group"===e.type,n=this.element,i="inset"===e.style;n.addClass("km-listview").toggleClass("km-list",!t).toggleClass("km-virtual-list",this.virtual).toggleClass("km-listinset",!t&&i).toggleClass("km-listgroup",t&&!i).toggleClass("km-listgroupinset",t&&i),n.parents(".km-listview")[0]||n.closest(".km-content").toggleClass("km-insetcontent",i),t&&this._styleGroups(),this.trigger(B)},_enhanceItems:function(t){t.each(function(){var t,n=e(this),i=!1;n.children().each(function(){t=e(this),t.is("a")?(r(t),i=!0):t.is("label")&&(s(t),i=!0)}),i||o(n)})}}),b.plugin(g)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});