Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/27/2014 05:10:54 AM (8 years ago)
Author:
johnjamesjacoby
Message:

First pass at unbundling inline jQuery plugins from BP Legacy's buddypress.js and BP Default's global.js. See #5208.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-cssjs.php

    r8091 r8453  
    99// Exit if accessed directly
    1010if ( !defined( 'ABSPATH' ) ) exit;
     11
     12/**
     13 * Register scripts commonly used by BuddyPress plugins and themes.
     14 *
     15 * @since BuddyPress (2.1.0)
     16 */
     17function bp_core_register_common_scripts() {
     18
     19    // Whether or not to use minified versions
     20    $min  = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
     21
     22    // Get the version for busting caches
     23    $ver  = bp_get_version();
     24
     25    // Get the common core JS URL
     26    $url  = buddypress()->plugin_url . 'bp-core/js/';
     27   
     28    // Array of common scripts
     29    $scripts = apply_filters( 'bp_core_register_common_scripts', array(
     30        'bp-confirm'          => 'confirm',
     31        'bp-widget-members'   => 'widget-members',
     32        'bp-jquery-query'     => 'jquery-query',
     33        'bp-jquery-cookie'    => 'jquery-cookie',
     34        'bp-jquery-scroll-to' => 'jquery-scroll-to',
     35    ) );
     36
     37    // Register scripts commonly used by BuddyPress themes
     38    foreach ( $scripts as $id => $file ) {
     39        wp_register_script( $id, $url . $file . $min, array( 'jquery' ), $ver );
     40    }
     41}
     42add_action( 'bp_enqueue_scripts', 'bp_core_register_common_scripts', 1 );
    1143
    1244/**
     
    1850    }
    1951
    20     $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    21     wp_enqueue_script( 'bp-confirm', buddypress()->plugin_url . "bp-core/js/confirm{$min}.js", array( 'jquery' ), bp_get_version() );
     52    wp_enqueue_script( 'bp-confirm' );
    2253
    2354    wp_localize_script( 'bp-confirm', 'BP_Confirm', array(
     
    2657
    2758}
    28 add_action( 'wp_enqueue_scripts',    'bp_core_confirmation_js' );
     59add_action( 'bp_enqueue_scripts',    'bp_core_confirmation_js' );
    2960add_action( 'admin_enqueue_scripts', 'bp_core_confirmation_js' );
    3061
     
    70101            jQuery('#avatar-to-crop').Jcrop({
    71102                onChange: showPreview,
    72                 onSelect: showPreview,
    73103                onSelect: updateCoords,
    74104                aspectRatio: <?php echo $aspect_ratio; ?>,
     
    154184    return apply_filters( 'bp_core_ajax_url', admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' ) );
    155185}
     186
     187/**
     188 * Get the javascript dependencies for buddypress.js.
     189 *
     190 * @since BuddyPress (2.0.0)
     191 *
     192 * @uses apply_filters() to allow other component to load extra dependencies
     193 *
     194 * @return array The javascript dependencies.
     195 */
     196function bp_core_get_js_dependencies() {
     197    return apply_filters( 'bp_core_get_js_dependencies', array(
     198        'jquery',
     199        'bp-confirm',
     200        'bp-widget-members',
     201        'bp-jquery-query',
     202        'bp-jquery-cookie',
     203        'bp-jquery-scroll-to'
     204    ) );
     205}
Note: See TracChangeset for help on using the changeset viewer.