Changeset 11008 for trunk/src/bp-core/bp-core-cssjs.php
- Timestamp:
- 08/10/2016 12:55:49 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-cssjs.php
r10899 r11008 48 48 'bp-cover-image' => array( 'file' => "{$url}cover-image{$min}.js", 'dependencies' => array(), 'footer' => true ), 49 49 50 // Version 2.7. 51 'bp-moment' => array( 'file' => "{$url}moment{$min}.js", 'dependencies' => array(), 'footer' => true ), 52 'bp-livestamp' => array( 'file' => "{$url}livestamp{$min}.js", 'dependencies' => array( 'jquery', 'bp-moment' ), 'footer' => true ), 50 53 ) ); 51 54 … … 461 464 } 462 465 add_action( 'bp_enqueue_scripts', 'bp_add_cover_image_inline_css', 11 ); 466 467 /** 468 * Enqueues livestamp.js on BuddyPress pages. 469 * 470 * @since 2.7.0 471 */ 472 function bp_core_add_livestamp() { 473 if ( ! is_buddypress() ) { 474 return; 475 } 476 477 bp_core_enqueue_livestamp(); 478 } 479 add_action( 'bp_enqueue_scripts', 'bp_core_add_livestamp' ); 480 481 /** 482 * Enqueue and localize livestamp.js script. 483 * 484 * @since 2.7.0 485 */ 486 function bp_core_enqueue_livestamp() { 487 // If bp-livestamp isn't enqueued, do it now. 488 if ( wp_script_is( 'bp-livestamp' ) ) { 489 return; 490 } 491 492 wp_enqueue_script( 'bp-livestamp' ); 493 494 // We're only localizing the relative time strings for moment.js since that's all we need for now. 495 wp_localize_script( 'bp-livestamp', 'BP_Moment_i18n', array( 496 'future' => __( 'in %s', 'buddypress' ), 497 'past' => __( '%s ago', 'buddypress' ), 498 's' => __( 'a few seconds', 'buddypress' ), 499 'm' => __( 'a minute', 'buddypress' ), 500 'mm' => __( '%d minutes', 'buddypress' ), 501 'h' => __( 'an hour', 'buddypress' ), 502 'hh' => __( '%d hours', 'buddypress' ), 503 'd' => __( 'a day', 'buddypress' ), 504 'dd' => __( '%d days', 'buddypress' ), 505 'M' => __( 'a month', 'buddypress' ), 506 'MM' => __( '%d months', 'buddypress' ), 507 'y' => __( 'a year', 'buddypress' ), 508 'yy' => __( '%d years', 'buddypress' ), 509 ) ); 510 511 if ( function_exists( 'wp_add_inline_script' ) ) { 512 wp_add_inline_script ( 'bp-livestamp', bp_core_moment_js_config() ); 513 } else { 514 add_action( 'wp_footer', '_bp_core_moment_js_config_footer', 20 ); 515 } 516 } 517 518 /** 519 * Return moment.js config. 520 * 521 * @since 2.7.0 522 * 523 * @return string 524 */ 525 function bp_core_moment_js_config() { 526 $inline_js = <<<EOD 527 jQuery(function() { 528 moment.locale( 'bp', { 529 relativeTime : BP_Moment_i18n 530 }); 531 }); 532 EOD; 533 534 return $inline_js; 535 } 536 537 /** 538 * Print moment.js config in page footer. 539 * 540 * Will be removed once we set our minimum version of WP 4.5. 541 * 542 * @since 2.7.0 543 * 544 * @access private 545 */ 546 function _bp_core_moment_js_config_footer() { 547 if ( ! wp_script_is( 'bp-livestamp' ) ) { 548 return; 549 } 550 551 printf( '<script>%s</script>', bp_core_moment_js_config() ); 552 }
Note: See TracChangeset
for help on using the changeset viewer.