Changeset 7011
- Timestamp:
- 04/03/2018 08:46:45 PM (8 years ago)
- Location:
- sites/trunk/wp15.wordpress.net/public_html/content/plugins/wp15-meetup-events
- Files:
-
- 3 edited
-
views/events-map.php (modified) (1 diff)
-
wp15-meetup-events.js (modified) (3 diffs)
-
wp15-meetup-events.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wp15.wordpress.net/public_html/content/plugins/wp15-meetup-events/views/events-map.php
r7010 r7011 4 4 defined( 'WPINC' ) || die(); 5 5 6 /** @var array $map_options */7 8 6 ?> 9 10 <script>11 var wp15MeetupEventsOptions = <?php echo wp_json_encode( $map_options ); ?>;12 </script>13 7 14 8 <div id="wp15-events-map"> -
sites/trunk/wp15.wordpress.net/public_html/content/plugins/wp15-meetup-events/wp15-meetup-events.js
r7010 r7011 8 8 var WP15MeetupEvents = ( function( $ ) { 9 9 // `templateOptions` is copied from Core in order to avoid an extra HTTP request just to get `wp.template`. 10 var options, 11 templateOptions = { 10 var events, 11 options, 12 strings, 13 templateOptions = { 12 14 evaluate: /<#([\s\S]+?)#>/g, 13 15 interpolate: /\{\{\{([\s\S]+?)\}\}\}/g, … … 18 20 * Initialization that runs when the document has fully loaded. 19 21 */ 20 function init( initOptions ) { 21 options = initOptions; 22 initOptions = null; 22 function init( data ) { 23 events = data.events; 24 options = data.map_options; 25 strings = data.strings; 23 26 24 27 try { 25 28 $( '#wp15-events-query' ).keyup( filterEventList ); 26 29 27 if ( options.hasOwnProperty( 'mapContainer' ) && options.hasOwnProperty( 'mapMarkers' )) {28 loadMap( options.mapContainer, options.mapMarkers );30 if ( options.hasOwnProperty( 'mapContainer' ) ) { 31 loadMap( options.mapContainer, events ); 29 32 } 30 33 } catch ( exception ) { … … 207 210 } )( jQuery ); 208 211 209 jQuery( document ).ready( WP15MeetupEvents.init( wp15MeetupEvents Options) );212 jQuery( document ).ready( WP15MeetupEvents.init( wp15MeetupEventsData ) ); -
sites/trunk/wp15.wordpress.net/public_html/content/plugins/wp15-meetup-events/wp15-meetup-events.php
r7009 r7011 177 177 } 178 178 179 wp_enqueue_style( 180 'wp15-meetup-events', 181 plugins_url( 'wp15-meetup-events.css', __FILE__ ), 182 array(), 183 filemtime( __DIR__ . '/wp15-meetup-events.css' ) 184 ); 185 179 186 wp_register_script( 180 187 'google-maps', … … 201 208 ); 202 209 203 wp_ enqueue_style(210 wp_localize_script( 204 211 'wp15-meetup-events', 205 plugins_url( 'wp15-meetup-events.css', __FILE__ ), 206 array(), 207 filemtime( __DIR__ . '/wp15-meetup-events.css' ) 208 ); 209 } 210 211 /** 212 * Render the WP15 events shortcode. 213 */ 214 function render_events_shortcode() { 215 $events = get_option( 'wp15_events' ); 216 217 // This needs to be done on the fly, in order to use the date format for the visitor's locale. 218 foreach ( $events as & $event ) { 219 $event['time'] = get_local_formatted_date( $event['time'], $event['timezone'] ); 220 } 221 unset( $event ); // Destroy the reference to restore expected behavior; see https://stackoverflow.com/a/4969286/450127. 222 223 usort( $events, __NAMESPACE__ . '\sort_events' ); 224 225 $map_options = array( 212 'wp15MeetupEventsData', 213 array( 214 'map_options' => get_map_options(), 215 'events' => get_formatted_events(), 216 ) 217 ); 218 } 219 220 221 /** 222 * Get the configuration for the Google Map of events. 223 * 224 * @return array 225 */ 226 function get_map_options() { 227 return array( 226 228 'mapContainer' => 'wp15-events-map', 227 'mapMarkers' => $events,228 229 'markerIconBaseURL' => plugins_url( '/images/', __FILE__ ), 229 230 'markerIcon' => 'map-marker.svg', … … 235 236 'clusterIconHeight' => 52, 236 237 ); 238 } 239 240 /** 241 * Format the WP15 events for presentation. 242 * 243 * @return array 244 */ 245 function get_formatted_events() { 246 $events = get_option( 'wp15_events' ); 247 248 // This needs to be done on the fly, in order to use the date format for the visitor's locale. 249 foreach ( $events as & $event ) { 250 $event['time'] = get_local_formatted_date( $event['time'], $event['timezone'] ); 251 } 252 unset( $event ); // Destroy the reference to restore expected behavior; see https://stackoverflow.com/a/4969286/450127. 253 254 usort( $events, __NAMESPACE__ . '\sort_events' ); 255 256 return $events; 257 } 258 259 /** 260 * Sort events by their timestamp. 261 * 262 * @param array $a 263 * @param array $b 264 * 265 * @return int 266 */ 267 function sort_events( $a, $b ) { 268 if ( $a['time'] === $b['time'] ) { 269 return 0; 270 } 271 272 return $a['time'] > $b['time']; 273 } 274 275 /** 276 * Render the WP15 events shortcode. 277 */ 278 function render_events_shortcode() { 279 $events = get_formatted_events(); 237 280 238 281 ob_start(); … … 240 283 require_once( __DIR__ . '/views/events-list.php' ); 241 284 return ob_get_clean(); 242 }243 244 /**245 * Sort events by their timestamp.246 *247 * @param array $a248 * @param array $b249 *250 * @return int251 */252 function sort_events( $a, $b ) {253 if ( $a['time'] === $b['time'] ) {254 return 0;255 }256 257 return $a['time'] > $b['time'];258 285 } 259 286
Note: See TracChangeset
for help on using the changeset viewer.