1/** 2 * Weather widget loader. 3 * 4 * Finds every `.gc-weather-async` placeholder on the page (rendered 5 * by the [greatchile_weather] shortcode and the matching block) and 6 * fetches the actual forecast HTML via the 7 * `greatchile_weather_loader` AJAX handler. Each placeholder reads 8 * its post id / limit / format from data attributes so multiple 9 * widgets on one page (rare but possible) each ask for their own 10 * forecast. 11 * 12 * Why an AJAX hop instead of inline rendering: the rendered HTML 13 * embeds the current hour / day, but full-page caches like W3TC 14 * would freeze whichever was current when the page was first built. 15 * Splitting the dynamic part into a per-visitor request lets the 16 * server-side hourly transient drive what visitors see, regardless 17 * of how stale the wrapping page-cache entry is. 18 */ 19jQuery(function ($) { 20 $('.gc-weather-async').each(function () { 21 var $el = $(this); 22 if ($el.data('gcWeatherLoaded')) return; 23 $el.data('gcWeatherLoaded', true); 24 25 var postId = parseInt($el.attr('data-post-id'), 10) || 0; 26 if (postId <= 0) return; 27 28 $.post(greatchile_weather_loader.ajaxurl, { 29 action: 'greatchile_weather_loader', 30 post_id: postId, 31 limit: parseInt($el.attr('data-limit'), 10) || 7, 32 format: $el.attr('data-format') || 'full' 33 }).done(function (response) { 34 if (response && response.success && response.data && response.data.html) { 35 $el.replaceWith(response.data.html); 36 } else { 37 // API failed / no locality data â leave a quiet empty 38 // container so layout doesn't reflow with a broken 39 // state. Console-only signal for debugging. 40 $el.empty(); 41 if (window.console && console.debug) { 42 console.debug('gc-weather: no forecast for post ' + postId); 43 } 44 } 45 }).fail(function () { 46 $el.empty(); 47 }); 48 }); 49});
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.