@@ -13,49 +13,58 @@ var App = function(){
1313 YoastSEO . app . registerModification ( 'content' , collect . append . bind ( collect ) , config . pluginName ) ;
1414
1515 this . bindListeners ( ) ;
16+
1617} ;
1718
1819App . prototype . bindListeners = function ( ) {
1920
21+ var _self = this ;
22+
2023 if ( helper . acf_version >= 5 ) {
21- var _self = this ;
24+
2225 acf . add_action ( 'ready' , function ( ) {
23- _self . replaceVars = replaceVars . createReplaceVars ( collect ) ;
26+
27+ replaceVars . updateReplaceVars ( collect ) ;
28+
2429 acf . add_action ( 'change remove append sortstop' , _self . maybeRefresh ) ;
25- acf . add_action ( 'change remove append sortstop' , replaceVars . updateReplaceVars . bind ( _self , collect , _self . replaceVars ) ) ;
30+ acf . add_action ( 'change remove append sortstop' , replaceVars . updateReplaceVars . bind ( _self , collect ) ) ;
31+
2632 } ) ;
33+
2734 } else {
35+
2836 var fieldSelectors = config . fieldSelectors . slice ( 0 ) ;
37+ var wysiwygSelector = 'textarea[id^=wysiwyg-acf]' ;
2938
3039 // Ignore Wysiwyg fields because they trigger a refresh in Yoast SEO itself
31- fieldSelectors = _ . without ( fieldSelectors , 'textarea[id^=wysiwyg-acf]' ) ;
32-
33- var _self = this ;
40+ fieldSelectorsWithoutWysiwyg = _ . without ( fieldSelectors , wysiwygSelector ) ;
3441
3542 jQuery ( document ) . on ( 'acf/setup_fields' , function ( ) {
36- this . replaceVars = replaceVars . createReplaceVars ( collect ) ;
43+
44+ replaceVars . updateReplaceVars ( collect ) ;
45+
46+ var fieldsWithoutWysiwyg = jQuery ( '#post-body, #edittag' ) . find ( fieldSelectorsWithoutWysiwyg . join ( ',' ) ) ;
3747 var fields = jQuery ( '#post-body, #edittag' ) . find ( fieldSelectors . join ( ',' ) ) ;
38- //This would cause faster updates while typing
39- //fields.on('change input', _self.maybeRefresh.bind(_self) );
40- fields . on ( 'change' , _self . maybeRefresh . bind ( _self ) ) ;
41- fields . on ( 'change' , replaceVars . updateReplaceVars . bind ( _self , collect , _self . replaceVars ) ) ;
4248
49+ fieldsWithoutWysiwyg . on ( 'change' , _self . maybeRefresh . bind ( _self ) ) ;
4350 // Do not ignore Wysiwyg fields for the purpose of Replace Vars.
44- jQuery ( 'textarea[id^=wysiwyg-acf]' ) . on ( 'change' , replaceVars . updateReplaceVars . bind ( _self , collect , _self . replaceVars ) ) ;
51+ fields . on ( 'change' , replaceVars . updateReplaceVars . bind ( _self , collect ) ) ;
52+
4553 if ( YoastSEO . wp . _tinyMCEHelper ) {
46- jQuery ( 'textarea[id^=wysiwyg-acf]' ) . each ( function ( ) {
54+
55+ jQuery ( wysiwygSelector ) . each ( function ( ) {
4756 YoastSEO . wp . _tinyMCEHelper . addEventHandler ( this . id , [ 'input' , 'change' , 'cut' , 'paste' ] ,
48- replaceVars . updateReplaceVars . bind ( _self , collect , _self . replaceVars ) ) ;
57+ replaceVars . updateReplaceVars . bind ( _self , collect ) ) ;
4958 } ) ;
50- }
5159
60+ }
5261
5362 //Also refresh on media close as attachment data might have changed
5463 wp . media . frame . on ( 'close' , _self . maybeRefresh . bind ( _self ) ) ;
5564 } ) ;
56- }
5765
58- }
66+ }
67+ } ;
5968
6069App . prototype . maybeRefresh = function ( ) {
6170
0 commit comments