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.