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*/ 8//<link href="~/style/kkpager_blue.css" rel="stylesheet" /> 9//if (!document.getElementById('kkpagecss')) { 10// var js = document.createElement('link'); 11// js.href = '/style/kkpager_blue.min.css'; 12// js.id = 'kkpagecss'; 13// js.rel = 'stylesheet'; 14// document.body.appendChild(js); 15//} 16 17var kkpager = { 18 type: '', //å¤ä¸ªå¯¼èªæ åç¬ç¹å»çæ¹æ³ 19 pagerid: 'kkpager', //divID 20 mode: 'link', //模å¼(link æè click) 21 pno: 1, //å½å页ç 22 total: 1, //æ»é¡µç 23 totalRecords: 0, //æ»æ°æ®æ¡æ° 24 isShowPages:7, //æ¾ç¤ºå 页 25 isShowFirstPageBtn: true, //æ¯å¦æ¾ç¤ºé¦é¡µæé® 26 isShowLastPageBtn: true, //æ¯å¦æ¾ç¤ºå°¾é¡µæé® 27 isShowPrePageBtn: true, //æ¯å¦æ¾ç¤ºä¸ä¸é¡µæé® 28 isShowNextPageBtn: true, //æ¯å¦æ¾ç¤ºä¸ä¸é¡µæé® 29 isShowTotalPage: false, //æ¯å¦æ¾ç¤ºæ»é¡µæ° 30 isShowCurrPage: false,//æ¯å¦æ¾ç¤ºå½å页 31 isShowTotalRecords: false, //æ¯å¦æ¾ç¤ºæ»è®°å½æ° 32 isGoPage: false, //æ¯å¦æ¾ç¤ºé¡µç 跳转è¾å ¥æ¡ 33 isWrapedPageBtns: true, //æ¯å¦ç¨spanå 裹ä½é¡µç æé® 34 isWrapedInfoTextAndGoPageBtn: true, //æ¯å¦ç¨spanå 裹ä½å页信æ¯å跳转æé® 35 hrefFormer: '', //龿¥åé¨ 36 hrefLatter: '', //龿¥å°¾é¨ 37 gopageWrapId: 'kkpager_gopage_wrap', 38 gopageButtonId: 'kkpager_btn_go', 39 gopageTextboxId: 'kkpager_btn_go_input', 40 lang: { 41 firstPageText: 'é¦é ', 42 firstPageTipText: 'é¦é ', 43 lastPageText: 'å°¾é ', 44 lastPageTipText: 'å°¾é ', 45 prePageText: 'ä¸ä¸é ', 46 prePageTipText: 'ä¸ä¸é ', 47 nextPageText: 'ä¸ä¸é ', 48 nextPageTipText: 'ä¸ä¸é ', 49 totalPageBeforeText: 'å ±', 50 totalPageAfterText: 'é ', 51 currPageBeforeText: 'ç¶å第', 52 currPageAfterText: 'é ', 53 totalInfoSplitStr: '/', 54 totalRecordsBeforeText: 'å ±', 55 totalRecordsAfterText: 'æ¢æ¸æ', 56 gopageBeforeText: ' è½å°', 57 gopageButtonOkText: '確å®', 58 gopageAfterText: 'é ', 59 buttonTipBeforeText: '第', 60 buttonTipAfterText: 'é ' 61 }, 62 //龿¥ç®æ³ï¼å½å¤äºlink模å¼ï¼,åæ°n为页ç 63 getLink: function (n) { 64 //è¿éçç®æ³éç¨äºæ¯å¦ï¼ 65 //hrefFormer=http://www.xx.com/news/20131212 66 //hrefLatter=.html 67 //é£ä¹é¦é¡µï¼ç¬¬1页ï¼å°±æ¯http://www.xx.com/news/20131212.html 68 //第2页就æ¯http://www.xx.com/news/20131212_2.html 69 //第n页就æ¯http://www.xx.com/news/20131212_n.html 70 if (n == 1) { 71 return this.hrefFormer + this.hrefLatter; 72 } 73 return this.hrefFormer + '_' + n + this.hrefLatter; 74 }, 75 //页ç åå»äºä»¶å¤ç彿°ï¼å½å¤äºmode模å¼ï¼,åæ°n为页ç 76 click: function (n) { 77 //è¿éèªå·±å®ç° 78 //è¿éå¯ä»¥ç¨thisæè kkpager访é®kkpager对象 79 return false; 80 }, 81 //è·åhrefçå¼ï¼å½å¤äºmode模å¼ï¼,åæ°n为页ç 82 getHref: function (n) { 83 //é»è®¤è¿å'javascript:;' 84 return 'javascript:;'; 85 }, 86 //跳转æ¡å¾å°è¾å ¥ç¦ç¹æ¶ 87 focus_gopage: function () { 88 var btnGo = $('#' + this.gopageButtonId); 89 $('#' + this.gopageTextboxId).attr('hideFocus', true); 90 btnGo.show(); 91 btnGo.css('left', '10px'); 92 $('#' + this.gopageTextboxId).addClass('focus'); 93 btnGo.animate({ left: '+=41' }, 50); 94 }, 95 //跳转æ¡å¤±å»è¾å ¥ç¦ç¹æ¶ 96 blur_gopage: function () { 97 var _this = this; 98 setTimeout(function () { 99 var btnGo = $('#' + _this.gopageButtonId); 100 btnGo.animate({ 101 left: '-=25' 102 }, 100, function () { 103 btnGo.hide(); 104 $('#' + _this.gopageTextboxId).removeClass('focus'); 105 }); 106 }, 400); 107 }, 108 //跳转è¾å ¥æ¡æé®æä½ 109 keypress_gopage: function () { 110 var event = arguments[0] || window.event; 111 var code = event.keyCode || event.charCode; 112 //delete key 113 if (code == 8) return true; 114 //enter key 115 if (code == 13) { 116 kkpager.gopage(); 117 return false; 118 } 119 //copy and paste 120 if (event.ctrlKey && (code == 99 || code == 118)) return true; 121 //only number key 122 if (code < 48 || code > 57) return false; 123 return true; 124 }, 125 //跳转æ¡é¡µé¢è·³è½¬ 126 gopage: function () { 127 var str_page = $('#' + this.gopageTextboxId).val(); 128 if (isNaN(str_page)) { 129 $('#' + this.gopageTextboxId).val(this.next); 130 return; 131 } 132 var n = parseInt(str_page); 133 if (n < 1) n = 1; 134 if (n > this.total) n = this.total; 135 if (this.mode == 'click') { 136 this._clickHandler(n, '{total:' + this.total + ',pagerid:\'' + this.pagerid + '\'}'); 137 } else { 138 window.location = this.getLink(n); 139 } 140 }, 141 //ä¸å·æ°é¡µé¢ç´æ¥æå¨è°ç¨é䏿ä¸é¡µç 142 selectPage: function (n) { 143 this._config['pno'] = n; 144 this.generPageHtml(this._config, true); 145 }, 146 //çææ§ä»¶ä»£ç 147 generPageHtml: function (config, enforceInit) { 148 if (enforceInit || !this.inited) { 149 this.init(config); 150 } 151 152 var str_first = '', str_prv = '', str_next = '', str_last = ''; 153 if (this.isShowFirstPageBtn) { 154 if (this.hasPrv) { 155 str_first = '<a ' + this._getHandlerStr(1) + ' title="' 156 + (this.lang.firstPageTipText || this.lang.firstPageText) + '">' + this.lang.firstPageText + '</a>'; 157 } else { 158 str_first = '<span class="disabled">' + this.lang.firstPageText + '</span>'; 159 } 160 } 161 if (this.isShowPrePageBtn) { 162 if (this.hasPrv) { 163 str_prv = '<a ' + this._getHandlerStr(this.prv) + ' title="' 164 + (this.lang.prePageTipText || this.lang.prePageText) + '">' + this.lang.prePageText + '</a>'; 165 } else { 166 str_prv = '<span class="disabled">' + this.lang.prePageText + '</span>'; 167 } 168 } 169 if (this.isShowNextPageBtn) { 170 if (this.hasNext) { 171 str_next = '<a ' + this._getHandlerStr(this.next) + ' title="' 172 + (this.lang.nextPageTipText || this.lang.nextPageText) + '">' + this.lang.nextPageText + '</a>'; 173 } else { 174 str_next = '<span class="disabled">' + this.lang.nextPageText + '</span>'; 175 } 176 } 177 if (this.isShowLastPageBtn) { 178 if (this.hasNext) { 179 str_last = '<a ' + this._getHandlerStr(this.total) + ' title="' 180 + (this.lang.lastPageTipText || this.lang.lastPageText) + '">' + this.lang.lastPageText + '</a>'; 181 } else { 182 str_last = '<span class="disabled">' + this.lang.lastPageText + '</span>'; 183 } 184 } 185 var str = ''; 186 var dot = '<span class="spanDot">...</span>'; 187 var total_info = '<span class="totalText">'; 188 var total_info_splitstr = '<span class="totalInfoSplitStr">
188' + this.lang.totalInfoSplitStr + '</span>'; 189 if (this.isShowCurrPage) { 190 total_info += this.lang.currPageBeforeText + '<span class="currPageNum">' + this.pno + '</span>' + this.lang.currPageAfterText; 191 if (this.isShowTotalPage) { 192 total_info += total_info_splitstr; 193 total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">' + this.total + '</span>' + this.lang.totalPageAfterText; 194 } else if (this.isShowTotalRecords) { 195 total_info += total_info_splitstr; 196 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">' + this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 197 } 198 } else if (this.isShowTotalPage) { 199 total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">' + this.total + '</span>' + this.lang.totalPageAfterText;; 200 if (this.isShowTotalRecords) { 201 total_info += total_info_splitstr; 202 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">' + this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 203 } 204 } else if (this.isShowTotalRecords) { 205 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">' + this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 206 } 207 total_info += '</span>'; 208 209 var gopage_info = ''; 210 if (this.isGoPage) { 211 gopage_info = '<span class="goPageBox">' + this.lang.gopageBeforeText + '<span id="' + this.gopageWrapId + '">' + 212 '<input type="button" id="' + this.gopageButtonId + '" onclick="kkpager.gopage()" value="' 213 + this.lang.gopageButtonOkText + '" />' + 214 '<input type="text" id="' + this.gopageTextboxId + '" onfocus="kkpager.focus_gopage()" onkeypress="return kkpager.keypress_gopage(event);" onblur="kkpager.blur_gopage()" value="' + this.next + '" /></span>' + this.lang.gopageAfterText + '</span>'; 215 } 216 217 //å页å¤ç 218 if (this.total <= 11) { 219 for (var i = 1; i <= this.total; i++) { 220 if (this.pno == i) { 221 str += '<span class="curr">' + i + '</span>'; 222 } else { 223 str += '<a ' + this._getHandlerStr(i) + ' title="' 224 + this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText + '">' + i + '</a>'; 225 } 226 } 227 } else { 228 if (this.pno <= 5) { 229 for (var i = 1; i <= this.isShowPages; i++) { 230 if (this.pno == i) { 231 str += '<span class="curr">' + i + '</span>'; 232 } else { 233 str += '<a ' + this._getHandlerStr(i) + ' title="' + 234 this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText + '">' + i + '</a>'; 235 } 236 } 237 str += dot; 238 } else { 239 str += '<a ' + this._getHandlerStr(1) + ' title="' 240 + this.lang.buttonTipBeforeText + '1' + this.lang.buttonTipAfterText + '">1</a>'; 241 str += '<a ' + this._getHandlerStr(2) + ' title="' 242 + this.lang.buttonTipBeforeText + '2' + this.lang.buttonTipAfterText + '">2</a>'; 243 str += dot; 244 245 var begin = this.pno - 2; 246 var end = this.pno + 2; 247 if (end > this.total) { 248 end = this.total; 249 begin = end - 4; 250 if (this.pno - begin < 2) { 251 begin = begin - 1; 252 } 253 } else if (end + 1 == this.total) { 254 end = this.total; 255 } 256 for (var i = begin; i <= end; i++) { 257 if (this.pno == i) { 258 str += '<span class="curr">' + i + '</span>'; 259 } else { 260 str += '<a ' + this._getHandlerStr(i) + ' title="' 261 + this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText + '">' + i + '</a>'; 262 } 263 } 264 if (end != this.total) { 265 str += dot; 266 } 267 } 268 } 269 var pagerHtml = '<div>'; 270 if (this.isWrapedPageBtns) { 271 pagerHtml += '<span class="pageBtnWrap">' + str_first + str_prv + str + str_next + str_last + '</span>' 272 } else { 273 pagerHtml += str_first + str_prv + str + str_next + str_last; 274 } 275 if (this.isWrapedInfoTextAndGoPageBtn) { 276 pagerHtml += '<span class="infoTextAndGoPageBtnWrap">' + total_info + gopage_info + '</span>'; 277 } else { 278 pagerHtml += total_info + gopage_info; 279 } 280 pagerHtml += '</div><div style="clear:both;"></div>'; 281 $("#" + this.pagerid).html(pagerHtml); 282 }, 283 //å页æé®æ§ä»¶åå§å 284 init: function (config) { 285 this.type = config.type; 286 this.pno = isNaN(config.pno) ? 1 : parseInt(config.pno); 287 this.total = isNaN(config.total) ? 1 : parseInt(config.total); 288 this.totalRecords = isNaN(config.totalRecords) ? 0 : parseInt(config.totalRecords);
289 this.isShowPages = isNaN(config.isShowPages) ? 7 : parseInt(config.isShowPages); 290 if (config.pagerid) { this.pagerid = config.pagerid; } 291 if (config.mode) { this.mode = config.mode; } 292 if (config.gopageWrapId) { this.gopageWrapId = config.gopageWrapId; } 293 if (config.gopageButtonId) { this.gopageButtonId = config.gopageButtonId; } 294 if (config.gopageTextboxId) { this.gopageTextboxId = config.gopageTextboxId; } 295 if (config.isShowFirstPageBtn != undefined) { this.isShowFirstPageBtn = config.isShowFirstPageBtn; } 296 if (config.isShowLastPageBtn != undefined) { this.isShowLastPageBtn = config.isShowLastPageBtn; } 297 if (config.isShowPrePageBtn != undefined) { this.isShowPrePageBtn = config.isShowPrePageBtn; } 298 if (config.isShowNextPageBtn != undefined) { this.isShowNextPageBtn = config.isShowNextPageBtn; } 299 if (config.isShowTotalPage != undefined) { this.isShowTotalPage = config.isShowTotalPage; } 300 if (config.isShowCurrPage != undefined) { this.isShowCurrPage = config.isShowCurrPage; } 301 if (config.isShowTotalRecords != undefined) { this.isShowTotalRecords = config.isShowTotalRecords; } 302 if (config.isWrapedPageBtns) { this.isWrapedPageBtns = config.isWrapedPageBtns; } 303 if (config.isWrapedInfoTextAndGoPageBtn) { this.isWrapedInfoTextAndGoPageBtn = config.isWrapedInfoTextAndGoPageBtn; } 304 if (config.isGoPage != undefined) { this.isGoPage = config.isGoPage; } 305 if (config.lang) { 306 for (var key in config.lang) { 307 this.lang[key] = config.lang[key]; 308 } 309 } 310 this.hrefFormer = config.hrefFormer || ''; 311 this.hrefLatter = config.hrefLatter || ''; 312 if (config.getLink && typeof (config.getLink) == 'function') { this.getLink = config.getLink; } 313 if (config.click && typeof (config.click) == 'function') { this.click = config.click; } 314 if (config.getHref && typeof (config.getHref) == 'function') { this.getHref = config.getHref; } 315 316 317 318 if (!this._config) { 319 this._config = config; 320 } 321 //validate 322 if (this.pno < 1) this.pno = 1; 323 this.total = (this.total <= 1) ? 1 : this.total; 324 if (this.pno > this.total) this.pno = this.total; 325 this.prv = (this.pno <= 2) ? 1 : (this.pno - 1); 326 this.next = (this.pno >= this.total - 1) ? this.total : (this.pno + 1); 327 this.hasPrv = (this.pno > 1); 328 this.hasNext = (this.pno < this.total); 329 330 this.inited = true; 331 }, 332 _getHandlerStr: function (n) { 333 if (this.mode == 'click') { 334 return 'href="' + this.getHref(n) + '" onclick="return ' + this.type + '._clickHandler(' + n + ',{total:' + this.total + ',pagerid:\'' + this.pagerid + '\'})"'; 335 } 336 //link模å¼ï¼ä¹æ¯é»è®¤ç 337 return 'href="' + this.getLink(n) + '"'; 338 }, 339 _clickHandler: function (n, config) { 340 var res = false; 341 if (this.click && typeof this.click == 'function') { 342 res = this.click.call(this, n, config) || false; 343 } 344 return res; 345 }, 346 //å¤å¶ä¸ä¸ªæ°çkkpager å½åæ¯ä¸ªåç¬çkkpagerç¨ 347 //ç¸å½äºnewçææ 348 deepCopy: function () { 349 return this._deepCopy(this); 350 }, 351 _deepCopy: function (kkpager) { 352 var result = {}; 353 for (var key in kkpager) { 354 result[key] = typeof kkpager[key] === 'object' ? this._deepCopy(kkpager[key]) : kkpager[key]; 355 } 356 return result; 357 } 358 359}; 360 361// mode: 'link' å·æ°é¡µé¢ 362//kkpager.generPageHtml({ 363// pagerid: "kkpager1", total: 4, pno: 4, isShowCurrPage: true, mode: 'link', click: function (n) { this.selectPage(n, config);; return false; } 364//}, true); 365 366 367//mode: 'click' æ å·æ°é¡µé¢ å¤ä¸ªå¯¼èªæ å¨click éé¢åajaxæ¹æ³ 368//å®ä¾ varçåå è¦ä¸ type éé¢ç䏿 · 369//var a = kkpager.deepCopy(); 370//var b = kkpager.deepCopy(); 371//a.generPageHtml({ 372// type: "a", pagerid: "kkpager1", total: 4, pno: 4, isShowCurrPage: true, mode: 'click', click: function (n) { this.selectPage(n, config);; return false; } 373//}, true); 374//b.generPageHtml({ type: "b", pagerid: "kkpager2", total: 5, pno: 5, isShowCurrPage: false, mode: 'click', click: function (n) { this.selectPage(n, config);; return false; } }, true); 375 376 377var kkpagerNews = {
378 pagerid: 'kkpager', //divID 379 mode: 'link', //模å¼(link æè click) 380 pno: 1, //å½å页ç 381 total: 1, //æ»é¡µç 382 totalRecords: 0, //æ»æ°æ®æ¡æ° 383 isShowPages: 7, //æ¾ç¤ºå 页 384 isJump: 6, //转跳å 页 385 isJumpLen:5, //转跳 386 isShowFirstPageBtn: true, //æ¯å¦æ¾ç¤ºé¦é¡µæé® 387 isShowLastPageBtn: true, //æ¯å¦æ¾ç¤ºå°¾é¡µæé® 388 isShowPrePageBtn: true, //æ¯å¦æ¾ç¤ºä¸ä¸é¡µæé® 389 isShowNextPageBtn: true, //æ¯å¦æ¾ç¤ºä¸ä¸é¡µæé® 390 isShowTotalPage: false, //æ¯å¦æ¾ç¤ºæ»é¡µæ° 391 isShowCurrPage: true,//æ¯å¦æ¾ç¤ºå½å页 392 isShowTotalRecords: false, //æ¯å¦æ¾ç¤ºæ»è®°å½æ° 393 isGoPage: false, //æ¯å¦æ¾ç¤ºé¡µç 跳转è¾å ¥æ¡ 394 isWrapedPageBtns: true, //æ¯å¦ç¨spanå 裹ä½é¡µç æé® 395 isWrapedInfoTextAndGoPageBtn: true, //æ¯å¦ç¨spanå 裹ä½å页信æ¯å跳转æé® 396 isEllipsisLink: true,//æ¯å¦çç¥å·å¯ç¹å» 397 isShowLastPage: true,//æ¯å¦æ¾ç¤ºæåä¸é¡µé¡µç 398 hrefFormer: '', //龿¥åé¨ 399 hrefLatter: '', //龿¥å°¾é¨ 400 gopageWrapId: 'kkpager_gopage_wrap', 401 gopageButtonId: 'kkpager_btn_go', 402 gopageTextboxId: 'kkpager_btn_go_input', 403 lang: { 404 firstPageText: 'é¦é ', 405 firstPageTipText: 'é¦é ', 406 lastPageText: 'å°¾é ', 407 lastPageTipText: 'å°¾é ', 408 prePageText: 'ä¸ä¸é ', 409 prePageTipText: 'ä¸ä¸é ', 410 nextPageText: 'ä¸ä¸é ', 411 nextPageTipText: 'ä¸ä¸é ', 412 totalPageBeforeText: 'å ±', 413 totalPageAfterText: 'é ', 414 currPageBeforeText: 'ç¶å第', 415 currPageAfterText: 'é ', 416 totalInfoSplitStr: '/', 417 totalRecordsBeforeText: 'å ±', 418 totalRecordsAfterText: 'æ¢æ¸æ', 419 gopageBeforeText: ' è½å°', 420 gopageButtonOkText: '確å®', 421 gopageAfterText: 'é ', 422 buttonTipBeforeText: '第', 423 buttonTipAfterText: 'é ' 424 }, 425 //龿¥ç®æ³ï¼å½å¤äºlink模å¼ï¼,åæ°n为页ç 426 getLink: function (n) { 427 //è¿éçç®æ³éç¨äºæ¯å¦ï¼ 428 //hrefFormer=http://www.xx.com/news/20131212 429 //hrefLatter=.html 430 //é£ä¹é¦é¡µï¼ç¬¬1页ï¼å°±æ¯http://www.xx.com/news/20131212.html 431 //第2页就æ¯http://www.xx.com/news/20131212_2.html 432 //第n页就æ¯http://www.xx.com/news/20131212_n.html 433 if (n == 1) { 434 return this.hrefFormer + this.hrefLatter; 435 } 436 return this.hrefFormer + '_' + n + this.hrefLatter; 437 }, 438 //页ç åå»äºä»¶å¤ç彿°ï¼å½å¤äºmode模å¼ï¼,åæ°n为页ç 439 click: function (n) { 440 //è¿éèªå·±å®ç° 441 //è¿éå¯ä»¥ç¨thisæè kkpagerNews访é®kkpagerNews对象 442 return false; 443 }, 444 //è·åhrefçå¼ï¼å½å¤äºmode模å¼ï¼,åæ°n为页ç 445 getHref: function (n) { 446 //é»è®¤è¿å'#' 447 return '#'; 448 }, 449 //跳转æ¡å¾å°è¾å ¥ç¦ç¹æ¶ 450 focus_gopage: function () { 451 var btnGo = $('#' + this.gopageButtonId); 452 $('#' + this.gopageTextboxId).attr('hideFocus', true); 453 btnGo.show(); 454 btnGo.css('left', '10px'); 455 $('#' + this.gopageTextboxId).addClass('focus'); 456 btnGo.animate({ left: '+=30' }, 50); 457 }, 458 //跳转æ¡å¤±å»è¾å ¥ç¦ç¹æ¶ 459 blur_gopage: function () { 460 var _this = this; 461 setTimeout(function () { 462 var btnGo = $('#' + _this.gopageButtonId); 463 btnGo.animate({ 464 left: '-=25' 465 }, 100, function () { 466 btnGo.hide(); 467 $('#' + _this.gopageTextboxId).removeClass('focus'); 468 }); 469 }, 400); 470 }, 471 //跳转è¾å ¥æ¡æé®æä½ 472 keypress_gopage: function () { 473 var event = arguments[0] || window.event; 474 var code = event.keyCode || event.charCode; 475 //delete key 476 if (code == 8) return true; 477 //enter key 478 if (code == 13) { 479 kkpagerNews.gopage(); 480 return false; 481 } 482 //copy and paste 483 if (event.ctrlKey && (code == 99 || code == 118)) return true; 484 //only number key 485 if (code < 48 || code > 57) return false; 486 return true; 487 }, 488 //跳转æ¡é¡µé¢è·³è½¬ 489 gopage: function () { 490 var str_page = $('#' + this.gopageTextboxId).val(); 491 if (isNaN(str_page)) { 492 $('#' + this.gopageTextboxId).val(this.next); 493 return; 494 } 495 var n = parseInt(str_page); 496 if (n < 1) n = 1; 497 if (n > this.total) n = this.total; 498 if (this.mode == 'click') { 499 this._clickHandler(n, '{total:' + this.total + ',pagerid:\'' + this.pagerid + '\'}'); 500 } else { 501 window.location = this.getLink(n); 502 } 503 }, 504 //ä¸å·æ°é¡µé¢ç´æ¥æå¨è°ç¨é䏿ä¸é¡µç 505 selectPage: function (n, config) { 506 this._config['pno'] = n; 507 this._config['total'] = config.total; 508 this._config['pagerid'] = config.pagerid; 509 this.generPageHtml(this._config, true); 510 }, 511 //çææ§ä»¶ä»£ç 512 generPageHtml: function (config, enforceInit) { 513 if (enforceInit || !this.inited) { 514 this.init(config); 515 } 516 517 var str_first = '', str_prv = '', str_next = '', str_last = ''; 518 if (this.isShowFirstPageBtn) { 519 if (this.hasPrv) { 520 str_first = '<a ' + this._getHandlerStr(1) + ' title="' 521 + (this.lang.firstPageTipText || this.lang.firstPageText) + '">' + this.lang.firstPageText + '</a>'; 522 } else { 523 str_first = '<span class="disabled">' + this.lang.firstPageText + '</span>'; 524 } 525 } 526 if (this.isShowPrePageBtn) { 527 if (this.hasPrv) { 528 str_prv = '<a ' + this._getHandlerStr(this.prv) + ' title="' 529 + (this.lang.prePageTipText || this.lang.prePageText) + '">' + this.lang.prePageText + '</a>'; 530 } else { 531 str_prv = '<span class="disabled">' + this.lang.prePageText + '</span>'; 532 } 533 } 534 if (this.isShowNextPageBtn) { 535 if (this.hasNext) { 536 str_next = '<a ' + this._getHandlerStr(this.next) + ' title="' 537 + (this.lang.nextPageTipText || this.lang.nextPageText) + '">' + this.lang.nextPageText + '</a>'; 538 } else { 539 str_next = '<span class="disabled">' + this.lang.nextPageText + '</span>'; 540 } 541 } 542 if (this.isShowLastPageBtn) { 543 if (this.hasNext) { 544 str_last = '<a ' + this._getHandlerStr(this.total) + ' title="' 545 + (this.lang.lastPageTipText || this.lang.lastPageText) + '">' + this.lang.lastPageText + '</a>'; 546 } else { 547 str_last = '<span class="disabled">' + this.lang.lastPageText + '</span>'; 548 } 549 } 550 var str = ''; 551 if (this.isEllipsisLink) { 552 var dot = '<a ' + this._getHandlerStr(this.prvMax) + ' title="...">...</a>'; 553 var dot2 = '<a ' + this._getHandlerStr(this.nextMax) + ' title="...">...</a>'; 554 } else { 555 var dot = '<span class="spanDot">...</span>'; 556 } 557 var total_info = '<span class="totalText">'; 558 var total_info_splitstr = '<span class="totalInfoSplitStr">
558' + this.lang.totalInfoSplitStr + '</span>'; 559 if (this.isShowCurrPage) { 560 total_info += this.lang.currPageBeforeText + '<span class="currPageNum">' + this.pno + '</span>' + this.lang.currPageAfterText; 561 if (this.isShowTotalPage) { 562 total_info += total_info_splitstr; 563 total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">' + this.total + '</span>' + this.lang.totalPageAfterText; 564 } else if (this.isShowTotalRecords) { 565 total_info += total_info_splitstr; 566 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">' + this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 567 } 568 } else if (this.isShowTotalPage) { 569 total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">' + this.total + '</span>' + this.lang.totalPageAfterText;; 570 if (this.isShowTotalRecords) { 571 total_info += total_info_splitstr; 572 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">' + this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 573 } 574 } else if (this.isShowTotalRecords) { 575 total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">' + this.totalRecords + '</span>' + this.lang.totalRecordsAfterText; 576 } 577 total_info += '</span>'; 578 579 var gopage_info = ''; 580 if (this.isGoPage) { 581 gopage_info = '<span class="goPageBox">' + this.lang.gopageBeforeText + '<span id="' + this.gopageWrapId + '">' + 582 '<input type="button" id="' + this.gopageButtonId + '" onclick="kkpagerNews.gopage()" value="' 583 + this.lang.gopageButtonOkText + '" />' + 584 '<input type="text" id="' + this.gopageTextboxId + '" onfocus="kkpagerNews.focus_gopage()" onkeypress="return kkpagerNews.keypress_gopage(event);" onblur="kkpagerNews.blur_gopage()" value="' + this.next + '" /></span>' + this.lang.gopageAfterText + '</span>'; 585 } 586 587 //å页å¤ç 588 if (this.total <= 11) { 589 for (var i = 1; i <= this.total; i++) { 590 if (this.pno == i) { 591 str += '<span class="curr">' + i + '</span>'; 592 } else { 593 str += '<a ' + this._getHandlerStr(i) + ' title="' 594 + this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText + '">' + i + '</a>'; 595 } 596 } 597 } else { 598 if (this.pno <= 5) { 599 for (var i = 1; i <= this.isShowPages; i++) { 600 if (this.pno == i) { 601 str += '<span class="curr">' + i + '</span>'; 602 } else { 603 str += '<a ' + this._getHandlerStr(i) + ' title="' + 604 this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText + '">' + i + '</a>'; 605 } 606 } 607 str += dot2; 608 if (this.isShowLastPage) { 609 str += '<a ' + this._getHandlerStr(this.total) + ' title="' 610 + this.lang.buttonTipBeforeText + this.total + this.lang.buttonTipAfterText + '">' + this.total + '</a>'; 611 } 612 } else { 613 str += '<a ' + this._getHandlerStr(1) + ' title="' 614 + this.lang.buttonTipBeforeText + '1' + this.lang.buttonTipAfterText + '">1</a>'; 615 str += '<a ' + this._getHandlerStr(2) + ' title="' 616 + this.lang.buttonTipBeforeText + '2' + this.lang.buttonTipAfterText + '">2</a>'; 617 str += dot; 618 619 var begin = this.pno - 2; 620 var end = this.pno + 2; 621 if (end > this.total) { 622 end = this.total; 623 begin = end - 4; 624 if (this.pno - begin < 2) { 625 begin = begin - 1; 626 } 627 } else if (end + 1 == this.total) { 628 end = this.total; 629 } 630 for (var i = begin; i <= end; i++) { 631 if (this.pno == i) { 632 str += '<span class="curr">' + i + '</span>'; 633 } else { 634 str += '<a ' + this._getHandlerStr(i) + ' title="' 635 + this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText + '">' + i + '</a>'; 636 } 637 } 638 if (end != this.total) { 639 if (this.isEllipsisLink) { 640 str += dot2; 641 } else { 642 str += dot; 643 } 644 if (this.isShowLastPage) { 645 str += '<a ' + this._getHandlerStr(this.total) + ' title="' 646 + this.lang.buttonTipBeforeText + this.total + this.lang.buttonTipAfterText + '">' + this.total + '</a>'; 647 } 648 } 649 } 650 } 651 var pagerHtml = '<div>'; 652 if (this.isWrapedPageBtns) { 653 pagerHtml += '<span class="pageBtnWrap">' + str_first + str_prv + str + str_next + str_last + '</span>' 654 } else { 655 pagerHtml += str_first + str_prv + str + str_next + str_last; 656 } 657 if (this.isWrapedInfoTextAndGoPageBtn) { 658 pagerHtml += '<span class="infoTextAndGoPageBtnWrap">' + total_info + gopage_info + '</span>'; 659 } else { 660 pagerHtml += total_info + gopage_info; 661 } 662 pagerHtml += '</div><div style="clear:both;"></div>'; 663 $("#" + this.pagerid).html(pagerHtml); 664 }, 665 //å页æé®æ§ä»¶åå§å 666 init: function (config) { 667 this.type = config.type; 668 this.pno = isNaN(config.pno) ? 1 : parseInt(config.pno); 669 this.total = isNaN(config.total) ? 1 : parseInt(config.total); 670 this.totalRecords = isNaN(config.totalRecords) ? 0 : parseInt(config.totalRecords);
671 this.isShowPages = isNaN(config.isShowPages) ? 7 : parseInt(config.isShowPages); 672 this.isJump = isNaN(config.isJump) ? 6 : parseInt(config.isJump); 673 this.isJumpLen = isNaN(config.isJumpLen) ? 5 : parseInt(config.isJumpLen); 674 if (config.pagerid) { this.pagerid = config.pagerid; } 675 if (config.mode) { this.mode = config.mode; } 676 if (config.gopageWrapId) { this.gopageWrapId = config.gopageWrapId; } 677 if (config.gopageButtonId) { this.gopageButtonId = config.gopageButtonId; } 678 if (config.gopageTextboxId) { this.gopageTextboxId = config.gopageTextboxId; } 679 if (config.isShowFirstPageBtn != undefined) { this.isShowFirstPageBtn = config.isShowFirstPageBtn; } 680 if (config.isShowLastPageBtn != undefined) { this.isShowLastPageBtn = config.isShowLastPageBtn; } 681 if (config.isShowPrePageBtn != undefined) { this.isShowPrePageBtn = config.isShowPrePageBtn; } 682 if (config.isShowNextPageBtn != undefined) { this.isShowNextPageBtn = config.isShowNextPageBtn; } 683 if (config.isShowTotalPage != undefined) { this.isShowTotalPage = config.isShowTotalPage; } 684 if (config.isShowCurrPage != undefined) { this.isShowCurrPage = config.isShowCurrPage; } 685 if (config.isShowTotalRecords != undefined) { this.isShowTotalRecords = config.isShowTotalRecords; } 686 if (config.isWrapedPageBtns) { this.isWrapedPageBtns = config.isWrapedPageBtns; } 687 if (config.isWrapedInfoTextAndGoPageBtn) { this.isWrapedInfoTextAndGoPageBtn = config.isWrapedInfoTextAndGoPageBtn; } 688 if (config.isGoPage != undefined) { this.isGoPage = config.isGoPage; } 689 if (config.lang) { 690 for (var key in config.lang) { 691 this.lang[key] = config.lang[key]; 692 } 693 } 694 this.hrefFormer = config.hrefFormer || ''; 695 this.hrefLatter = config.hrefLatter || ''; 696 if (config.getLink && typeof (config.getLink) == 'function') { this.getLink = config.getLink; } 697 if (config.click && typeof (config.click) == 'function') { this.click = config.click; } 698 if (config.getHref && typeof (config.getHref) == 'function') { this.getHref = config.getHref; } 699 if (!this._config) { 700 this._config = config; 701 } 702 //validate 703 if (this.pno < 1) this.pno = 1; 704 this.total = (this.total <= 1) ? 1 : this.total; 705 if (this.pno > this.total) this.pno = this.total; 706 this.prv = (this.pno <= 2) ? 1 : (this.pno - 1); 707 this.prvMax = (this.pno <= this.isJump) ? 1 : (this.pno - this.isJumpLen); 708 this.next = (this.pno >= this.total - 1) ? this.total : (this.pno + 1); 709 this.nextMax = (this.pno >= this.total - this.isJumpLen) ? this.total : (this.pno + this.isJumpLen); 710 this.hasPrv = (this.pno > 1); 711 this.hasNext = (this.pno < this.total); 712 713 this.inited = true; 714 }, 715 _getHandlerStr: function (n) { 716 if (this.mode == 'click') { 717 return 'href="' + this.getHref(n) + '" onclick="return '+this.type+'._clickHandler(' + n + ',{total:' + this.total + ',pagerid:\'' + this.pagerid + '\'})"'; 718 } 719 //link模å¼ï¼ä¹æ¯é»è®¤ç 720 return 'href="' + this.getLink(n) + '"'; 721 }, 722 _clickHandler: function (n, config) { 723 var res = false; 724 if (this.click && typeof this.click == 'function') { 725 res = this.click.call(this, n, config) || false; 726 } 727 return res; 728 }, 729 //å¤å¶ä¸ä¸ªæ°çkkpager å½åæ¯ä¸ªåç¬çkkpagerç¨ 730 //ç¸å½äºnewçææ 731 deepCopy: function () { 732 return this._deepCopy(this); 733 }, 734 _deepCopy: function (kkpager) { 735 var result = {}; 736 for (var key in kkpager) { 737 result[key] = typeof kkpager[key] === 'object' ? this._deepCopy(kkpager[key]) : kkpager[key]; 738 } 739 return result; 740 } 741};
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.