Skip to content

Commit

Permalink
Merge pull request #67 from Yoast/stories/fix-asset-loading
Browse files Browse the repository at this point in the history
Improve conditional Asset loading
  • Loading branch information
kraftner authored Oct 12, 2017
2 parents 623a206 + a69694c commit 7e3df0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions inc/class-yoast-acf-analysis-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Yoast_ACF_Analysis_Assets {
public function init() {
$this->plugin_data = get_plugin_data( AC_SEO_ACF_ANALYSIS_PLUGIN_FILE );

add_filter( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_filter( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
}

/**
Expand All @@ -28,27 +28,30 @@ public function enqueue_scripts() {
$config = Yoast_ACF_Analysis_Facade::get_registry()->get( 'config' );

// Post page enqueue.
if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
if ( wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'post-scraper' ) ) {
wp_enqueue_script(
'yoast-acf-analysis-post',
plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ),
array( 'jquery', 'yoast-seo-post-scraper', 'underscore' ),
$this->plugin_data['Version']
array( 'jquery', WPSEO_Admin_Asset_Manager::PREFIX . 'post-scraper', 'underscore' ),
$this->plugin_data['Version'],
true
);

wp_localize_script( 'yoast-acf-analysis-post', 'YoastACFAnalysisConfig', $config->to_array() );
}

// Term page enqueue.
if ( 'term.php' === $pagenow ) {
if ( wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ) ) {
wp_enqueue_script(
'yoast-acf-analysis-term',
plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ),
array( 'jquery', 'yoast-seo-term-scraper' ),
$this->plugin_data['Version']
array( 'jquery', WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ),
$this->plugin_data['Version'],
true
);

wp_localize_script( 'yoast-acf-analysis-term', 'YoastACFAnalysisConfig', $config->to_array() );
}
}

}
2 changes: 1 addition & 1 deletion js/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ App.prototype.bindListeners = function(){

if(helper.acf_version >= 5){

acf.add_action('ready', function () {
jQuery(function(){

replaceVars.updateReplaceVars(collect);

Expand Down
2 changes: 1 addition & 1 deletion js/yoast-acf-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ App.prototype.bindListeners = function(){

if(helper.acf_version >= 5){

acf.add_action('ready', function () {
jQuery(function(){

replaceVars.updateReplaceVars(collect);

Expand Down

0 comments on commit 7e3df0c

Please sign in to comment.