1/* 2 kkpager V1.3 3 https://github.com/pgkk/kkpager 4 5 Copyright (c) 2013 [email protected] 6 Licensed under the GNU GENERAL PUBLIC LICENSE 7*/ 8var kkpager = { 9 pagerid : 'kkpager', //divID 10 mode : 'link', //模å¼(link æè click) 11 pno : 1, //å½å页ç 12 total : 1, //æ»é¡µç 13 totalRecords : 0, //æ»æ°æ®æ¡æ° 14 isShowFirstPageBtn : true, //æ¯å¦æ¾ç¤ºé¦é¡µæé® 15 isShowLastPageBtn : true, //æ¯å¦æ¾ç¤ºå°¾é¡µæé® 16 isShowPrePageBtn : true, //æ¯å¦æ¾ç¤ºä¸ä¸é¡µæé® 17 isShowNextPageBtn : true, //æ¯å¦æ¾ç¤ºä¸ä¸é¡µæé® 18 isShowTotalPage : true, //æ¯å¦æ¾ç¤ºæ»é¡µæ° 19 isShowCurrPage : true,//æ¯å¦æ¾ç¤ºå½å页 20 isShowTotalRecords : false, //æ¯å¦æ¾ç¤ºæ»è®°å½æ° 21 isGoPage : true, //æ¯å¦æ¾ç¤ºé¡µç 跳转è¾å ¥æ¡ 22 isWrapedPageBtns : true, //æ¯å¦ç¨spanå 裹ä½é¡µç æé® 23 isWrapedInfoTextAndGoPageBtn : true, //æ¯å¦ç¨spanå 裹ä½å页信æ¯å跳转æé® 24 hrefFormer : '', //龿¥åé¨ 25 hrefLatter : '', //龿¥å°¾é¨ 26 gopageWrapId : 'kkpager_gopage_wrap', 27 gopageButtonId : 'kkpager_btn_go', 28 gopageTextboxId : 'kkpager_btn_go_input', 29 lang : { 30 firstPageText : 'é¦é¡µ', 31 firstPageTipText : 'é¦é¡µ', 32 lastPageText : '尾页', 33 lastPageTipText : '尾页', 34 prePageText : 'ä¸ä¸é¡µ', 35 prePageTipText : 'ä¸ä¸é¡µ', 36 nextPageText : 'ä¸ä¸é¡µ', 37 nextPageTipText : 'ä¸ä¸é¡µ', 38 totalPageBeforeText : 'å ±', 39 totalPageAfterText : '页', 40 currPageBeforeText : 'å½å第', 41 currPageAfterText : '页', 42 totalInfoSplitStr : '/', 43 totalRecordsBeforeText : 'å ±', 44 totalRecordsAfterText : 'æ¡æ°æ®', 45 gopageBeforeText : ' 转å°', 46 gopageButtonOkText : 'ç¡®å®', 47 gopageAfterText : '页', 48 buttonTipBeforeText : '第', 49 buttonTipAfterText : '页' 50 }, 51 //龿¥ç®æ³ï¼å½å¤äºlink模å¼ï¼,åæ°n为页ç 52 getLink : function(n){ 53 //è¿éçç®æ³éç¨äºæ¯å¦ï¼ 54 //hrefFormer=http://www.xx.com/news/20131212 55 //hrefLatter=.html 56 //é£ä¹é¦é¡µï¼ç¬¬1页ï¼å°±æ¯http://www.xx.com/news/20131212.html 57 //第2页就æ¯http://www.xx.com/news/20131212_2.html 58 //第n页就æ¯http://www.xx.com/news/20131212_n.html 59 if(n == 1){ 60 return this.hrefFormer + this.hrefLatter; 61 } 62 return this.hrefFormer + '_' + n + this.hrefLatter; 63 }, 64 //页ç åå»äºä»¶å¤ç彿°ï¼å½å¤äºmode模å¼ï¼,åæ°n为页ç 65 click : function(n){ 66 //è¿éèªå·±å®ç° 67 //è¿éå¯ä»¥ç¨thisæè kkpager访é®kkpager对象 68 return false; 69 }, 70 //è·åhrefçå¼ï¼å½å¤äºmode模å¼ï¼,åæ°n为页ç 71 getHref : function(n){ 72 //é»è®¤è¿å'#' 73 return '#'; 74 }, 75 //跳转æ¡å¾å°è¾å ¥ç¦ç¹æ¶ 76 focus_gopage : function (){ 77 var btnGo = $('#'+this.gopageButtonId); 78 $('#'+this.gopageTextboxId).attr('hideFocus',true); 79 btnGo.show(); 80 btnGo.css('left','10px'); 81 $('#'+this.gopageTextboxId).addClass('focus'); 82 btnGo.animate({left: '+=70px'}, 50); 83 }, 84 //跳转æ¡å¤±å»è¾å ¥ç¦ç¹æ¶ 85 blur_gopage : function(){ 86 var _this = this; 87 setTimeout(function(){ 88 var btnGo = $('#'+_this.gopageButtonId); 89 btnGo.animate({ 90 left: '-=25' 91 }, 100, function(){ 92 btnGo.hide(); 93 $('#'+_this.gopageTextboxId).removeClass('focus'); 94 }); 95 },400); 96 }, 97 //跳转è¾å ¥æ¡æé®æä½ 98 keypress_gopage : function(){ 99 var event = arguments[0] || window.event; 100 var code = event.keyCode || event.charCode; 101 //delete key 102 if(code == 8) return true; 103 //enter key 104 if(code == 13){ 105 kkpager.gopage(); 106 return false; 107 } 108 //copy and paste 109 if(event.ctrlKey && (code == 99 || code == 118)) return true; 110 //only number key 111 if(code<48 || code>57)return false; 112 return true; 113 }, 114 //跳转æ¡é¡µé¢è·³è½¬ 115 gopage : function(){ 116 var str_page = $('#'+this.gopageTextboxId).val(); 117 if(isNaN(str_page)){ 118 $('#'+this.gopageTextboxId).val(this.next); 119 return; 120 } 121 var n = parseInt(str_page); 122 if(n < 1) n = 1; 123 if(n > this.total) n = this.total; 124 if(this.mode == 'click'){ 125 this._clickHandler(n); 126 }else{ 127 window.location = this.getLink(n); 128 } 129 }, 130 //ä¸å·æ°é¡µé¢ç´æ¥æå¨è°ç¨é䏿ä¸é¡µç 131 selectPage : function(n){ 132 this._config['pno'] = n; 133 this.generPageHtml(this._config,true); 134 }, 135 //çææ§ä»¶ä»£ç 136 generPageHtml : function(config,enforceInit){ 137 if(enforceInit || !this.inited){ 138 this.init(config); 139 } 140 141 var str_first='',str_prv='',str_next='',str_last=''; 142 if(this.isShowFirstPageBtn){ 143 if(this.hasPrv){ 144 str_first = '<a '+this._getHandlerStr(1)+' title="' 145 +(this.lang.firstPageTipText || this.lang.firstPageText)+'">'+this.lang.firstPageText+'</a>'; 146 }else{ 147 str_first = '<span class="disabled">'+this.lang.firstPageText+'</span>'; 148 } 149 } 150 if(this.isShowPrePageBtn){ 151 if(this.hasPrv){ 152 str_prv = '<a '+this._getHandlerStr(this.prv)+' title="' 153 +(this.lang.prePageTipText || this.lang.prePageText)+'">'+this.lang.prePageText+'</a>'; 154 }else{ 155 str_prv = '<span class="disabled">'+this.lang.prePageText+'</span>'; 156 } 157 } 158 if(this.isShowNextPageBtn){ 159 if(this.hasNext){ 160 str_next = '<a '+this._getHandlerStr(this.next)+' title="' 161 +(this.lang.nextPageTipText || this.lang.nextPageText)+'">'+this.lang.nextPageText+'</a>'; 162 }else{ 163 str_next = '<span class="disabled">'+this.lang.nextPageText+'</span>'; 164 } 165 } 166 if(this.isShowLastPageBtn){ 167 if(this.hasNext){ 168 str_last = '<a '+this._getHandlerStr(this.total)+' title="' 169 +(this.lang.lastPageTipText || this.lang.lastPageText)+'">'+this.lang.lastPageText+'</a>'; 170 }else{ 171 str_last = '<span class="disabled">'+this.lang.lastPageText+'</span>'; 172 } 173 } 174 var str = ''; 175 var dot = '<span class="spanDot">...</span>'; 176 var total_info='<span class="totalText">'; 177 var total_info_splitstr = '<span class="totalInfoSplitStr">'+this.lang.totalInfoSplitStr+'</span>'; 178 if(this.isShowCurrPage){ 179 total_info += this.lang.currPageBeforeText + '<span class="currPageNum">' + this.pno + '</span>' + this.lang.currPageAfterText; 180 if(this.isShowTotalPage){ 181 total_info += total_info_splitstr; 182 total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">'+this.total + '</span>' + this.lang.totalPageAfterText; 183 }else if(this.isShowTotalRecords){ 184 total_info += total_info_splitstr; 185 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">'+this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 186 } 187 }else if(this.isShowTotalPage){ 188 total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">'+this.total + '</span>' + this.lang.totalPageAfterText;; 189 if(this.isShowTotalRecords){ 190 total_info += total_info_splitstr; 191 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">'+this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 192 } 193 }else if(this.isShowTotalRecords){ 194 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">'+this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 195 } 196 total_info += '</span>'; 197 198 var gopage_info = ''; 199 if(this.isGoPage){ 200 gopage_info = '<span class="goPageBox">'+this.lang.gopageBeforeText+'<span id="'+this.gopageWrapId+'">'+ 201 '<input type="button" id="'+this.gopageButtonId+'" onclick="kkpager.gopage()" value="' 202 +this.lang.gopageButtonOkText+'" />'+ 203 '<input type="text" id="'+this.gopageTextboxId+'" onfocus="kkpager.focus_gopage()" onkeypress="return kkpager.ke
203ypress_gopage(event);" onblur="kkpager.blur_gopage()" value="'+this.next+'" /></span>'+this.lang.gopageAfterText+'</span>'; 204 } 205 206 //å页å¤ç 207 if(this.total <= 8){ 208 for(var i=1;i<=this.total;i++){ 209 if(this.pno == i){ 210 str += '<span class="curr">'+i+'</span>'; 211 }else{ 212 str += '<a '+this._getHandlerStr(i)+' title="' 213 +this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText+'">'+i+'</a>'; 214 } 215 } 216 }else{ 217 if(this.pno <= 5){ 218 for(var i=1;i<=7;i++){ 219 if(this.pno == i){ 220 str += '<span class="curr">'+i+'</span>'; 221 }else{ 222 str += '<a '+this._getHandlerStr(i)+' title="'+ 223 this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText+'">'+i+'</a>'; 224 } 225 } 226 str += dot; 227 }else{ 228 str += '<a '+this._getHandlerStr(1)+' title="' 229 +this.lang.buttonTipBeforeText + '1' + this.lang.buttonTipAfterText+'">1</a>'; 230 str += '<a '+this._getHandlerStr(2)+' title="' 231 +this.lang.buttonTipBeforeText + '2' + this.lang.buttonTipAfterText +'">2</a>'; 232 str += dot; 233 234 var begin = this.pno - 2; 235 var end = this.pno + 2; 236 if(end > this.total){ 237 end = this.total; 238 begin = end - 4; 239 if(this.pno - begin < 2){ 240 begin = begin-1; 241 } 242 }else if(end + 1 == this.total){ 243 end = this.total; 244 } 245 for(var i=begin;i<=end;i++){ 246 if(this.pno == i){ 247 str += '<span class="curr">'+i+'</span>'; 248 }else{ 249 str += '<a '+this._getHandlerStr(i)+' title="' 250 +this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText+'">'+i+'</a>'; 251 } 252 } 253 if(end != this.total){ 254 str += dot; 255 } 256 } 257 } 258 var pagerHtml = '<div>'; 259 if(this.isWrapedPageBtns){ 260 pagerHtml += '<span class="pageBtnWrap">' + str_first + str_prv + str + str_next + str_last + '</span>' 261 }else{ 262 pagerHtml += str_first + str_prv + str + str_next + str_last; 263 } 264 if(this.isWrapedInfoTextAndGoPageBtn){ 265 pagerHtml += '<span class="infoTextAndGoPageBtnWrap">' + total_info + gopage_info + '</span>'; 266 }else{ 267 pagerHtml += total_info + gopage_info; 268 } 269 pagerHtml += '</div><div style="clear:both;"></div>'; 270 $("#"+this.pagerid).html(pagerHtml); 271 }, 272 //å页æé®æ§ä»¶åå§å 273 init : function(config){ 274 this.pno = isNaN(config.pno) ? 1 : parseInt(config.pno); 275 this.total = isNaN(config.total) ? 1 : parseInt(config.total); 276 this.totalRecords = isNaN(config.totalRecords) ? 0 : parseInt(config.totalRecords); 277 if(config.pagerid){this.pagerid = config.pagerid;} 278 if(config.mode){this.mode = config.mode;} 279 if(config.gopageWrapId){this.gopageWrapId = config.gopageWrapId;} 280 if(config.gopageButtonId){this.gopageButtonId = config.gopageButtonId;} 281 if(config.gopageTextboxId){this.gopageTextboxId = config.gopageTextboxId;} 282 if(config.isShowFirstPageBtn != undefined){this.isShowFirstPageBtn=config.isShowFirstPageBtn;} 283 if(config.isShowLastPageBtn != undefined){this.isShowLastPageBtn=config.isShowLastPageBtn;} 284 if(config.isShowPrePageBtn != undefined){this.isShowPrePageBtn=config.isShowPrePageBtn;} 285 if(config.isShowNextPageBtn != undefined){this.isShowNextPageBtn=config.isShowNextPageBtn;} 286 if(config.isShowTotalPage != undefined){this.isShowTotalPage=config.isShowTotalPage;} 287 if(config.isShowCurrPage != undefined){this.isShowCurrPage=config.isShowCurrPage;} 288 if(config.isShowTotalRecords != undefined){this.isShowTotalRecords=config.isShowTotalRecords;} 289 if(config.isWrapedPageBtns){this.isWrapedPageBtns=config.isWrapedPageBtns;} 290 if(config.isWrapedInfoTextAndGoPageBtn){this.isWrapedInfoTextAndGoPageBtn=config.isWrapedInfoTextAndGoPageBtn;} 291 if(config.isGoPage != undefined){this.isGoPage=config.isGoPage;} 292 if(config.lang){ 293 for(var key in config.lang){ 294 this.lang[key] = config.lang[key]; 295 } 296 } 297 this.hrefFormer = config.hrefFormer || ''; 298 this.hrefLatter = config.hrefLatter || ''; 299 if(config.getLink && typeof(config.getLink) == 'function'){this.getLink = config.getLink;} 300 if(config.click && typeof(config.click) == 'function'){this.click = config.click;} 301 if(config.getHref && typeof(config.getHref) == 'function'){this.getHref = config.getHref;} 302 if(!this._config){ 303 this._config = config; 304 } 305 //validate 306 if(this.pno < 1) this.pno = 1; 307 this.total = (this.total <= 1) ? 1: this.total; 308 if(this.pno > this.total) this.pno = this.total; 309 this.prv = (this.pno<=2) ? 1 : (this.pno-1); 310 this.next = (this.pno >= this.total-1) ? this.total : (this.pno + 1); 311 this.hasPrv = (this.pno > 1); 312 this.hasNext = (this.pno < this.total); 313 314 this.inited = true; 315 }, 316 _getHandlerStr : function(n){ 317 if(this.mode == 'click'){ 318 return 'href="'+this.getHref(n)+'" onclick="return kkpager._clickHandler('+n+')"';
319 } 320 //link模å¼ï¼ä¹æ¯é»è®¤ç 321 return 'href="'+this.getLink(n)+'"'; 322 }, 323 _clickHandler : function(n){ 324 var res = false; 325 if(this.click && typeof this.click == 'function'){ 326 res = this.click.call(this,n) || false; 327 } 328 return res; 329 } 330};
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.