1(function($){ 2 3$.fn.acLoadmore = function(params) { 4 var config = { 5 container: '', 6 wp_query: { 7 page: 1, 8 post_type: 'post', 9 }, 10 done: function(){}, 11 fail: function(){}, 12 always: function(){}, 13 }; 14 15 config = $.extend(true, config, params); 16 17 if (config.wp_query.post_type=='post') { 18 config.wp_query.post_type = 'posts'; 19 } else if (config.wp_query.post_type=='page') { 20 config.wp_query.post_type = 'pages'; 21 } 22 23 var $button = this; 24 var $container = $(config.container); 25 var endpoint = wpApiSettings.root + 'wp/v2/' + config.wp_query.post_type; 26 27 $button.on('click', function(e){ 28 e.preventDefault(); 29 30 $container.addClass('loading'); 31 $button.addClass('loading'); 32 33 $.ajax({ 34 url: endpoint, 35 method: 'GET', 36 dataType: 'json', 37 beforeSend: function(xhr){ 38 xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce ); 39 }, 40 data: config.wp_query, 41 }).done(function(response, textStatus, request) { 42 43 $.each(response, function(index, item) { 44 $container.append(item.tmp); 45 }); 46 47 var totalPages = request.getResponseHeader('X-WP-TotalPages'); 48 49 if(config.wp_query.page>=parseInt(totalPages)) { 50 $button.hide(); 51 } else { 52 $button.show(); 53 } 54 55 config.done(); 56 57 }).fail(function(response){ 58 59 console.log( response.responseJSON.message ); 60 61 config.fail(); 62 63 }).always(function(){ 64 65 $container.removeClass('loading'); 66 $button.removeClass('loading'); 67 config.wp_query.page++; 68 69 config.always(); 70 71 }); 72 73 }); 74 75 $('.archive-event-list-filter .btn-submit').on('click', function(e){ 76 e.preventDefault(); 77 78 config.wp_query.page = 1; 79 config.wp_query.event_categories = $('[name="topic-areas"]').val(); 80 config.wp_query.str_start_date = $('.event-start-date').val(); 81 config.wp_query.str_end_date = $('.event-end-date').val(); 82 83 $container.html(''); 84 85 $button.trigger('click'); 86 }) 87 88 $button.trigger('click'); 89} 90})(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.