1/** 2 * Font: https://www.jqueryscript.net/loading/Load-More-Pagination-jQuery-loadMoreResults.html 3 * Load More Results v1.0.0 4 * 5 * Options: 6 * - tag (object): 7 * - name (string) 8 * - class (string) 9 * - displayedItems (int) 10 * - showItems (int) 11 * - button (object): 12 * - class (string) 13 * - text (string) 14*/ 15 16(function ($) { 17 'use strict'; 18 19 $.fn.loadMoreResults = function (options) { 20 21 var defaults = { 22 tag: { 23 name: 'div', 24 'class': 'item' 25 }, 26 displayedItems: 5, 27 showItems: 5, 28 button: { 29 'class': 'btn-load-more', 30 text: 'Load More' 31 } 32 }; 33 if(options.button){ 34 defaults.button = options.button; 35 } 36 var opts = $.extend(true, {}, defaults, options); 37 var alphaNumRE = /^[A-Za-z][-_A-Za-z0-9]+$/; 38 var numRE = /^[0-9]+$/; 39 40 $.each(opts, function validateOptions(key, val) { 41 if (key === 'tag') { 42 formatCheck(key, val, 'name', 'string'); 43 formatCheck(key, val, 'class', 'string'); 44 } 45 if (key === 'displayedItems') { 46 formatCheck(key, val, null, 'number'); 47 } 48 if (key === 'showItems') { 49 formatCheck(key, val, null, 'number'); 50 } 51 if (key === 'button') { 52 formatCheck(key, val, 'class', 'string'); 53 } 54 }); 55 56 function formatCheck(key, val, prop, typ) { 57 if (prop !== null && typeof prop !== 'object') { 58 if (typeof val[prop] !== typ || String(val[prop]).match(typ == 'string' ? alphaNumRE : numRE) === null) { 59 opts[key][prop] = defaults[key][prop]; 60 } 61 } else { 62 if (typeof val !== typ || String(val).match(typ == 'string' ? alphaNumRE : numRE) === null) { 63 opts[key] = defaults[key]; 64 } 65 } 66 }; 67 68 return this.each(function (index, element) { 69 var $list = $(element), 70 lc = $list.find(' > ' + opts.tag.name + '.' + opts.tag.class).length, 71 dc = parseInt(opts.displayedItems), 72 sc = parseInt(opts.showItems); 73 74 $list.find(' > ' + opts.tag.name + '.' + opts.tag.class + ':lt(' + dc + ')').css("display", "inline-block"); 75 $list.find(' > ' + opts.tag.name + '.' + opts.tag.class + ':gt(' + (dc - 1) + ')').css("display", "none"); 76 77 if($('.btn-load-more').length == 0) 78 $list.parent().append('<div class="text-center"><button class="btn-view ' + opts.button.class + '">' + opts.button.text + '</button></div>'); 79 80 $list.parent().on("click", ".btn-view", function (e) { 81 e.preventDefault(); 82 dc = (dc + sc <= lc) ? dc + sc : lc; 83 84 $list.find(' > ' + opts.tag.name + '.' + opts.tag.class + ':lt(' + dc + ')').fadeIn(); 85 if (dc == lc) { 86 $(this).hide(); 87 } 88 }); 89 }); 90 91 }; 92})(jQuery);
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.