/** * pagination鍒嗛〉鎻掍欢 * @version 1.3.1 * @author mss * @url http://maxiaoxiang.com/jQuery-plugins/plugins/pagination.html * * @璋冪敤鏂规硶 * $(selector).pagination(); */ ; (function (factory) { if (typeof define === "function" && (define.amd || define.cmd) && !jQuery) { // AMD鎴朇MD define(["jquery"], factory); } else if (typeof module === 'object' && module.exports) { // Node/CommonJS module.exports = function (root, jQuery) { if (jQuery === undefined) { if (typeof window !== 'undefined') { jQuery = require('jquery'); } else { jQuery = require('jquery')(root); } } factory(jQuery); return jQuery; }; } else { //Browser globals factory(jQuery); } }(function ($) { //閰嶇疆鍙傛暟 var defaults = { totalData: 0, //鏁版嵁鎬绘潯鏁 showData: 0, //姣忛〉鏄剧ず鐨勬潯鏁 pageCount: 9, //鎬婚〉鏁?榛樿涓? current: 1, //褰撳墠绗嚑椤 prevCls: 'prev', //涓婁竴椤礳lass nextCls: 'next', //涓嬩竴椤礳lass prevContent: '涓婁竴椤?, //涓婁竴椤靛唴瀹 nextContent: '涓嬩竴椤?, //涓嬩竴椤靛唴瀹 normalCls: 'page', //鏅€氶〉class activeCls: 'page on', //褰撳墠椤甸€変腑鐘舵€ coping: true, //棣栭〉鍜屽熬椤 isHide: true, //褰撳墠椤垫暟涓?椤垫垨鑰?椤垫椂涓嶆樉绀哄垎椤 homePage: '', //棣栭〉鑺傜偣鍐呭 endPage: '', //灏鹃〉鑺傜偣鍐呭 keepShowPN: false, //鏄惁涓€鐩存樉绀轰笂涓€椤典笅涓€椤 count: 3, //褰撳墠椤靛墠鍚庡垎椤典釜鏁 jump: false, //璺宠浆鍒版寚瀹氶〉鏁 jumpIptCls: 'propertychange', //鏂囨湰妗嗗唴瀹 jumpBtnCls: 'jump-page-button', //璺宠浆鎸夐挳 jumpBtn: '璺宠浆', //璺宠浆鎸夐挳鏂囨湰 callback: function () { } //鍥炶皟 }; var paramPageKeys = ""; var paramPages = ""; var getQueryString = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeURI(r[2]); return null; } var Pagination = function (element, options) { //鍏ㄥ眬鍙橀噺 var opts = options, //閰嶇疆 current, //褰撳墠椤 $document = $(document), $obj = $(element); //瀹瑰櫒 if (getQueryString("key")) { paramPageKeys = "&key=" + getQueryString("key"); } else { paramPageKeys = ""; } if (getQueryString("pages")) { paramPages = "&pages=" + getQueryString("pages"); } else { paramPages = "&pages=9"; } /** * 璁剧疆鎬婚〉鏁 * @param int page 椤电爜 * @return opts.pageCount 鎬婚〉鏁伴厤缃 */ this.setPageCount = function (page) { return opts.pageCount = page; }; /** * 鑾峰彇鎬婚〉鏁 * 濡傛灉閰嶇疆浜嗘€绘潯鏁板拰姣忛〉鏄剧ず鏉℃暟锛屽皢浼氳嚜鍔ㄨ绠楁€婚〉鏁板苟鐣ヨ繃鎬婚〉鏁伴厤缃紝鍙嶄箣 * @return int p 鎬婚〉鏁 */ this.getPageCount = function () { return opts.totalData || opts.showData ? Math.ceil(parseInt(opts.totalData) / opts.showData) : opts.pageCount; }; /** * 鑾峰彇鎬绘潯鏁 /** * 鑾峰彇褰撳墠椤 * @return int current 褰撳墠绗嚑椤 */ this.getCurrent = function () { return current; }; /** * 濉厖鏁版嵁 * @param int index 椤电爜 */ this.filling = function (index) { var html = ''; current = index || opts.current; //褰撳墠椤电爜 var pageCount = this.getPageCount(); //鑾峰彇鐨勬€婚〉鏁 html += '
'; if (current > 1) { html += ''; html += ''; html += ''; html += ''; html += ''; html += ' '; } else { html += ''; html += ''; html += ''; html += ' '; html += ''; html += ''; } //if (opts.keepShowPN && current > 1) {//涓婁竴椤 // html += ' '; //} else { // //if (opts.keepShowPN == false) { // // $obj.find('.' + opts.prevCls) && $obj.find('.' + opts.prevCls).remove(); // //} // //else { // // html += ' '; // //} //} if (current >= opts.count + 2 && current != 1 && pageCount != opts.count) { var home = opts.coping && opts.homePage ? opts.homePage : '1'; html += opts.coping ? '...' : ''; } html += ''; var end = current + opts.count; var start = ''; //淇鍒版渶鍚庝竴椤垫椂姣旂涓€椤靛皯鏄剧ず涓ら〉 start = current === pageCount ? current - opts.count - 2 : current - opts.count; ((start > 1 && current < opts.count) || current == 1) && end++; (current > pageCount - opts.count && current >= pageCount) && start++; for (; start <= end; start++) { if (start <= pageCount && start >= 1) { if (start != current) { html += '' + start + ''; } else { html += '' + start + ''; } } } html += ''; //html += ' '; //if (opts.keepShowPN && current < pageCount) {//涓嬩竴椤 // html += ''; //} //else { // //if (opts.keepShowPN == false) { // // $obj.find('.' + opts.nextCls) && $obj.find('.' + opts.nextCls).remove(); // //} // //else { // // html += ''; // //} //} if (parseInt(current + 1) > pageCount) { html += ''; html += ''; html += ' '; html += ''; html += ''; html += ''; } else { html += ''; html += ''; html += ' '; html += ''; html += ''; html += ''; } html += ' '; if (opts.jump) { html += '