1/** 2 * pagination.js 1.5.1 3 * A jQuery plugin to provide simple yet fully customisable pagination. 4 * @version 1.5.1 5 * @author mss 6 * @url https://github.com/Maxiaoxiang/jQuery-plugins 7 * 8 * @µ÷Ó÷½·¨ 9 * $(selector).pagination(option, callback); 10 * -´Ë´¦callbackÊdzõʼ»¯µ÷Óã¬optionÀïµÄcallbackÊǵã»÷Ò³Âëºóµ÷Óà 11 * 12 * -- example -- 13 * $(selector).pagination({ 14 * ... // ÅäÖòÎÊý 15 * callback: function(api) { 16 * console.log('µã»÷Ò³Âëµ÷Óøûص÷'); //Çл»Ò³ÂëʱִÐÐÒ»´Î»Øµ÷ 17 * } 18 * }, function(){ 19 * console.log('³õʼ»¯'); //²å¼þ³õʼ»¯Ê±µ÷Óø÷½·¨£¬±ÈÈçÇëÇóµÚÒ»´Î½Ó¿ÚÀ´³õʼ»¯·ÖÒ³ÅäÖà 20 * }); 21 */ 22; 23(function (factory) { 24 if (typeof define === "function" && (define.amd || define.cmd) && !jQuery) { 25 // AMD»òCMD 26 define(["jquery"], factory); 27 } else if (typeof module === 'object' && module.exports) { 28 // Node/CommonJS 29 module.exports = function (root, jQuery) { 30 if (jQuery === undefined) { 31 if (typeof window !== 'undefined') { 32 jQuery = require('jquery'); 33 } else { 34 jQuery = require('jquery')(root); 35 } 36 } 37 factory(jQuery); 38 return jQuery; 39 }; 40 } else { 41 //Browser globals 42 factory(jQuery); 43 } 44}(function ($) { 45 46 //ÅäÖòÎÊý 47 var defaults = { 48 totalData: 0, //Êý¾Ý×ÜÌõÊý 49 showData: 0, //ÿҳÏÔʾµÄÌõÊý 50 pageCount: 9, //×ÜÒ³Êý,ĬÈÏΪ9 51 current: 1, //µ±Ç°µÚ¼¸Ò³ 52 prevCls: 'prev', //ÉÏÒ»Ò³class 53 nextCls: 'next', //ÏÂÒ»Ò³class 54 prevContent: '<', //ÉÏÒ»Ò³ÄÚÈÝ 55 nextContent: '>', //ÏÂÒ»Ò³ÄÚÈÝ 56 activeCls: 'active', //µ±Ç°Ò³Ñ¡ÖÐ״̬ 57 coping: false, //Ê×Ò³ºÍβҳ 58 isHide: false, //µ±Ç°Ò³ÊýΪ0Ò³»òÕß1ҳʱ²»ÏÔʾ·ÖÒ³ 59 homePage: '', //Ê×Ò³½ÚµãÄÚÈÝ 60 endPage: '', //βҳ½ÚµãÄÚÈÝ 61 keepShowPN: false, //ÊÇ·ñÒ»Ö±ÏÔʾÉÏÒ»Ò³ÏÂÒ»Ò³ 62 mode: 'unfixed', //·Öҳģʽ£¬unfixed£º²»¹Ì¶¨Ò³ÂëÊýÁ¿£¬fixed£º¹Ì¶¨Ò³ÂëÊýÁ¿ 63 count: 4, //modeΪunfixedʱÏÔʾµ±Ç°Ñ¡ÖÐҳǰºóÒ³Êý£¬modeΪfixedÏÔʾҳÂë×ÜÊý 64 jump: false, //Ìø×ªµ½Ö¸¶¨Ò³Êý 65 jumpIptCls: 'jump-ipt', //Îı¾¿òÄÚÈÝ 66 jumpBtnCls: 'jump-btn', //Ìø×ª°´Å¥ 67 jumpBtn: 'Ìø×ª', //Ìø×ª°´Å¥Îı¾ 68 callback: function () {} //»Øµ÷ 69 }; 70 71 var Pagination = function (element, options) { 72 //È«¾Ö±äÁ¿ 73 var opts = options, //ÅäÖà 74 current, //µ±Ç°Ò³ 75 $document = $(document), 76 $obj = $(element); //ÈÝÆ÷ 77 78 /** 79 * ÉèÖÃ×ÜÒ³Êý 80 * @param {int} page Ò³Âë 81 * @return opts.pageCount ×ÜÒ³ÊýÅäÖà 82 */ 83 this.setPageCount = function (page) { 84 return opts.pageCount = page; 85 }; 86 87 /** 88 * »ñÈ¡×ÜÒ³Êý 89 * Èç¹ûÅäÖÃÁË×ÜÌõÊýºÍÿҳÏÔʾÌõÊý£¬½«»á×Ô¶¯¼ÆËã×ÜÒ³Êý²¢ÂÔ¹ý×ÜÒ³ÊýÅäÖ㬷´Ö® 90 * @return {int} ×ÜÒ³Êý 91 */ 92 this.getPageCount = function () { 93 return opts.totalData && opts.showData ? Math.ceil(parseInt(opts.totalData) / opts.showData) : opts.pageCount; 94 }; 95 96 /** 97 * »ñÈ¡µ±Ç°Ò³ 98 * @return {int} µ±Ç°Ò³Âë 99 */ 100 this.getCurrent = function () { 101 return current; 102 }; 103 104 /** 105 * Ìî³äÊý¾Ý 106 * @param {int} Ò³Âë 107 */ 108 this.filling = function (index) { 109 var html = ''; 110 current = parseInt(index) || parseInt(opts.current); //µ±Ç°Ò³Âë 111 var pageCount = this.getPageCount(); //»ñÈ¡µÄ×ÜÒ³Êý 112 switch (opts.mode) { //ÅäÖÃģʽ 113 case 'fixed': //¹Ì¶¨°´Å¥Ä£Ê½ 114 html += '<a href="javascript:;" class="' + opts.prevCls + '">' + opts.prevContent + '</a>'; 115 if (opts.coping) { 116 var home = opts.coping && opts.homePage ? opts.homePage : '1'; 117 html += '<a href="javascript:;" data-page="1">' + home + '</a>'; 118 } 119 var start = current >
119 opts.count - 1 ? current + opts.count - 1 > pageCount ? current - (opts.count - (pageCount - current)) : current - 2 : 1; 120 var end = current + opts.count - 1 > pageCount ? pageCount : start + opts.count; 121 for (; start <= end; start++) { 122 if (start != current) { 123 html += '<a href="javascript:;" data-page="' + start + '">' + start + '</a>'; 124 } else { 125 html += '<span class="' + opts.activeCls + '">' + start + '</span>'; 126 } 127 } 128 if (opts.coping) { 129 var _end = opts.coping && opts.endPage ? opts.endPage : pageCount; 130 html += '<a href="javascript:;" data-page="' + pageCount + '">' + _end + '</a>'; 131 } 132 html += '<a href="javascript:;" class="' + opts.nextCls + '">' + opts.nextContent + '</a>'; 133 break; 134 case 'unfixed': //²»¹Ì¶¨°´Å¥Ä£Ê½ 135 if (opts.keepShowPN || current > 1) { //ÉÏÒ»Ò³ 136 html += '<a href="javascript:;" class="' + opts.prevCls + '">' + opts.prevContent + '</a>'; 137 } else { 138 if (opts.keepShowPN == false) { 139 $obj.find('.' + opts.prevCls) && $obj.find('.' + opts.prevCls).remove(); 140 } 141 } 142 if (current >= opts.count + 2 && current != 1 && pageCount != opts.count) { 143 var home = opts.coping && opts.homePage ? opts.homePage : '1'; 144 html += opts.coping ? '<a href="javascript:;" data-page="1">' + home + '</a><span>...</span>' : ''; 145 } 146 var start = (current - opts.count) <= 1 ? 1 : (current - opts.count); 147 var end = (current + opts.count) >= pageCount ? pageCount : (current + opts.count); 148 for (; start <= end; start++) { 149 if (start <= pageCount && start >= 1) { 150 if (start != current) { 151 html += '<a href="javascript:;" data-page="' + start + '">' + start + '</a>'; 152 } else { 153 html += '<span class="' + opts.activeCls + '">' + start + '</span>'; 154 } 155 } 156 } 157 if (current + opts.count < pageCount && current >= 1 && pageCount > opts.count) { 158 var end = opts.coping && opts.endPage ? opts.endPage : pageCount; 159 html += opts.coping ? '<span>...</span><a href="javascript:;" data-page="' + pageCount + '">' + end + '</a>' : ''; 160 } 161 if (opts.keepShowPN || current < pageCount) { //ÏÂÒ»Ò³ 162 html += '<a href="javascript:;" class="' + opts.nextCls + '">' + opts.nextContent + '</a>'; 163 } else { 164 if (opts.keepShowPN == false) { 165 $obj.find('.' + opts.nextCls) && $obj.find('.' + opts.nextCls).remove(); 166 } 167 } 168 break; 169 case 'easy': //¼òµ¥Ä£Ê½ 170 break; 171 default: 172 } 173 html += opts.jump ? '<input type="text" class="' + opts.jumpIptCls + '"><a href="javascript:;" class="' + opts.jumpBtnCls + '">' + opts.jumpBtn + '</a>' : ''; 174 $obj.empty().html(html); 175 }; 176 177 //°ó¶¨Ê¼þ 178 this.eventBind = function () { 179 var that = this; 180 var pageCount = that.getPageCount(); //×ÜÒ³Êý 181 var index = 1; 182 $obj.off().on('click', 'a', function () { 183 if ($(this).hasClass(opts.nextCls)) { 184 if ($obj.find('.' + opts.activeCls).text() >= pageCount) { 185 $(this).addClass('disabled'); 186 return false; 187 } else { 188 index = parseInt($obj.find('.' + opts.activeCls).text()) + 1; 189 } 190 } else if ($(this).hasClass(opts.prevCls)) { 191 if ($obj.find('.' + opts.activeCls).text() <= 1) { 192 $(this).addClass('disabled'); 193 return false; 194 } else { 195 index = parseInt($obj.find('.' + opts.activeCls).text()) - 1; 196 } 197 } else if ($(this).hasClass(opts.jumpBtnCls)) { 198 if ($obj.find('.' + opts.jumpIptCls).val() !== '') { 199 index = parseInt($obj.find('.' + opts.jumpIptCls).val()); 200 } else { 201 return; 202 } 203 } else { 204 index = parseInt($(this).data('page')); 205 } 206 that.filling(index); 207 typeof opts.callback === 'function' && opts.callback(that); 208 }); 209 //ÊäÈëÌø×ªµÄÒ³Âë 210 $obj.on('input propertychange', '.' + opts.jumpIptCls, function () { 211 var $this = $(this); 212 var val = $this.val(); 213 var reg = /[^\d]/g; 214 if (reg.test(val)) $this.val(val.replace(reg, '')); 215 (parseInt(val) > pageCount) && $this.val(pageCount); 216 if (parseInt(val) === 0) $this.val(1); //×îСֵΪ1 217 }); 218 //»Ø³µÌø×ªÖ¸¶¨Ò³Âë 219 $document.keydown(function (e) { 220 if (e.keyCode == 13 && $obj.find('.' + opts.jumpIptCls).val()) { 221 var index = parseInt($obj.find('.' + opts.jumpIptCls).val()); 222 that.filling(index); 223 typeof opts.callback === 'function' && opts.callback(that); 224 } 225 }); 226 }; 227 228 //³õʼ»¯ 229 this.init = function () { 230 this.filling(opts.current); 231 this.eventBind(); 232 if (opts.isHide && this.getPageCount() == '1' || this.getPageCount() == '0') { 233 $obj.hide(); 234 } else { 235 $obj.show(); 236 } 237 }; 238 this.init(); 239 }; 240 241 $.fn.pagination = function (parameter, callback) { 242 if (typeof parameter == 'function') { //ÖØÔØ 243 callback = parameter; 244 parameter = {}; 245 } else { 246 parameter = parameter || {}; 247 callback = callback || function () {}; 248 } 249 var options = $.extend({}, defaults, parameter); 250 return this.each(function () { 251 var pagination = new Pagination(this, options); 252 callback(pagination); 253 }); 254 }; 255 256}));
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.