16 lines
6.3 KiB
JavaScript
16 lines
6.3 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.data.min"],e)}(function(){return function(e,t){function n(e,t,n,i,r){return e({idx:t,text:n,ns:u.ns,numeric:i,title:r||""})}function i(e,t,n){return x({className:e.substring(1),text:t,wrapClassName:n||""})}function r(e,t,n,i){e.find(t).parent().attr(u.attr("page"),n).attr("tabindex",-1).toggleClass("k-state-disabled",i)}function o(e,t){r(e,h,1,1>=t)}function a(e,t){r(e,g,Math.max(1,t-1),1>=t)}function s(e,t,n){r(e,m,Math.min(n,t+1),t>=n)}function l(e,t,n){r(e,p,n,t>=n)}var u=window.kendo,d=u.ui,c=d.Widget,f=e.proxy,h=".k-i-seek-w",p=".k-i-seek-e",g=".k-i-arrow-w",m=".k-i-arrow-e",v="change",_=".kendoPager",y="click",b="keydown",w="disabled",x=u.template('<a href="\\#" title="#=text#" class="k-link k-pager-nav #= wrapClassName #"><span class="k-icon #= className #">#=text#</span></a>'),k=c.extend({init:function(t,n){var r,d,w=this;c.fn.init.call(w,t,n),n=w.options,w.dataSource=u.data.DataSource.create(n.dataSource),w.linkTemplate=u.template(w.options.linkTemplate),w.selectTemplate=u.template(w.options.selectTemplate),r=w.page(),d=w.totalPages(),w._refreshHandler=f(w.refresh,w),w.dataSource.bind(v,w._refreshHandler),n.previousNext&&(w.element.find(h).length||(w.element.append(i(h,n.messages.first,"k-pager-first")),o(w.element,r,d)),w.element.find(g).length||(w.element.append(i(g,n.messages.previous)),a(w.element,r,d))),n.numeric&&(w.list=w.element.find(".k-pager-numbers"),w.list.length||(w.list=e('<ul class="k-pager-numbers k-reset" />').appendTo(w.element))),n.input&&(w.element.find(".k-pager-input").length||w.element.append('<span class="k-pager-input k-label">'+n.messages.page+'<input class="k-textbox">'+u.format(n.messages.of,d)+"</span>"),w.element.on(b+_,".k-pager-input input",f(w._keydown,w))),n.previousNext&&(w.element.find(m).length||(w.element.append(i(m,n.messages.next)),s(w.element,r,d)),w.element.find(p).length||(w.element.append(i(p,n.messages.last,"k-pager-last")),l(w.element,r,d))),n.pageSizes&&(w.element.find(".k-pager-sizes").length||e('<span class="k-pager-sizes k-label"><select/>'+n.messages.itemsPerPage+"</span>").appendTo(w.element).find("select").html(e.map(e.isArray(n.pageSizes)?n.pageSizes:[5,10,20],function(e){return"<option>"+e+"</option>"}).join("")).end().appendTo(w.element),w.element.find(".k-pager-sizes select").val(w.pageSize()),u.ui.DropDownList&&w.element.find(".k-pager-sizes select").show().kendoDropDownList(),w.element.on(v+_,".k-pager-sizes select",f(w._change,w))),n.refresh&&(w.element.find(".k-pager-refresh").length||w.element.append('<a href="#" class="k-pager-refresh k-link" title="'+n.messages.refresh+'"><span class="k-icon k-i-refresh">'+n.messages.refresh+"</span></a>"),w.element.on(y+_,".k-pager-refresh",f(w._refreshClick,w))),n.info&&(w.element.find(".k-pager-info").length||w.element.append('<span class="k-pager-info k-label" />')),w.element.on(y+_,"a",f(w._click,w)).addClass("k-pager-wrap k-widget"),n.autoBind&&w.refresh(),u.notify(w)},destroy:function(){var e=this;c.fn.destroy.call(e),e.element.off(_),e.dataSource.unbind(v,e._refreshHandler),e._refreshHandler=null,u.destroy(e.element),e.element=e.list=null},events:[v],options:{name:"Pager",selectTemplate:'<li><span class="k-state-selected">#=text#</span></li>',linkTemplate:'<li><a tabindex="-1" href="\\#" class="k-link" data-#=ns#page="#=idx#" #if (title !== "") {# title="#=title#" #}#>#=text#</a></li>',buttonCount:10,autoBind:!0,numeric:!0,info:!0,input:!1,previousNext:!0,pageSizes:!1,refresh:!1,messages:{display:"{0} - {1} of {2} items",empty:"No items to display",page:"Page",of:"of {0}",itemsPerPage:"items per page",first:"Go to the first page",previous:"Go to the previous page",next:"Go to the next page",last:"Go to the last page",refresh:"Refresh",morePages:"More pages"}},setDataSource:function(e){var t=this;t.dataSource.unbind(v,t._refreshHandler),t.dataSource=t.options.dataSource=e,e.bind(v,t._refreshHandler),t.options.autoBind&&e.fetch()},refresh:function(e){var t,i,r,d=this,c=1,f="",h=d.page(),p=d.options,g=d.pageSize(),m=d.dataSource.total(),v=d.totalPages(),_=d.linkTemplate,y=p.buttonCount;if(!e||"itemchange"!=e.action){if(p.numeric){for(h>y&&(r=h%y,c=0===r?h-y+1:h-r+1),i=Math.min(c+y-1,v),c>1&&(f+=n(_,c-1,"...",!1,p.messages.morePages)),t=c;i>=t;t++)f+=n(t==h?d.selectTemplate:_,t,t,!0);v>i&&(f+=n(_,t,"...",!1,p.messages.morePages)),""===f&&(f=d.selectTemplate({text:0})),d.list.html(f)}p.info&&(f=m>0?u.format(p.messages.display,(h-1)*g+1,Math.min(h*g,m),m):p.messages.empty,d.element.find(".k-pager-info").html(f)),p.input&&d.element.find(".k-pager-input").html(d.options.messages.page+'<input class="k-textbox">'+u.format(p.messages.of,v)).find("input").val(h).attr(w,1>m).toggleClass("k-state-disabled",1>m),p.previousNext&&(o(d.element,h,v),a(d.element,h,v),s(d.element,h,v),l(d.element,h,v)),p.pageSizes&&d.element.find(".k-pager-sizes select").val(g).filter("["+u.attr("role")+"=dropdownlist]").kendoDropDownList("value",g).kendoDropDownList("text",g)}},_keydown:function(e){if(e.keyCode===u.keys.ENTER){var t=this.element.find(".k-pager-input").find("input"),n=parseInt(t.val(),10);(isNaN(n)||1>n||n>this.totalPages())&&(n=this.page()),t.val(n),this.page(n)}},_refreshClick:function(e){e.preventDefault(),this.dataSource.read()},_change:function(e){var t=parseInt(e.currentTarget.value,10);isNaN(t)||this.dataSource.pageSize(t)},_click:function(t){var n=e(t.currentTarget);t.preventDefault(),n.is(".k-state-disabled")||this.page(n.attr(u.attr("page")))},totalPages:function(){return Math.ceil((this.dataSource.total()||0)/this.pageSize())},pageSize:function(){return this.dataSource.pageSize()||this.dataSource.total()},page:function(e){return e===t?this.dataSource.total()>0?this.dataSource.page():0:(this.dataSource.page(e),this.trigger(v,{index:e}),t)}});d.plugin(k)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |