vendor: 10,770 bytes, lines 1-375
1/*! 2 * jQuery pagination plugin v1.4.1 3 * http://esimakin.github.io/twbs-pagination/ 4 * 5 * Copyright 2014-2016, Eugene Simakin 6 * Released under Apache 2.0 license 7 * http://apache.org/licenses/LICENSE-2.0.html 8 */ 9(function ($, window, document, undefined) { 10 "use strict"; 11 12 var old = $.fn.twbsPagination; 13 14 // PROTOTYPE AND CONSTRUCTOR 15 16 var TwbsPagination = function (element, options) { 17 this.$element = $(element); 18 this.options = $.extend({}, $.fn.twbsPagination.defaults, options); 19 20 if ( 21 this.options.startPage < 1 || 22 this.options.startPage > this.options.totalPages 23 ) { 24 throw new Error("Start page option is incorrect"); 25 } 26 27 this.options.totalPages = parseInt(this.options.totalPages); 28 if (isNaN(this.options.totalPages)) { 29 throw new Error("Total pages option is not correct!"); 30 } 31 32 this.options.visiblePages = parseInt(this.options.visiblePages); 33 if (isNaN(this.options.visiblePages)) { 34 throw new Error("Visible pages option is not correct!"); 35 } 36 37 if (this.options.onPageClick instanceof Function) { 38 this.$element.first().on("page", this.options.onPageClick); 39 } 40 41 // hide if only one page exists 42 if (this.options.hideOnlyOnePage && this.options.totalPages == 1) { 43 this.$element.trigger("page", 1); 44 return this; 45 } 46 47 if (this.options.totalPages < this.options.visiblePages) { 48 this.options.visiblePages = this.options.totalPages; 49 } 50 51 if (this.options.href) { 52 this.options.startPage = this.getPageFromQueryString(); 53 if (!this.options.startPage) { 54 this.options.startPage = 1; 55 } 56 } 57 58 var tagName = 59 typeof this.$element.prop === "function" 60 ? this.$element.prop("tagName") 61 : this.$element.attr("tagName"); 62 63 if (tagName === "UL") { 64 this.$listContainer = this.$element; 65 } else { 66 this.$listContainer = $("<ul></ul>"); 67 } 68 69 this.$listContainer.addClass(this.options.paginationClass); 70 71 if (tagName !== "UL") { 72 this.$element.append(this.$listContainer); 73 } 74 75 if (this.options.initiateStartPageClick) { 76 this.show(this.options.startPage); 77 } else { 78 this.currentPage = this.options.startPage; 79 this.render(this.getPages(this.options.startPage)); 80 this.setupEvents(); 81 } 82 83 return this; 84 }; 85 86 TwbsPagination.prototype = { 87 constructor: TwbsPagination, 88 89 destroy: function () { 90 this.$element.empty(); 91 this.$element.removeData("twbs-pagination"); 92 this.$element.off("page"); 93 94 return this; 95 }, 96 97 show: function (page) { 98 if (page < 1 || page > this.options.totalPages) { 99 throw new Error("Page is incorrect."); 100 } 101 this.currentPage = page; 102 103 this.render(this.getPages(page)); 104 this.setupEvents(); 105 106 this.$element.trigger("page", page); 107 108 return this; 109 }, 110 111 enable: function () { 112 this.show(this.currentPage); 113 }, 114 115 disable: function () { 116 var _this = this; 117 this.$listContainer.off("click").on("click", "li", function (evt) { 118 evt.preventDefault(); 119 }); 120 this.$listContainer.children().each(function () { 121 var $this = $(this); 122 if (!$this.hasClass(_this.options.activeClass)) { 123 $(this).addClass(_this.options.disabledClass); 124 } 125 }); 126 }, 127 128 buildListItems: function (pages) { 129 var listItems = []; 130 131 if (this.options.first) { 132 listItems.push(this.buildItem("first", 1)); 133 } 134 135 if (this.options.prev) { 136 var prev = 137 pages.currentPage > 1 138 ? pages.currentPage - 1 139 : this.options.loop 140 ? this.options.totalPages 141 : 1; 142 listItems.push(this.buildItem("prev", prev)); 143 } 144 145 for (var i = 0; i < pages.numeric.length; i++) { 146 listItems.push(this.buildItem("page", pages.numeric[i])); 147 } 148 149 if (this.options.next) { 150 var next = 151 pages.currentPage < this.options.totalPages 152 ? pages.currentPage + 1 153 : this.options.loop 154 ? 1 155 : this.options.totalPages; 156 listItems.push(this.buildItem("next", next)); 157 } 158 159 if (this.options.last) { 160 listItems.push(this.buildItem("last", this.options.totalPages)); 161 } 162 163 return listItems; 164 }, 165 166 buildItem: function (type, page) { 167 var $itemContainer = $('<li onclick="scrollUp();"></li>'), 168 $itemContent = $("<a></a>"), 169 itemText = this.options[type] 170 ? this.makeText(this.options[type], page) 171 : page; 172 173 $itemContainer.addClass(this.options[type + "Class"]); 174 $itemContainer.data("page", page); 175 $itemContainer.data("page-type", type); 176 $itemContainer.append( 177 $itemContent 178 .attr("href", this.makeHref(page)) 179 .addClass(this.options.anchorClass) 180 .html(itemText) 181 ); 182 183 return $itemContainer; 184 }, 185 186 getPages: function (currentPage) { 187 var pages = []; 188 189 var half = Math.floor(this.options.visiblePages / 2); 190 var start = currentPage - half + 1 - (this.options.visiblePages % 2); 191 var end = currentPage + half; 192 193 // handle boundary case 194 if (start <= 0) { 195 start = 1; 196 end = this.options.visiblePages; 197 } 198 if (end > this.options.totalPages) { 199 start = this.options.totalPages - this.options.visiblePages + 1; 200 end = this.options.totalPages; 201 } 202 203 var itPage = start; 204 while (itPage <= end) { 205 pages.push(itPage); 206 itPage++; 207 } 208 209 return { currentPage: currentPage, numeric: pages }; 210 }, 211 212 render: function (pages) { 213 var _this = this; 214 this.$listContainer.children().remove(); 215 var items = this.buildListItems(pages); 216 $.each(items, function (key, item) { 217 _this.$listContainer.append(item); 218 }); 219 220 this.$listContainer.children().each(function () { 221 var $this = $(this), 222 pageType = $this.data("page-type"); 223 224 switch (pageType) { 225 case "page": 226 if ($this.data("page") === pages.currentPage) { 227 $this.addClass(_this.options.activeClass); 228 } 229 break; 230 case "first": 231 $this.toggleClass( 232 _this.options.disabledClass, 233 pages.currentPage === 1 234 ); 235 break; 236 case "last": 237 $this.toggleClass( 238 _this.options.disabledClass, 239 pages.currentPage === _this.options.totalPages 240 ); 241 break; 242 case "prev": 243 $this.toggleClass( 244 _this.options.disabledClass, 245 !_this.options.loop && pages.currentPage === 1 246 ); 247 break; 248 case "next": 249 $this.toggleClass( 250 _this.options.disabledClass, 251 !_this.options.loop && 252 pages.currentPage === _this.options.totalPages 253 ); 254 break; 255 default: 256 break; 257 } 258 }); 259 }, 260 261 setupEvents: function () { 262 var _this = this; 263 this.$listContainer.off("click").on("click", "li", function (evt) { 264 var $this = $(this); 265 if ( 266 $this.hasClass(_this.options.disabledClass) || 267 $this.hasClass(_this.options.activeClass) 268 ) { 269 return false; 270 } 271 // Prevent click event if href is not set. 272 !_this.options.href && evt.preventDefault(); 273 _this.show(parseInt($this.data("page"))); 274 }); 275 }, 276 277 makeHref: function (page) { 278 return this.options.href ? this.generateQueryString(page) : "#"; 279 }, 280 281 makeText: function (text, page) { 282 return text 283 .replace(this.options.pageVariable, page) 284 .replace(this.options.totalPagesVariable, this.options.totalPages); 285 }, 286 getPageFromQueryString: function (searchStr) { 287 var search = this.getSearchString(searchStr), 288 regex = new RegExp(this.options.pageVariable + "(=([^&#]*)|&|#|$)"), 289 page = regex.exec(search); 290 if (!page || !page[2]) { 291 return null; 292 } 293 page = decodeURIComponent(page[2]); 294 page = parseInt(page); 295 if (isNaN(page)) { 296 return null; 297 } 298 return page; 299 }, 300 generateQueryString: function (pageNumber, searchStr) { 301 var search = this.getSearchString(searchStr), 302 regex = new RegExp(this.options.pageVariable + "=*[^&#]*"); 303 if (!search) return ""; 304 return ( 305 "?" + 306 search.replace(regex, this.options.pageVariable + "=" + pageNumber) 307 ); 308 }, 309 getSearchString: function (searchStr) { 310 var search = searchStr || window.location.search; 311 if (search === "") { 312 return null; 313 } 314 if (search.indexOf("?") === 0) search = search.substr(1); 315 return search; 316 }, 317 getCurrentPage: function () { 318 return this.currentPage; 319 }, 320 }; 321 322 // PLUGIN DEFINITION 323 324 $.fn.twbsPagination = function (option) { 325 var args = Array.prototype.slice.call(arguments, 1); 326 var methodReturn; 327 328 var $this = $(this); 329 var data = $this.data("twbs-pagination"); 330 var options = typeof option === "object" ? option : {}; 331 332 if (!data) 333 $this.data("twbs-pagination", (data = new TwbsPagination(this, options))); 334 if (typeof option === "string") 335 methodReturn = data[option].apply(data, args); 336 337 return methodReturn === undefined ? $this : methodReturn; 338 }; 339 340 $.fn.twbsPagination.defaults = { 341 totalPages: 1, 342 startPage: 1, 343 visiblePages: 5, 344 initiateStartPageClick: true, 345 hideOnlyOnePage: false, 346 href: false, 347 pageVariable: "{{page}}", 348 totalPagesVariable: "{{total_pages}}", 349 page: null, 350 first: "First", 351 prev: "Previous", 352 next: "Next", 353 last: "Last", 354 loop: false, 355 onPageClick: null, 356 paginationClass: "pagination", 357 nextClass: "page-item next", 358 prevClass: "page-item prev", 359 lastClass: "page-item last", 360 firstClass: "page-item first", 361 pageClass: "page-item", 362 activeClass: "active", 363 disabledClass: "disabled", 364 anchorClass: "page-link", 365 }; 366 367 $.fn.twbsPagination.Constructor = TwbsPagination; 368 369 $.fn.twbsPagination.noConflict = function () { 370 $.fn.twbsPagination = old; 371 return this; 372 }; 373 374 $.fn.twbsPagination.version = "1.4.1"; 375})(window.jQuery, window, document);
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.