1/* global jQuery, mptbm_taxi_list_i18n */ 2(function ($) { 3 'use strict'; 4 5 $(document).on('click', '[data-taxilist-view]', function () { 6 var $btn = $(this); 7 var view = $btn.data('taxilist-view'); 8 var $root = $btn.closest('.mptbm_taxilist'); 9 10 $root.attr('data-view', view); 11 $root.find('[data-taxilist-view]').removeClass('is-active'); 12 $btn.addClass('is-active'); 13 14 try { 15 localStorage.setItem('mptbm_taxilist_view', view); 16 } catch (e) { 17 // Private browsing / storage disabled - the toggle still works, 18 // it just won't be remembered next visit. 19 } 20 }); 21 22 $(document).on('click', '[data-taxilist-load-more]', function () { 23 var $btn = $(this); 24 if ($btn.prop('disabled')) { 25 return; 26 } 27 var $root = $btn.closest('.mptbm_taxilist'); 28 var $grid = $root.find('[data-taxilist-grid]'); 29 var offset = parseInt($root.attr('data-offset'), 10) || 0; 30 var perPage = parseInt($root.attr('data-per-page'), 10) || 20; 31 32 $btn.prop('disabled', true); 33 $btn.find('[data-taxilist-spinner]').removeAttr('hidden'); 34 35 $.post(mptbm_taxi_list_i18n.ajax_url, { 36 action: 'mptbm_taxi_list_load_more', 37 nonce: mptbm_taxi_list_i18n.nonce, 38 offset: offset, 39 per_page: perPage 40 }).done(function (response) { 41 if (!response || !response.success || !response.data) { 42 return; 43 } 44 $grid.append(response.data.html); 45 46 var shown = parseInt(response.data.shown, 10) || 0; 47 var total = parseInt(response.data.total, 10) || 0; 48 $root.attr('data-offset', shown); 49 50 if (shown >= total) { 51 $root.find('[data-taxilist-footer]').remove(); 52 } 53 }).always(function () { 54 $btn.prop('disabled', false); 55 $btn.find('[data-taxilist-spinner]').attr('hidden', true); 56 }); 57 }); 58 59 // Restore the viewer's last-chosen view (grid/list), per browser - a 60 // convenience only; without it the shortcode's own default still renders. 61 $(function () { 62 var saved; 63 try { 64 saved = localStorage.getItem('mptbm_taxilist_view'); 65 } catch (e) { 66 saved = null; 67 } 68 if (saved !== 'grid' && saved !== 'list') { 69 return; 70 } 71 $('.mptbm_taxilist').each(function () { 72 var $root = $(this); 73 $root.attr('data-view', saved); 74 $root.find('[data-taxilist-view]').removeClass('is-active'); 75 $root.find('[data-taxilist-view="' + saved + '"]').addClass('is-active'); 76 }); 77 }); 78})(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.