PageSourceSearch

https://llamasofatlanta.com/statics/zhsite/js/jquery.pagination.js

js llamasofatlanta.com collected 2026-10-02 23:49:25 UTC 11,448 bytes, 256 lines download raw bytes

vendor: 2,010 bytes, lines 1-58
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是初始化调用,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 > 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:;
159" 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.