1var PagerUtil = { 2 pagers : {}, 3 render : function (config) { 4 var pager = new Pager(config); 5 this.pagers[config.containerId] = pager; 6 pager.render(); 7 return pager; 8 }, 9 changePage : function (containerId,pageNo,pageSize) { 10 var pager = this.pagers[containerId]; 11 pager.pageNo = pageNo; 12 if(pageSize) pager.pageSize = pageSize; 13 pager.render(); 14 if(typeof(pager.onPageChange) == 'function'){ 15 pager.onPageChange(pager.pageNo,pager.pageSize); 16 } 17 }, 18 jumpPage:function (containerId,fm) { 19 var pager = this.pagers[containerId]; 20 var pn = parseInt(fm.pageNo.value); 21 var ps = parseInt(fm.pageSize.value); 22 var totalPage = pager.totalPage; 23 if(isNaN(ps) || ps > 1000 || ps < 1){ 24 ps = 20; 25 } 26 if(isNaN(pn) || pn < 1 || pn > totalPage){ 27 pn = 1; 28 } 29 pager.pageNo = pn; 30 pager.pageSize = ps; 31 pager.render(); 32 if(typeof(pager.onPageChange) == 'function'){ 33 pager.onPageChange(pager.pageNo,pager.pageSize); 34 } 35 } 36}; 37 38function Pager(config) { 39 this.pageNo = config.pageNo; 40 this.pageSize = config.pageSize; 41 this.totalPage = config.totalPage; 42 this.totalRecord = config.totalRecord; 43 this.containerId = config.containerId; 44 45 //é¡µç æ¹åçåè°æ¹æ³ 46 this.onPageChange = config.onPageChange; 47 48 this.currPageRange = null; 49 50 51 this.hasPrePage = function () { 52 return this.pageNo > 1; 53 }; 54 55 this.hasNextPage = function () { 56 return this.pageNo < this.totalPage; 57 }; 58 59 this.isCurrPage = function (pageNo) { 60 return this.pageNo == pageNo; 61 }; 62 63 this.getPageRange = function (pagingCount) { 64 if (this.pageNo < 1 || this.pageNo > this.totalPage) { 65 this.pageNo = 1; 66 } 67 //èµ·å§é¡µ 68 var startPage = Math.max(1, this.pageNo - pagingCount/2); 69 var endPage = Math.min(this.totalPage, startPage + pagingCount - 1); 70 //ä¸å¤æ° 71 var curr = endPage - startPage + 1; 72 if(curr < pagingCount){ 73 if(startPage != 1){ 74 var offset = pagingCount - curr; 75 startPage = Math.max(1, startPage - offset); 76 } 77 } 78 var pageRange = { 79 "startPage":startPage, 80 "endPage":endPage 81 }; 82 return pageRange; 83 }; 84 85 this.needReRender = function () { 86 var need = true; 87 if(this.currPageRange != null){ 88 if((this.pageNo < this.currPageRange.endPage && this.pageNo > this.currPageRange.startPage) 89 || this.pageNo == 1 || this.pageNo == this.totalPage){ 90 need = false; 91 } 92 } 93 return need; 94 } 95 96 //渲æpager 97 this.render = function () { 98 //ä¸éè¦éæ°æ¸²æ 99 //if(!this.needReRender()) return; 100 101 var pr = this.getPageRange(10); 102 this.currPageRange = pr; 103 104 var html = ""; 105 html += "<div class='search_page'>"; 106 html += "<a class='first_page' href='javascript:void(0);' onclick='PagerUtil.changePage(\""+this.containerId+"\","+1+")'>é¦é¡µ</a> "; 107 if(this.hasPrePage()){ 108 var prePage = this.pageNo - 1; 109 html += "<a class='prev_page' href='javascript:void(0);' onclick='PagerUtil.changePage(\""+this.containerId+"\","+prePage+")'><</a> "; 110 }else{ 111 html += "<a class='prev_page' href='javascript:void(0);'><</a> "; 112 } 113 114 115 for(; pr.startPage <= pr.endPage ; pr.startPage++){ 116 if (this.isCurrPage(pr.startPage)){ 117 html += "<a href='javascript:void(0);' class='current_page'>"+pr.startPage+"</a> "; 118 } else{ 119 html += "<a href='javascript:void(0);' onclick='PagerUtil.changePage(\""+this.containerId+"\","+pr.startPage+")'>"+pr.startPage+"</a> "; 120 } 121 } 122 if(this.hasNextPage()){ 123 var nextPage = this.pageNo + 1; 124 html += "<a class='next_page' href='javascript:void(0);' onclick='PagerUtil.changePage(\""+this.containerId+"\","+nextPage+")'>></a> "; 125 }else{ 126 html += "<a class='next_page' href='javascript:void(0);'>></a> "; 127 } 128 html += "<a class='last_page' href='javascript:void(0);' onclick='PagerUtil.changePage(\""+this.containerId+"\","+this.totalPage+")'>æ«é¡µ</a> "; 129 130 html += "</div>"; 131 132 $("#"+this.containerId).html(html); 133 134 } 135}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.