PageSourceSearch

http://www.stoppolygamy.com/statics/zhsite/js/jquery.pagination.js

js stoppolygamy.com collected 2026-10-04 10:55:39 UTC 12,007 bytes, 256 lines download raw bytes

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鏄垵濮嬪寲璋冪敤锛宱ption閲岀殑callback鏄偣鍑婚〉鐮佸悗璋冪敤
11 * 
12 * -- example --
13 * $(selector).pagination({
14 *     ... // 閰嶇疆鍙傛暟
15 *     callback: function(api) {
16 *         console.log('鐐瑰嚮椤电爜璋冪敤璇ュ洖璋?); //鍒囨崲椤电爜鏃舵墽琛屼竴娆″洖璋?
17 *     }
18 * }, function(){
19 *     console.log('鍒濆鍖?); //鎻掍欢鍒濆鍖栨椂璋冪敤璇ユ柟娉曪紝姣斿璇锋眰绗竴娆℃帴鍙f潵鍒濆鍖栧垎椤甸厤缃?
20 * });
21 */
22;
23(function (factory) {
24    if (typeof define === "function" && (define.amd || define.cmd) && !jQuery) {
25        // AMD鎴朇MD
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, //鎬婚〉鏁?榛樿涓?
51        current: 1, //褰撳墠绗嚑椤?
52        prevCls: 'prev', //涓婁竴椤礳lass
53        nextCls: 'next', //涓嬩竴椤礳lass
54        prevContent: '<', //涓婁竴椤靛唴瀹?
55        nextContent: '>', //涓嬩竴椤靛唴瀹?
56        activeCls: 'active', //褰撳墠椤甸€変腑鐘舵€?
57        coping: false, //棣栭〉鍜屽熬椤?
58        isHide: false, //褰撳墠椤垫暟涓?椤垫垨鑰?椤垫椂涓嶆樉绀哄垎椤?
59        homePage: '', //棣栭〉鑺傜偣鍐呭
60        endPage: '', //灏鹃〉鑺傜偣鍐呭
61        keepShowPN: false, //鏄惁涓€鐩存樉绀轰笂涓€椤典笅涓€椤?
62        mode: 'unfixed', //鍒嗛〉妯″紡锛寀nfixed锛氫笉鍥哄畾椤电爜鏁伴噺锛宖ixed锛氬浐瀹氶〉鐮佹暟閲?
63        count: 4, //mode涓簎nfixed鏃舵樉绀哄綋鍓嶉€変腑椤靛墠鍚庨〉鏁帮紝mode涓篺ixed鏄剧ず椤电爜鎬绘暟
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 > 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.