Changeset 12002
- Timestamp:
- 04/27/2018 04:52:27 PM (7 years ago)
- Location:
- trunk/src/bp-templates/bp-nouveau
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-templates/bp-nouveau/buddypress-functions.php
r11962 r12002 383 383 'view' => __( 'View', 'buddypress' ), 384 384 'object_nav_parent' => '#buddypress', 385 'time_since' => array(386 'sometime' => _x( 'sometime', 'javascript time since', 'buddypress' ),387 'now' => _x( 'right now', 'javascript time since', 'buddypress' ),388 'ago' => _x( '% ago', 'javascript time since', 'buddypress' ),389 'separator' => _x( ',', 'Separator in javascript time since', 'buddypress' ),390 'year' => _x( '% year', 'javascript time since singular', 'buddypress' ),391 'years' => _x( '% years', 'javascript time since plural', 'buddypress' ),392 'month' => _x( '% month', 'javascript time since singular', 'buddypress' ),393 'months' => _x( '% months', 'javascript time since plural', 'buddypress' ),394 'week' => _x( '% week', 'javascript time since singular', 'buddypress' ),395 'weeks' => _x( '% weeks', 'javascript time since plural', 'buddypress' ),396 'day' => _x( '% day', 'javascript time since singular', 'buddypress' ),397 'days' => _x( '% days', 'javascript time since plural', 'buddypress' ),398 'hour' => _x( '% hour', 'javascript time since singular', 'buddypress' ),399 'hours' => _x( '% hours', 'javascript time since plural', 'buddypress' ),400 'minute' => _x( '% minute', 'javascript time since singular', 'buddypress' ),401 'minutes' => _x( '% minutes', 'javascript time since plural', 'buddypress' ),402 'second' => _x( '% second', 'javascript time since singular', 'buddypress' ),403 'seconds' => _x( '% seconds', 'javascript time since plural', 'buddypress' ),404 'time_chunks' => array(405 'a_year' => YEAR_IN_SECONDS,406 'b_month' => 30 * DAY_IN_SECONDS,407 'c_week' => WEEK_IN_SECONDS,408 'd_day' => DAY_IN_SECONDS,409 'e_hour' => HOUR_IN_SECONDS,410 'f_minute' => MINUTE_IN_SECONDS,411 'g_second' => 1,412 ),413 ),414 385 ); 415 386 -
trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php
r11900 r12002 426 426 427 427 return $classes; 428 }429 430 /**431 * @since 3.0.0432 */433 function bp_nouveau_activity_time_since( $time_since, $activity = null ) {434 if ( ! isset( $activity->date_recorded ) ) {435 return $time_since;436 }437 438 return apply_filters(439 'bp_nouveau_activity_time_since', sprintf(440 '<time class="time-since" datetime="%1$s" data-bp-timestamp="%2$d">%3$s</time>',441 esc_attr( $activity->date_recorded ),442 esc_attr( strtotime( $activity->date_recorded ) ),443 esc_attr( bp_core_time_since( $activity->date_recorded ) )444 )445 );446 }447 448 /**449 * @since 3.0.0450 */451 function bp_nouveau_activity_allowed_tags( $activity_allowedtags = array() ) {452 $activity_allowedtags['time'] = array();453 $activity_allowedtags['time']['class'] = array();454 $activity_allowedtags['time']['datetime'] = array();455 $activity_allowedtags['time']['data-bp-timestamp'] = array();456 457 return $activity_allowedtags;458 428 } 459 429 -
trunk/src/bp-templates/bp-nouveau/includes/activity/loader.php
r11902 r12002 97 97 add_filter( 'bp_get_activity_action_pre_meta', 'bp_nouveau_activity_secondary_avatars', 10, 2 ); 98 98 add_filter( 'bp_get_activity_css_class', 'bp_nouveau_activity_scope_newest_class', 10, 1 ); 99 add_filter( 'bp_activity_time_since', 'bp_nouveau_activity_time_since', 10, 2 );100 add_filter( 'bp_activity_allowed_tags', 'bp_nouveau_activity_allowed_tags', 10, 1 );101 99 } 102 100 } -
trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js
r11992 r12002 96 96 97 97 $.extend( data, { bp_heartbeat: bp.Nouveau.getStorage( 'bp-activity' ) } ); 98 99 // Update all displayed time100 $.each( $( '#buddypress time' ), function( t, time ) {101 if ( $( time ).data( 'bp-timestamp' ) ) {102 $( time ).html( bp.Nouveau.updateTimeSince( Number( $( time ).data( 'bp-timestamp' ) ) ) );103 }104 } );105 98 }, 106 99 -
trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js
r11906 r12002 49 49 this.objects = $.map( BP_Nouveau.objects, function( value ) { return value; } ); 50 50 this.objectNavParent = BP_Nouveau.object_nav_parent; 51 this.time_since = BP_Nouveau.time_since;52 51 53 52 // HeartBeat Global … … 206 205 } else { 207 206 $( selector ).html( content ); 208 }209 },210 211 /**212 * [updateTimeSince description]213 * @param {[type]} timestamp [description]214 * @return {[type]} [description]215 */216 updateTimeSince: function( timestamp ) {217 var now = new Date( $.now() ), diff, count_1, chunk_1, count_2, chunk_2,218 time_since = [], time_chunks = $.extend( {}, this.time_since.time_chunks ), ms;219 220 // Returns sometime221 if ( undefined === timestamp ) {222 return this.time_since.sometime;223 }224 225 // Javascript timestamps are in ms.226 timestamp = new Date( timestamp * 1000 );227 228 // Calculate the diff229 diff = now - timestamp;230 231 // Returns right now232 if ( 0 === diff ) {233 return this.time_since.now;234 }235 236 $.each( time_chunks, function( c, chunk ) {237 var milliseconds = chunk * 1000;238 var rounded_time = Math.floor( diff / milliseconds );239 240 if ( 0 !== rounded_time && ! chunk_1 ) {241 chunk_1 = c;242 count_1 = rounded_time;243 ms = milliseconds;244 }245 } );246 247 // First chunk248 chunk_1 = chunk_1.substr( 2 );249 time_since.push( ( 1 === count_1 ) ? this.time_since[ chunk_1 ].replace( '%', count_1 ) : this.time_since[ chunk_1 + 's' ].replace( '%', count_1 ) );250 251 // Remove Year from chunks252 delete time_chunks.a_year;253 254 $.each( time_chunks, function( c, chunk ) {255 var milliseconds = chunk * 1000;256 var rounded_time = Math.floor( ( diff - ( ms * count_1 ) ) / milliseconds );257 258 if ( 0 !== rounded_time && ! chunk_2 ) {259 chunk_2 = c;260 count_2 = rounded_time;261 }262 } );263 264 // Second chunk265 if ( undefined !== chunk_2 ) {266 chunk_2 = chunk_2.substr( 2 );267 time_since.push( ( 1 === count_2 ) ? this.time_since[ chunk_2 ].replace( '%', count_2 ) : this.time_since[ chunk_2 + 's' ].replace( '%', count_2 ) );268 }269 270 // Returns x time, y time ago271 if ( time_since.length >= 1 ) {272 return this.time_since.ago.replace( '%', time_since.join( this.time_since.separator + ' ' ) );273 274 // Returns sometime275 } else {276 return this.time_since.sometime;277 207 } 278 208 },
Note: See TracChangeset
for help on using the changeset viewer.