PageSourceSearch

https://gliver.ru/local/templates/gliver_new/js/pagination.js?16667832848388

js gliver.ru collected 2026-10-07 08:16:27 UTC 8,388 bytes, 221 lines download raw bytes

1/*!
2 * Pagination v1.4.1 (https://github.com/nashaofu/pagination)
3 * Copyright 2016 nashaofu
4 * Licensed under MIT
5 */
6(function (factory) {
7    "use strict";
8    if (typeof define === "function" && define.amd) {
9        /** AMD规范模块调用 */
10        define(["jquery"], factory);
11    } else if (typeof define === "function" && define.cmd) {
12        /** CMD规范模块调用 */
13        define(function (require, exports, module) {
14            factory(require("jquery"));
15        });
16    } else {
17        /** 在浏览器环境下 */
18        factory(jQuery);
19    }
20})(function ($) {
21    'use strict';
22    /**
23     * 分页按钮构造函数
24     * @param {[type]} $target [description]
25     * @param {[type]} options [description]
26     */
27    var Pagination = function ($target, options) {
28        this.$target = $target;
29        this.options = $.extend({}, Pagination.DEFAULTS, this.$target.data("pagination"), typeof options == "object" && options);
30        this.init();
31    };
32    // 插件版本号
33    Pagination.VERSION = "1.4.0";
34    // 插件默认值
35    Pagination.DEFAULTS = {
36        total: 1, // 数据总数
37        current: 1, // 当前页码
38        length: 10, // 每页数量
39        size: 2, // 当前页码两边显示页码数量
40        prev: "<", // 上一页默认符号
41        next: ">", // 下一页默认符号
42        click: function (e) { } //点击回调函数
43    };
44    // 插件原型方法
45    Pagination.prototype = {
46        /**
47         * 插件初始化
48         * 对数据进行分析和对数据的标准化处理
49         * @return {[type]} [description]
50         */
51        init: function () {
52            if (this.options.total < 1) {
53                this.options.total = 1;
54            }
55            if (this.options.current < 1) {
56                this.options.current = 1;
57            }
58            if (this.options.length < 1) {
59                this.options.length = 1;
60            }
61            if (this.options.current > Math.ceil(this.options.total / this.options.length)) {
62                this.options.current = Math.ceil(this.options.total / this.options.length);
63            }
64            if (this.options.size < 1) {
65                this.options.size = 1;
66            }
67            if ('function' === typeof this.options.ajax) {
68                var me = this;
69                this.options.ajax({
70                    current: me.options.current,
71                    length: me.options.length,
72                    total: me.options.total
73                }, function (options) {
74                    return me.refresh(options);
75                }, me.$target);
76            } else {
77                this.render();
78            }
79            this.onClick();
80        },
81        /**
82         * 渲染分页按钮
83         * @return {[type]} [description]
84         */
85        render: function () {
86            var options = this.options,
87                $target = this.$target;
88            $target.empty();
89            // 上一页
90            $target.append('<li><a herf="javascript:void(0)" data-page="prev">' + options.prev + '</a></li>');
91            var page = this.getPages();
92            if (page.start > 1) {
93                $target.append('<li><a herf="javascript:void(0)" data-page="' + 1 + '">' + 1 + '</a></li>');
94                $target.append('<li><span>...</span></li>');
95
96            }
97            // 生成中间页码
98            for (var i = page.start; i <= page.end; i++) {
99                $target.append('<li><a herf="javascript:void(0)" data-page="' + i + '">' + i + '</a></li>');
100            }
101            if (page.end < Math.ceil(options.total / options.length)) {
102                $target.append('<li><span>...</span></li>');
103                $target.append('<li><a herf="javascript:void(0)" data-page="' + Math.ceil(options.total / options.length) + '">' + Math.ceil(options.total / options.length) + '</a></li>');
104            }
105            // 下一页
106            $target.append('<li><a herf="javascript:void(0)" data-page="next">' + options.next + '</a></li>');
107            // 设置当前页样式
108            $target.find('li>a[data-page="' + options.current + '"]').parent().addClass('active');
109            // 设置上一页样式
110            if (options.current <= 1) {
111                $target.find('li>a[data-page="prev"]').parent().addClass("disabled");
112            }
113            // 设置下一页样式
114            if (options.current >= Math.ceil(options.total / options.length)) {
115                $target.find('li>a[data-page="next"]').parent().addClass("disabled");
116            }
117        },
118        /**
119         * 根据插件的参数获取分页页码渲染数据
120         * @return {[type]} [description]
121         */
122        getPages: function () {
123            var $target = this.$target,
124                options = this.options,
125                start = options.current - options.size,
126                end = options.current + options.size;
127            // 获取开始页码
128            if (options.current >= Math.ceil(options.total / options.length) - options.size) {
129                start -= options.current - Math.ceil(options.total / options.length) + options.size;
130            }
131            // 获取结束页码
132            if (options.current <= options.size) {
133                end += options.size - options.current + 1;
134            }
135            // 起始页码不得小于等于1
136            if (start < 1) {
137                start = 1;
138            }
139            // 终止页码不得大于等于总页数
140            if (end > Math.ceil(options.total / options.length)) {
141                end = Math.ceil(options.total / options.length);
142            }
143            var pages = {
144                start: start,
145                end: end
146            }
147            return pages;
148        },
149        /**
150         * 页码点击事件
151         * @return {[type]} [description]
152         */
153        onClick: function () {
154            var $target = this.$target,
155                options = this.options,
156                me = this;
157            $target.off('click');
158            $target.on('click', '>li>a[data-page]', function (e) {
159                if ($(this).parent().hasClass('disabled') || $(this).parent().hasClass('active')) {
160                    return
161                }
162                var button = $(this).data("page");
163                switch (button) {
164                    case 'prev': // 上一页
165                        if (options.current > 1) {
166                            options.current--;
167                        }
168                        break;
169                    case 'next': // 下一页
170                        if (options.current < Math.ceil(options.total)) {
171                            options.current++;
172                        }
173                        break;
174                    default:
175                        button = parseInt(button);
176                        if (!isNaN(button)) {
177                            options.current = parseInt(button);
178                        }
179                        break;
180                }
181                var temp = {
182                    current: options.current,
183                    length: options.length,
184                    total: options.total
185                }
186                if ('function' === typeof options.ajax) {
187                    options.ajax(temp, function (options) {
188                        return me.refresh(options);
189                    }, $target);
190                } else {
191                    me.render();
192                }
193                // 返回当前页和页码列表jQuery对象
194                options.click(temp, $target);
195            });
196        },
197        /**
198         * 刷新分页按钮方法
199         * @param  {[object]} options [description]
200         * @return {[type]}         [description]
201         */
202        refresh: function (options) {
203            if ('object' === typeof options) {
204                if (options.total) {
205                    this.options.total = options.total;
206                }
207                if (options.length) {
208                    this.options.length = options.length;
209                }
210            }
211            this.render();
212        }
213    };
214    // 定义为jQuery插件
215    $.fn.pagination = function (options) {
216        this.each(function () {
217            $(this).data("pagination", new Pagination($(this), options));
218        });
219        return this;
220    }
221});

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.