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