bp-activity-cssjs.php 2.2 KB
Newer Older
lucha's avatar
lucha committed
1
2
3
4
5
6
<?php
/**
 * Activity component CSS/JS
 *
 * @package BuddyPress
 * @subpackage ActivityScripts
lechuck's avatar
lechuck committed
7
 * @since 1.0.0
lucha's avatar
lucha committed
8
9
 */

lechuck's avatar
lechuck committed
10
// Exit if accessed directly.
ale's avatar
ale committed
11
defined( 'ABSPATH' ) || exit;
lucha's avatar
lucha committed
12
13
14
15

/**
 * Enqueue @mentions JS.
 *
lechuck's avatar
lechuck committed
16
 * @since 2.1.0
lucha's avatar
lucha committed
17
18
19
20
21
22
 */
function bp_activity_mentions_script() {
	if ( ! bp_activity_maybe_load_mentions_scripts() ) {
		return;
	}

lechuck's avatar
lechuck committed
23
	// Special handling for New/Edit screens in wp-admin.
lucha's avatar
lucha committed
24
25
26
27
28
29
30
31
32
33
	if ( is_admin() ) {
		if (
			! get_current_screen() ||
			! in_array( get_current_screen()->base, array( 'page', 'post' ) ) ||
			! post_type_supports( get_current_screen()->post_type, 'editor' ) ) {
			return;
		}
	}


lechuck's avatar
lechuck committed
34
	$min = bp_core_get_minified_asset_suffix();
lucha's avatar
lucha committed
35
36
37
38
39
40
41
42
43

	wp_enqueue_script( 'bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array( 'jquery', 'jquery-atwho' ), bp_get_version(), true );
	wp_enqueue_style( 'bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version() );

	wp_style_add_data( 'bp-mentions-css', 'rtl', true );
	if ( $min ) {
		wp_style_add_data( 'bp-mentions-css', 'suffix', $min );
	}

lechuck's avatar
lechuck committed
44
45
46
	// If the script has been enqueued, let's attach our mentions TinyMCE init callback.
	add_filter( 'tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2 );

ale's avatar
ale committed
47
48
49
50
51
52
	/**
	 * Fires at the end of the Activity Mentions script.
	 *
	 * This is the hook where BP components can add their own prefetched results
	 * friends to the page for quicker @mentions lookups.
	 *
lechuck's avatar
lechuck committed
53
	 * @since 2.1.0
ale's avatar
ale committed
54
	 */
lucha's avatar
lucha committed
55
56
57
	do_action( 'bp_activity_mentions_prime_results' );
}
add_action( 'bp_enqueue_scripts', 'bp_activity_mentions_script' );
ale's avatar
ale committed
58
add_action( 'bp_admin_enqueue_scripts', 'bp_activity_mentions_script' );
lechuck's avatar
lechuck committed
59
60
61
62

/**
 * Bind the mentions listener to a wp_editor instance when TinyMCE initializes.
 *
lechuck's avatar
lechuck committed
63
 * @since 2.3.3
lechuck's avatar
lechuck committed
64
65
66
67
68
69
70
71
72
73
74
75
76
 *
 * @param array  $settings   An array with TinyMCE config.
 * @param string $editor_id Unique editor identifier, e.g. 'content'.
 * @return array  $mceInit   An array with TinyMCE config.
 */
function bp_add_mentions_on_tinymce_init( $settings, $editor_id ) {
	// We only apply the mentions init to the visual post editor in the WP dashboard.
	if ( 'content' === $editor_id ) {
		$settings['init_instance_callback'] = 'window.bp.mentions.tinyMCEinit';
	}

	return $settings;
}