Edit File by line
/home/barbar84/www/wp-admin/js
File: dashboard.js
* should be displayed.
[500] Fix | Delete
*/
[501] Fix | Delete
if ( templateParams.location.ip ) {
[502] Fix | Delete
/*
[503] Fix | Delete
* If the API determined the location by geolocating an IP, it will
[504] Fix | Delete
* provide events, but not a specific location.
[505] Fix | Delete
*/
[506] Fix | Delete
$locationMessage.text( __( 'Attend an upcoming event near you.' ) );
[507] Fix | Delete
[508] Fix | Delete
if ( templateParams.events.length ) {
[509] Fix | Delete
template = wp.template( 'community-events-event-list' );
[510] Fix | Delete
$results.html( template( templateParams ) );
[511] Fix | Delete
} else {
[512] Fix | Delete
template = wp.template( 'community-events-no-upcoming-events' );
[513] Fix | Delete
$results.html( template( templateParams ) );
[514] Fix | Delete
}
[515] Fix | Delete
[516] Fix | Delete
elementVisibility['#community-events-location-message'] = true;
[517] Fix | Delete
elementVisibility['.community-events-toggle-location'] = true;
[518] Fix | Delete
elementVisibility['.community-events-results'] = true;
[519] Fix | Delete
[520] Fix | Delete
} else if ( templateParams.location.description ) {
[521] Fix | Delete
template = wp.template( 'community-events-attend-event-near' );
[522] Fix | Delete
$locationMessage.html( template( templateParams ) );
[523] Fix | Delete
[524] Fix | Delete
if ( templateParams.events.length ) {
[525] Fix | Delete
template = wp.template( 'community-events-event-list' );
[526] Fix | Delete
$results.html( template( templateParams ) );
[527] Fix | Delete
} else {
[528] Fix | Delete
template = wp.template( 'community-events-no-upcoming-events' );
[529] Fix | Delete
$results.html( template( templateParams ) );
[530] Fix | Delete
}
[531] Fix | Delete
[532] Fix | Delete
if ( 'user' === initiatedBy ) {
[533] Fix | Delete
wp.a11y.speak(
[534] Fix | Delete
sprintf(
[535] Fix | Delete
/* translators: %s: The name of a city. */
[536] Fix | Delete
__( 'City updated. Listing events near %s.' ),
[537] Fix | Delete
templateParams.location.description
[538] Fix | Delete
),
[539] Fix | Delete
'assertive'
[540] Fix | Delete
);
[541] Fix | Delete
}
[542] Fix | Delete
[543] Fix | Delete
elementVisibility['#community-events-location-message'] = true;
[544] Fix | Delete
elementVisibility['.community-events-toggle-location'] = true;
[545] Fix | Delete
elementVisibility['.community-events-results'] = true;
[546] Fix | Delete
[547] Fix | Delete
} else if ( templateParams.unknownCity ) {
[548] Fix | Delete
template = wp.template( 'community-events-could-not-locate' );
[549] Fix | Delete
$( '.community-events-could-not-locate' ).html( template( templateParams ) );
[550] Fix | Delete
wp.a11y.speak(
[551] Fix | Delete
sprintf(
[552] Fix | Delete
/*
[553] Fix | Delete
* These specific examples were chosen to highlight the fact that a
[554] Fix | Delete
* state is not needed, even for cities whose name is not unique.
[555] Fix | Delete
* It would be too cumbersome to include that in the instructions
[556] Fix | Delete
* to the user, so it's left as an implication.
[557] Fix | Delete
*/
[558] Fix | Delete
/*
[559] Fix | Delete
* translators: %s is the name of the city we couldn't locate.
[560] Fix | Delete
* Replace the examples with cities related to your locale. Test that
[561] Fix | Delete
* they match the expected location and have upcoming events before
[562] Fix | Delete
* including them. If no cities related to your locale have events,
[563] Fix | Delete
* then use cities related to your locale that would be recognizable
[564] Fix | Delete
* to most users. Use only the city name itself, without any region
[565] Fix | Delete
* or country. Use the endonym (native locale name) instead of the
[566] Fix | Delete
* English name if possible.
[567] Fix | Delete
*/
[568] Fix | Delete
__( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
[569] Fix | Delete
templateParams.unknownCity
[570] Fix | Delete
)
[571] Fix | Delete
);
[572] Fix | Delete
[573] Fix | Delete
elementVisibility['.community-events-errors'] = true;
[574] Fix | Delete
elementVisibility['.community-events-could-not-locate'] = true;
[575] Fix | Delete
[576] Fix | Delete
} else if ( templateParams.error && 'user' === initiatedBy ) {
[577] Fix | Delete
/*
[578] Fix | Delete
* Errors messages are only shown for requests that were initiated
[579] Fix | Delete
* by the user, not for ones that were initiated by the app itself.
[580] Fix | Delete
* Showing error messages for an event that user isn't aware of
[581] Fix | Delete
* could be confusing or unnecessarily distracting.
[582] Fix | Delete
*/
[583] Fix | Delete
wp.a11y.speak( __( 'An error occurred. Please try again.' ) );
[584] Fix | Delete
[585] Fix | Delete
elementVisibility['.community-events-errors'] = true;
[586] Fix | Delete
elementVisibility['.community-events-error-occurred'] = true;
[587] Fix | Delete
} else {
[588] Fix | Delete
$locationMessage.text( __( 'Enter your closest city to find nearby events.' ) );
[589] Fix | Delete
[590] Fix | Delete
elementVisibility['#community-events-location-message'] = true;
[591] Fix | Delete
elementVisibility['.community-events-toggle-location'] = true;
[592] Fix | Delete
}
[593] Fix | Delete
[594] Fix | Delete
// Set the visibility of toggleable elements.
[595] Fix | Delete
_.each( elementVisibility, function( isVisible, element ) {
[596] Fix | Delete
$( element ).attr( 'aria-hidden', ! isVisible );
[597] Fix | Delete
});
[598] Fix | Delete
[599] Fix | Delete
$toggleButton.attr( 'aria-expanded', elementVisibility['.community-events-toggle-location'] );
[600] Fix | Delete
[601] Fix | Delete
if ( templateParams.location && ( templateParams.location.ip || templateParams.location.latitude ) ) {
[602] Fix | Delete
// Hide the form when there's a valid location.
[603] Fix | Delete
app.toggleLocationForm( 'hide' );
[604] Fix | Delete
[605] Fix | Delete
if ( 'user' === initiatedBy ) {
[606] Fix | Delete
/*
[607] Fix | Delete
* When the form is programmatically hidden after a user search,
[608] Fix | Delete
* bring the focus back to the toggle button so users relying
[609] Fix | Delete
* on screen readers don't lose their place.
[610] Fix | Delete
*/
[611] Fix | Delete
$toggleButton.trigger( 'focus' );
[612] Fix | Delete
}
[613] Fix | Delete
} else {
[614] Fix | Delete
app.toggleLocationForm( 'show' );
[615] Fix | Delete
}
[616] Fix | Delete
},
[617] Fix | Delete
[618] Fix | Delete
/**
[619] Fix | Delete
* Populate event fields that have to be calculated on the fly.
[620] Fix | Delete
*
[621] Fix | Delete
* These can't be stored in the database, because they're dependent on
[622] Fix | Delete
* the user's current time zone, locale, etc.
[623] Fix | Delete
*
[624] Fix | Delete
* @since 5.5.2
[625] Fix | Delete
*
[626] Fix | Delete
* @param {Array} rawEvents The events that should have dynamic fields added to them.
[627] Fix | Delete
* @param {string} timeFormat A time format acceptable by `wp.date.dateI18n()`.
[628] Fix | Delete
*
[629] Fix | Delete
* @returns {Array}
[630] Fix | Delete
*/
[631] Fix | Delete
populateDynamicEventFields: function( rawEvents, timeFormat ) {
[632] Fix | Delete
// Clone the parameter to avoid mutating it, so that this can remain a pure function.
[633] Fix | Delete
var populatedEvents = JSON.parse( JSON.stringify( rawEvents ) );
[634] Fix | Delete
[635] Fix | Delete
$.each( populatedEvents, function( index, event ) {
[636] Fix | Delete
var timeZone = app.getTimeZone( event.start_unix_timestamp * 1000 );
[637] Fix | Delete
[638] Fix | Delete
event.user_formatted_date = app.getFormattedDate(
[639] Fix | Delete
event.start_unix_timestamp * 1000,
[640] Fix | Delete
event.end_unix_timestamp * 1000,
[641] Fix | Delete
timeZone
[642] Fix | Delete
);
[643] Fix | Delete
[644] Fix | Delete
event.user_formatted_time = dateI18n(
[645] Fix | Delete
timeFormat,
[646] Fix | Delete
event.start_unix_timestamp * 1000,
[647] Fix | Delete
timeZone
[648] Fix | Delete
);
[649] Fix | Delete
[650] Fix | Delete
event.timeZoneAbbreviation = app.getTimeZoneAbbreviation( event.start_unix_timestamp * 1000 );
[651] Fix | Delete
} );
[652] Fix | Delete
[653] Fix | Delete
return populatedEvents;
[654] Fix | Delete
},
[655] Fix | Delete
[656] Fix | Delete
/**
[657] Fix | Delete
* Returns the user's local/browser time zone, in a form suitable for `wp.date.i18n()`.
[658] Fix | Delete
*
[659] Fix | Delete
* @since 5.5.2
[660] Fix | Delete
*
[661] Fix | Delete
* @param startTimestamp
[662] Fix | Delete
*
[663] Fix | Delete
* @returns {string|number}
[664] Fix | Delete
*/
[665] Fix | Delete
getTimeZone: function( startTimestamp ) {
[666] Fix | Delete
/*
[667] Fix | Delete
* Prefer a name like `Europe/Helsinki`, since that automatically tracks daylight savings. This
[668] Fix | Delete
* doesn't need to take `startTimestamp` into account for that reason.
[669] Fix | Delete
*/
[670] Fix | Delete
var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
[671] Fix | Delete
[672] Fix | Delete
/*
[673] Fix | Delete
* Fall back to an offset for IE11, which declares the property but doesn't assign a value.
[674] Fix | Delete
*/
[675] Fix | Delete
if ( 'undefined' === typeof timeZone ) {
[676] Fix | Delete
/*
[677] Fix | Delete
* It's important to use the _event_ time, not the _current_
[678] Fix | Delete
* time, so that daylight savings time is accounted for.
[679] Fix | Delete
*/
[680] Fix | Delete
timeZone = app.getFlippedTimeZoneOffset( startTimestamp );
[681] Fix | Delete
}
[682] Fix | Delete
[683] Fix | Delete
return timeZone;
[684] Fix | Delete
},
[685] Fix | Delete
[686] Fix | Delete
/**
[687] Fix | Delete
* Get intuitive time zone offset.
[688] Fix | Delete
*
[689] Fix | Delete
* `Data.prototype.getTimezoneOffset()` returns a positive value for time zones
[690] Fix | Delete
* that are _behind_ UTC, and a _negative_ value for ones that are ahead.
[691] Fix | Delete
*
[692] Fix | Delete
* See https://stackoverflow.com/questions/21102435/why-does-javascript-date-gettimezoneoffset-consider-0500-as-a-positive-off.
[693] Fix | Delete
*
[694] Fix | Delete
* @since 5.5.2
[695] Fix | Delete
*
[696] Fix | Delete
* @param {number} startTimestamp
[697] Fix | Delete
*
[698] Fix | Delete
* @returns {number}
[699] Fix | Delete
*/
[700] Fix | Delete
getFlippedTimeZoneOffset: function( startTimestamp ) {
[701] Fix | Delete
return new Date( startTimestamp ).getTimezoneOffset() * -1;
[702] Fix | Delete
},
[703] Fix | Delete
[704] Fix | Delete
/**
[705] Fix | Delete
* Get a short time zone name, like `PST`.
[706] Fix | Delete
*
[707] Fix | Delete
* @since 5.5.2
[708] Fix | Delete
*
[709] Fix | Delete
* @param {number} startTimestamp
[710] Fix | Delete
*
[711] Fix | Delete
* @returns {string}
[712] Fix | Delete
*/
[713] Fix | Delete
getTimeZoneAbbreviation: function( startTimestamp ) {
[714] Fix | Delete
var timeZoneAbbreviation,
[715] Fix | Delete
eventDateTime = new Date( startTimestamp );
[716] Fix | Delete
[717] Fix | Delete
/*
[718] Fix | Delete
* Leaving the `locales` argument undefined is important, so that the browser
[719] Fix | Delete
* displays the abbreviation that's most appropriate for the current locale. For
[720] Fix | Delete
* some that will be `UTC{+|-}{n}`, and for others it will be a code like `PST`.
[721] Fix | Delete
*
[722] Fix | Delete
* This doesn't need to take `startTimestamp` into account, because a name like
[723] Fix | Delete
* `America/Chicago` automatically tracks daylight savings.
[724] Fix | Delete
*/
[725] Fix | Delete
var shortTimeStringParts = eventDateTime.toLocaleTimeString( undefined, { timeZoneName : 'short' } ).split( ' ' );
[726] Fix | Delete
[727] Fix | Delete
if ( 3 === shortTimeStringParts.length ) {
[728] Fix | Delete
timeZoneAbbreviation = shortTimeStringParts[2];
[729] Fix | Delete
}
[730] Fix | Delete
[731] Fix | Delete
if ( 'undefined' === typeof timeZoneAbbreviation ) {
[732] Fix | Delete
/*
[733] Fix | Delete
* It's important to use the _event_ time, not the _current_
[734] Fix | Delete
* time, so that daylight savings time is accounted for.
[735] Fix | Delete
*/
[736] Fix | Delete
var timeZoneOffset = app.getFlippedTimeZoneOffset( startTimestamp ),
[737] Fix | Delete
sign = -1 === Math.sign( timeZoneOffset ) ? '' : '+';
[738] Fix | Delete
[739] Fix | Delete
// translators: Used as part of a string like `GMT+5` in the Events Widget.
[740] Fix | Delete
timeZoneAbbreviation = _x( 'GMT', 'Events widget offset prefix' ) + sign + ( timeZoneOffset / 60 );
[741] Fix | Delete
}
[742] Fix | Delete
[743] Fix | Delete
return timeZoneAbbreviation;
[744] Fix | Delete
},
[745] Fix | Delete
[746] Fix | Delete
/**
[747] Fix | Delete
* Format a start/end date in the user's local time zone and locale.
[748] Fix | Delete
*
[749] Fix | Delete
* @since 5.5.2
[750] Fix | Delete
*
[751] Fix | Delete
* @param {int} startDate The Unix timestamp in milliseconds when the the event starts.
[752] Fix | Delete
* @param {int} endDate The Unix timestamp in milliseconds when the the event ends.
[753] Fix | Delete
* @param {string} timeZone A time zone string or offset which is parsable by `wp.date.i18n()`.
[754] Fix | Delete
*
[755] Fix | Delete
* @returns {string}
[756] Fix | Delete
*/
[757] Fix | Delete
getFormattedDate: function( startDate, endDate, timeZone ) {
[758] Fix | Delete
var formattedDate;
[759] Fix | Delete
[760] Fix | Delete
/*
[761] Fix | Delete
* The `date_format` option is not used because it's important
[762] Fix | Delete
* in this context to keep the day of the week in the displayed date,
[763] Fix | Delete
* so that users can tell at a glance if the event is on a day they
[764] Fix | Delete
* are available, without having to open the link.
[765] Fix | Delete
*
[766] Fix | Delete
* The case of crossing a year boundary is intentionally not handled.
[767] Fix | Delete
* It's so rare in practice that it's not worth the complexity
[768] Fix | Delete
* tradeoff. The _ending_ year should be passed to
[769] Fix | Delete
* `multiple_month_event`, though, just in case.
[770] Fix | Delete
*/
[771] Fix | Delete
/* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://www.php.net/manual/datetime.format.php */
[772] Fix | Delete
var singleDayEvent = __( 'l, M j, Y' ),
[773] Fix | Delete
/* translators: Date string for upcoming events. 1: Month, 2: Starting day, 3: Ending day, 4: Year. */
[774] Fix | Delete
multipleDayEvent = __( '%1$s %2$d–%3$d, %4$d' ),
[775] Fix | Delete
/* translators: Date string for upcoming events. 1: Starting month, 2: Starting day, 3: Ending month, 4: Ending day, 5: Ending year. */
[776] Fix | Delete
multipleMonthEvent = __( '%1$s %2$d – %3$s %4$d, %5$d' );
[777] Fix | Delete
[778] Fix | Delete
// Detect single-day events.
[779] Fix | Delete
if ( ! endDate || format( 'Y-m-d', startDate ) === format( 'Y-m-d', endDate ) ) {
[780] Fix | Delete
formattedDate = dateI18n( singleDayEvent, startDate, timeZone );
[781] Fix | Delete
[782] Fix | Delete
// Multiple day events.
[783] Fix | Delete
} else if ( format( 'Y-m', startDate ) === format( 'Y-m', endDate ) ) {
[784] Fix | Delete
formattedDate = sprintf(
[785] Fix | Delete
multipleDayEvent,
[786] Fix | Delete
dateI18n( _x( 'F', 'upcoming events month format' ), startDate, timeZone ),
[787] Fix | Delete
dateI18n( _x( 'j', 'upcoming events day format' ), startDate, timeZone ),
[788] Fix | Delete
dateI18n( _x( 'j', 'upcoming events day format' ), endDate, timeZone ),
[789] Fix | Delete
dateI18n( _x( 'Y', 'upcoming events year format' ), endDate, timeZone )
[790] Fix | Delete
);
[791] Fix | Delete
[792] Fix | Delete
// Multi-day events that cross a month boundary.
[793] Fix | Delete
} else {
[794] Fix | Delete
formattedDate = sprintf(
[795] Fix | Delete
multipleMonthEvent,
[796] Fix | Delete
dateI18n( _x( 'F', 'upcoming events month format' ), startDate, timeZone ),
[797] Fix | Delete
dateI18n( _x( 'j', 'upcoming events day format' ), startDate, timeZone ),
[798] Fix | Delete
dateI18n( _x( 'F', 'upcoming events month format' ), endDate, timeZone ),
[799] Fix | Delete
dateI18n( _x( 'j', 'upcoming events day format' ), endDate, timeZone ),
[800] Fix | Delete
dateI18n( _x( 'Y', 'upcoming events year format' ), endDate, timeZone )
[801] Fix | Delete
);
[802] Fix | Delete
}
[803] Fix | Delete
[804] Fix | Delete
return formattedDate;
[805] Fix | Delete
}
[806] Fix | Delete
};
[807] Fix | Delete
[808] Fix | Delete
if ( $( '#dashboard_primary' ).is( ':visible' ) ) {
[809] Fix | Delete
app.init();
[810] Fix | Delete
} else {
[811] Fix | Delete
$( document ).on( 'postbox-toggled', function( event, postbox ) {
[812] Fix | Delete
var $postbox = $( postbox );
[813] Fix | Delete
[814] Fix | Delete
if ( 'dashboard_primary' === $postbox.attr( 'id' ) && $postbox.is( ':visible' ) ) {
[815] Fix | Delete
app.init();
[816] Fix | Delete
}
[817] Fix | Delete
});
[818] Fix | Delete
}
[819] Fix | Delete
});
[820] Fix | Delete
[821] Fix | Delete
/**
[822] Fix | Delete
* Removed in 5.6.0, needed for back-compatibility.
[823] Fix | Delete
*
[824] Fix | Delete
* @since 4.8.0
[825] Fix | Delete
* @deprecated 5.6.0
[826] Fix | Delete
*
[827] Fix | Delete
* @type {object}
[828] Fix | Delete
*/
[829] Fix | Delete
window.communityEventsData.l10n = window.communityEventsData.l10n || {
[830] Fix | Delete
enter_closest_city: '',
[831] Fix | Delete
error_occurred_please_try_again: '',
[832] Fix | Delete
attend_event_near_generic: '',
[833] Fix | Delete
could_not_locate_city: '',
[834] Fix | Delete
city_updated: ''
[835] Fix | Delete
};
[836] Fix | Delete
[837] Fix | Delete
window.communityEventsData.l10n = window.wp.deprecateL10nObject( 'communityEventsData.l10n', window.communityEventsData.l10n, '5.6.0' );
[838] Fix | Delete
[839] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function