diff --git a/js/src/app.js b/js/src/app.js index ed31a5cc..7a6c7747 100644 --- a/js/src/app.js +++ b/js/src/app.js @@ -18,9 +18,12 @@ var App = function(){ App.prototype.bindListeners = function(){ if(helper.acf_version >= 5){ - this.replaceVars = replaceVars.createReplaceVars(collect); - acf.add_action('change remove append sortstop', this.maybeRefresh); - acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(this, collect, this.replaceVars)); + var _self = this; + acf.add_action('ready', function () { + _self.replaceVars = replaceVars.createReplaceVars(collect); + acf.add_action('change remove append sortstop', _self.maybeRefresh); + acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(_self, collect, _self.replaceVars)); + }); }else{ var fieldSelectors = config.fieldSelectors.slice(0); diff --git a/js/src/helper.js b/js/src/helper.js index 619bbbe0..1585df02 100644 --- a/js/src/helper.js +++ b/js/src/helper.js @@ -1,5 +1,5 @@ var config = require( "./config/config.js" ); module.exports = { - acf_version: parseInt(config.acfVersion, 10) + acf_version: parseFloat(config.acfVersion, 10) }; \ No newline at end of file diff --git a/js/src/scraper/scraper.taxonomy.js b/js/src/scraper/scraper.taxonomy.js index c9ab7ea2..75133f8e 100644 --- a/js/src/scraper/scraper.taxonomy.js +++ b/js/src/scraper/scraper.taxonomy.js @@ -1,4 +1,5 @@ var scrapers = require( "./../scraper-store.js" ); +var helper = require( "./../helper.js" ); var Scraper = function() {}; @@ -16,8 +17,10 @@ Scraper.prototype.scrape = function(fields){ if( field.$el.find('.acf-taxonomy-field[data-type="multi_select"]').length > 0 ){ + var select2Target = (helper.acf_version >= 5.6)?'select':'input'; + terms = _.pluck( - field.$el.find('.acf-taxonomy-field[data-type="multi_select"] input') + field.$el.find('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target ) .select2('data') , 'text' ); diff --git a/js/yoast-acf-analysis.js b/js/yoast-acf-analysis.js index 9639196b..0f21cfb0 100644 --- a/js/yoast-acf-analysis.js +++ b/js/yoast-acf-analysis.js @@ -19,9 +19,12 @@ var App = function(){ App.prototype.bindListeners = function(){ if(helper.acf_version >= 5){ - this.replaceVars = replaceVars.createReplaceVars(collect); - acf.add_action('change remove append sortstop', this.maybeRefresh); - acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(this, collect, this.replaceVars)); + var _self = this; + acf.add_action('ready', function () { + _self.replaceVars = replaceVars.createReplaceVars(collect); + acf.add_action('change remove append sortstop', _self.maybeRefresh); + acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(_self, collect, _self.replaceVars)); + }); }else{ var fieldSelectors = config.fieldSelectors.slice(0); @@ -300,7 +303,7 @@ module.exports = YoastACFAnalysisConfig; var config = require( "./config/config.js" ); module.exports = { - acf_version: parseInt(config.acfVersion, 10) + acf_version: parseFloat(config.acfVersion, 10) }; },{"./config/config.js":7}],9:[function(require,module,exports){ /* global jQuery, YoastACFAnalysis: true */ @@ -590,6 +593,7 @@ Scraper.prototype.scrape = function(fields){ module.exports = Scraper; },{"./../cache/cache.attachments.js":2,"./../scraper-store.js":11}],15:[function(require,module,exports){ var scrapers = require( "./../scraper-store.js" ); +var helper = require( "./../helper.js" ); var Scraper = function() {}; @@ -607,8 +611,10 @@ Scraper.prototype.scrape = function(fields){ if( field.$el.find('.acf-taxonomy-field[data-type="multi_select"]').length > 0 ){ + var select2Target = (helper.acf_version >= 5.6)?'select':'input'; + terms = _.pluck( - field.$el.find('.acf-taxonomy-field[data-type="multi_select"] input') + field.$el.find('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target ) .select2('data') , 'text' ); @@ -652,7 +658,7 @@ Scraper.prototype.scrape = function(fields){ }; module.exports = Scraper; -},{"./../scraper-store.js":11}],16:[function(require,module,exports){ +},{"./../helper.js":8,"./../scraper-store.js":11}],16:[function(require,module,exports){ var config = require( "./../config/config.js" ); var scrapers = require( "./../scraper-store.js" ); diff --git a/tests/js/system/tests/acf5/relational.js b/tests/js/system/tests/acf5/relational.js index 9517480b..adcb33e5 100644 --- a/tests/js/system/tests/acf5/relational.js +++ b/tests/js/system/tests/acf5/relational.js @@ -32,28 +32,51 @@ module.exports = { 'Taxonomy Multi Select Field' : function (browser) { - var selector = '.acf-taxonomy-field[data-type="multi_select"][data-taxonomy="category"] .select2-input '; + browser.execute( + function() { + return parseFloat(YoastACFAnalysisConfig.acfVersion, 10); + }, + [], + function( result ){ + var acfVersion = result.value; + var inputSelector, optionSelector, choiceSelector; - browser.waitForElementVisible( selector, 10000 ); + if( acfVersion >= 5.6 ){ + inputSelector = '.acf-taxonomy-field[data-type="multi_select"][data-taxonomy="category"] .select2-search__field '; + optionSelector = '.select2-results__option--highlighted'; + choiceSelector = '.acf-taxonomy-field .select2-selection__choice'; + }else{ + inputSelector = '.acf-taxonomy-field[data-type="multi_select"][data-taxonomy="category"] .select2-input '; + optionSelector = '.select2-result:first-child'; + choiceSelector = '.acf-taxonomy-field .select2-search-choice'; + } - browser.setValue( selector, [ browser.Keys.SPACE ] ); + browser.waitForElementVisible( inputSelector, 10000 ); - browser.waitForElementVisible( '.select2-result:first-child', 10000 ); + browser.setValue( inputSelector, [ browser.Keys.SPACE ] ); - browser.setValue( selector, [ browser.Keys.ENTER ] ); + browser.waitForElementVisible( optionSelector, 10000 ); - browser.waitForElementVisible( '.acf-taxonomy-field .select2-search-choice', 10000 ); + browser.setValue( inputSelector, [ browser.Keys.ENTER ] ); - browser.execute( - function() { - return jQuery('.acf-taxonomy-field[data-type="multi_select"] input').select2('data')[0].text - }, - [], - function( result ){ - this.pause( 3000 ); - logContains( browser, 'li>' + result.value , browser.assert.ok ); + browser.waitForElementVisible( choiceSelector, 10000 ); + + browser.execute( + function() { + + var select2Target = (parseFloat(YoastACFAnalysisConfig.acfVersion, 10) >= 5.6)?'select':'input'; + + return jQuery('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target).select2('data')[0].text + }, + [], + function( result ){ + this.pause( 3000 ); + logContains( browser, 'li>' + result.value , browser.assert.ok ); + } + ); } ); + }, after : function(browser) {